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

Force use of Clang over C++ modules with use_module_maps #22660

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions tools/cpp/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ cc_toolchain_config(
coverage_compile_flags = [%{coverage_compile_flags}],
coverage_link_flags = [%{coverage_link_flags}],
supports_start_end_lib = %{supports_start_end_lib},
extra_flags_per_feature = %{extra_flags_per_feature},
)

# Android tooling requires a default toolchain for the armeabi-v7a cpu.
Expand Down
17 changes: 17 additions & 0 deletions tools/cpp/unix_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,22 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
builtin_include_directories,
paths["@bazel_tools//tools/cpp:generate_system_module_map.sh"],
))
extra_flags_per_feature = {}
if is_clang:
# Only supported by LLVM 14 and later, but required with C++20 and
# layering_check as C++ modules are the default.
# https://github.com/llvm/llvm-project/commit/0556138624edf48621dd49a463dbe12e7101f17d
result = repository_ctx.execute([
cc,
"-Xclang",
"-fno-cxx-modules",
"-o",
"/dev/null",
"-c",
str(repository_ctx.path("tools/cpp/empty.cc")),
])
if "-fno-cxx-modules" not in result.stderr:
extra_flags_per_feature["use_module_maps"] = ["-Xclang", "-fno-cxx-modules"]

write_builtin_include_directory_paths(repository_ctx, cc, builtin_include_directories)
repository_ctx.template(
Expand Down Expand Up @@ -696,5 +712,6 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
"%{coverage_compile_flags}": coverage_compile_flags,
"%{coverage_link_flags}": coverage_link_flags,
"%{supports_start_end_lib}": "True" if gold_or_lld_linker_path else "False",
"%{extra_flags_per_feature}": repr(extra_flags_per_feature),
},
)
9 changes: 5 additions & 4 deletions tools/cpp/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _target_os_version(ctx):
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
return xcode_config.minimum_os_for_platform_type(platform_type)

def layering_check_features(compiler, is_macos):
def layering_check_features(compiler, extra_flags_per_feature, is_macos):
if compiler != "clang":
return []
return [
Expand All @@ -58,7 +58,7 @@ def layering_check_features(compiler, is_macos):
"-fmodule-name=%{module_name}",
] + (["-Xclang"] if is_macos else []) + [
"-fmodule-map-file=%{module_map_file}",
],
] + extra_flags_per_feature.get("use_module_maps", []),
),
],
),
Expand Down Expand Up @@ -1489,7 +1489,7 @@ def _impl(ctx):
unfiltered_compile_flags_feature,
treat_warnings_as_errors_feature,
archive_param_file_feature,
] + layering_check_features(ctx.attr.compiler, is_macos = False)
] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = False)
else:
# macOS artifact name patterns differ from the defaults only for dynamic
# libraries.
Expand Down Expand Up @@ -1530,7 +1530,7 @@ def _impl(ctx):
treat_warnings_as_errors_feature,
archive_param_file_feature,
generate_linkmap_feature,
] + layering_check_features(ctx.attr.compiler, is_macos = True)
] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = True)

parse_headers_action_configs, parse_headers_features = parse_headers_support(
parse_headers_tool_path = ctx.attr.tool_paths.get("parse_headers"),
Expand Down Expand Up @@ -1583,6 +1583,7 @@ cc_toolchain_config = rule(
"coverage_link_flags": attr.string_list(),
"supports_start_end_lib": attr.bool(),
"builtin_sysroot": attr.string(),
"extra_flags_per_feature": attr.string_list_dict(),
"_xcode_config": attr.label(default = configuration_field(
fragment = "apple",
name = "xcode_config_label",
Expand Down
Loading