Skip to content

Commit

Permalink
Plumb conly_flags through to the toolchain (#435)
Browse files Browse the repository at this point in the history
This allows us to pull even more configuration of the toolchain out of
.bazelrc flags into the toolchain definition.

Signed-off-by: Austin Schuh <[email protected]>
  • Loading branch information
AustinSchuh authored Jan 8, 2025
1 parent 9ead61d commit a2452f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def cc_toolchain_config(
# The linker has no way of knowing if there are C++ objects; so we
# always link C++ libraries.
cxx_standard = compiler_configuration["cxx_standard"]
conly_flags = compiler_configuration["conly_flags"]
sysroot_path = compiler_configuration["sysroot_path"]
if stdlib == "builtin-libc++" and is_xcompile:
stdlib = "stdc++"
Expand Down Expand Up @@ -380,6 +381,7 @@ def cc_toolchain_config(
compile_flags = compile_flags,
dbg_compile_flags = dbg_compile_flags,
opt_compile_flags = opt_compile_flags,
conly_flags = conly_flags,
cxx_flags = cxx_flags,
link_flags = link_flags + select({str(Label("@toolchains_llvm//toolchain/config:use_libunwind")): libunwind_link_flags, "//conditions:default": []}) +
select({str(Label("@toolchains_llvm//toolchain/config:use_compiler_rt")): compiler_rt_link_flags, "//conditions:default": []}),
Expand Down
3 changes: 3 additions & 0 deletions toolchain/internal/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def llvm_config_impl(rctx):
stdlib_dict = rctx.attr.stdlib,
cxx_standard_dict = rctx.attr.cxx_standard,
compile_flags_dict = rctx.attr.compile_flags,
conly_flags_dict = rctx.attr.conly_flags,
cxx_flags_dict = rctx.attr.cxx_flags,
link_flags_dict = rctx.attr.link_flags,
archive_flags_dict = rctx.attr.archive_flags,
Expand Down Expand Up @@ -377,6 +378,7 @@ cc_toolchain_config(
"stdlib": "{stdlib}",
"cxx_standard": "{cxx_standard}",
"compile_flags": {compile_flags},
"conly_flags": {conly_flags},
"cxx_flags": {cxx_flags},
"link_flags": {link_flags},
"archive_flags": {archive_flags},
Expand Down Expand Up @@ -549,6 +551,7 @@ cc_toolchain(
stdlib = _dict_value(toolchain_info.stdlib_dict, target_pair, "builtin-libc++"),
cxx_standard = _dict_value(toolchain_info.cxx_standard_dict, target_pair, "c++17"),
compile_flags = _list_to_string(_dict_value(toolchain_info.compile_flags_dict, target_pair)),
conly_flags = _list_to_string(toolchain_info.conly_flags_dict.get(target_pair, [])),
cxx_flags = _list_to_string(_dict_value(toolchain_info.cxx_flags_dict, target_pair)),
link_flags = _list_to_string(_dict_value(toolchain_info.link_flags_dict, target_pair)),
archive_flags = _list_to_string(_dict_value(toolchain_info.archive_flags_dict, target_pair)),
Expand Down
6 changes: 6 additions & 0 deletions toolchain/internal/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ _compiler_configuration_attrs = {
"target OS and arch pair you want to override " +
"({}); empty key overrides all.".format(_target_pairs)),
),
"conly_flags": attr.string_list_dict(
mandatory = False,
doc = ("Extra flags for compiling C (not C++) files, " +
"for each target OS and arch pair you want to support " +
"({}), ".format(", ".join(_supported_os_arch_keys())) + "."),
),
"cxx_flags": attr.string_list_dict(
mandatory = False,
doc = ("Override for cxx_flags, replacing the default values. " +
Expand Down

0 comments on commit a2452f1

Please sign in to comment.