Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags from copts and linkopts attributes #796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions foreign_cc/private/cc_toolchain_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ def get_flags_info(ctx, link_output_file = None):
cc_toolchain = cc_toolchain_,
)

copts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.conlyopts) or []
cxxopts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts) or []
linkopts = ctx.fragments.cpp.linkopts or []
copts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.conlyopts + ctx.attr.copts) or []
cxxopts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts + ctx.attr.copts) or []
linkopts = (ctx.fragments.cpp.linkopts + ctx.attr.linkopts) or []
defines = _defines_from_deps(ctx)

flags = CxxFlagsInfo(
Expand Down
6 changes: 5 additions & 1 deletion test/standard_cxx_flags_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load(":tests.bzl", "flags_test")

flags_test(name = "flags_test")
flags_test(
name = "flags_test",
copts = ["-fblah4"],
linkopts = ["-fblah5"],
)
16 changes: 16 additions & 0 deletions test/standard_cxx_flags_test/tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ def _impl(ctx):

assert_contains_once(flags.cc, "-fblah0")
assert_contains_once(flags.cc, "-fblah2")
assert_contains_once(flags.cc, "-fblah4")
if "-fblah5" in flags.cc:
fail("C flags should not contain '-fblah5'")

assert_contains_once(flags.cxx, "-fblah0")
assert_contains_once(flags.cxx, "-fblah1")
assert_contains_once(flags.cxx, "-fblah4")
if "-fblah5" in flags.cxx:
fail("C++ flags should not contain '-fblah5'")

assert_contains_once(flags.cxx_linker_executable, "-fblah3")
assert_contains_once(flags.cxx_linker_executable, "-fblah5")
if "-fblah4" in flags.cxx_linker_executable:
fail("Executable linker flags should not contain '-fblah4'")

assert_contains_once(flags.cxx_linker_shared, "-fblah3")
assert_contains_once(flags.cxx_linker_shared, "-fblah5")
if "-fblah4" in flags.cxx_linker_shared:
fail("Shared linker flags should not contain '-fblah4'")

if "-fblah3" in flags.cxx_linker_static:
fail("Static linker flags should not contain '-fblah3'")

Expand Down Expand Up @@ -44,7 +58,9 @@ def assert_contains_once(arr, value):
_flags_test = rule(
implementation = _impl,
attrs = {
"copts": attr.string_list(),
"deps": attr.label_list(),
"linkopts": attr.string_list(),
"out": attr.output(),
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
},
Expand Down