aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Yu <zachyu@google.com>2024-05-20 15:04:30 -0700
committerZach Yu <zachyu@google.com>2024-05-20 15:08:18 -0700
commit607657aa0887db862550dfd2e38706693b3d033b (patch)
tree7605ca44f326698a629bbb0b16b66d9432c143c3
parent2d0c604b010a68e1e096760756fa7157b002980e (diff)
downloadbazel-emu-dev.tar.gz
Set toolchain compiler namesemu-dev
The compiler name attribute is used by some targets to select() on the current compiler and provide compiler-specific settings (e.g. absl) Change-Id: I9da1fe4b93f3ec34f04dd1ea1083c38a86fb4194
-rw-r--r--tool.bazelrc11
-rw-r--r--toolchains/cc/linux_clang/BUILD.bazel1
-rw-r--r--toolchains/cc/mac_clang/BUILD.bazel2
-rw-r--r--toolchains/cc/rules.bzl8
-rw-r--r--toolchains/cc/windows_clang/BUILD.bazel1
-rw-r--r--toplevel.bazelrc8
6 files changed, 23 insertions, 8 deletions
diff --git a/tool.bazelrc b/tool.bazelrc
index f1da22d1..f4a92e8d 100644
--- a/tool.bazelrc
+++ b/tool.bazelrc
@@ -1,4 +1,6 @@
# Bazel tool configs
+
+## C++
common --repo_env='BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1'
build --incompatible_enable_cc_toolchain_resolution
# TODO(zachyu) remove when we have a custom rust toolchain with this on by default.
@@ -11,10 +13,19 @@ build:linux --force_pic
build:macos --host_platform='//build/bazel/platforms:host_clang'
build:macos --features='generate_debug_symbols'
+# See https://github.com/bazelbuild/bazel/issues/4341#issuecomment-758361769
+# Prevent thread-local issues in protobuf.
+build:macos --features=-supports_dynamic_linker
build:macos --force_pic
build:windows --host_platform='//build/bazel/platforms:host_clang-cl'
build:windows --features='-supports_start_end_lib'
build:windows --features='generate_pdb_file'
+
+## Python
# On windows cleaning up python zips can fail and leak disk (see b/277781554)
build:windows --nobuild_python_zip
+
+## Protobuf
+build --proto_compiler=@com_google_protobuf//:protoc
+build --proto_toolchain_for_cc=@com_google_protobuf//:cc_toolchain
diff --git a/toolchains/cc/linux_clang/BUILD.bazel b/toolchains/cc/linux_clang/BUILD.bazel
index 2d8f94ff..6c530de3 100644
--- a/toolchains/cc/linux_clang/BUILD.bazel
+++ b/toolchains/cc/linux_clang/BUILD.bazel
@@ -60,6 +60,7 @@ cc_toolchain_config(
"@clang//:linux_x64_archiver",
"@clang//:linux_x64_strip",
],
+ compiler_name = "clang",
identifier = "linux_clang_x64",
legacy_builtin_include_directories = select({
":host_stdlibs": [
diff --git a/toolchains/cc/mac_clang/BUILD.bazel b/toolchains/cc/mac_clang/BUILD.bazel
index 94fbbe38..09086979 100644
--- a/toolchains/cc/mac_clang/BUILD.bazel
+++ b/toolchains/cc/mac_clang/BUILD.bazel
@@ -57,6 +57,7 @@ cc_toolchain_config(
"@clang//:macos_all_archiver",
"@clang//:macos_all_strip",
],
+ compiler_name = "clang",
identifier = "macos_clang_x64",
sysroot = "@macos_sdk//:sdk",
target_cpu = "k8",
@@ -139,6 +140,7 @@ cc_toolchain_config(
"@clang//:macos_all_archiver",
"@clang//:macos_all_strip",
],
+ compiler_name = "clang",
identifier = "macos_clang_arm64",
sysroot = "@macos_sdk//:sdk",
target_cpu = "arm64",
diff --git a/toolchains/cc/rules.bzl b/toolchains/cc/rules.bzl
index 38950528..03b8af8b 100644
--- a/toolchains/cc/rules.bzl
+++ b/toolchains/cc/rules.bzl
@@ -407,10 +407,11 @@ def _cc_toolchain_config_impl(ctx):
builtin_sysroot = sysroot,
cxx_builtin_include_directories = ctx.attr.legacy_builtin_include_directories,
target_cpu = ctx.attr.target_cpu,
+ # This is needed by targets using legacy compiler flag value.
+ compiler = ctx.attr.compiler_name,
# The attributes below are required by the constructor, but don't
# affect actions at all.
target_system_name = "__toolchain_target_system_name__",
- compiler = "__toolchain_compiler__",
target_libc = "__toolchain_target_libc__",
abi_version = "__toolchain_abi_version__",
abi_libc_version = "__toolchain_abi_libc_version__",
@@ -447,6 +448,11 @@ cc_toolchain_config = rule(
doc = "Target CPU architecture. This only affects the directory name of execution and output trees.",
mandatory = True,
),
+ "compiler_name": attr.string(
+ doc = "C compiler name. Used by targets to select on the compiler name.",
+ default = "unknown",
+ values = ["clang", "clang-cl", "gcc", "msvc-cl", "mingw", "unknown"],
+ ),
"toolchain_imports": attr.label_list(
doc = "A list of cc_toolchain_import targets.",
providers = [DefaultInfo],
diff --git a/toolchains/cc/windows_clang/BUILD.bazel b/toolchains/cc/windows_clang/BUILD.bazel
index a9a5aa5c..b00f5e57 100644
--- a/toolchains/cc/windows_clang/BUILD.bazel
+++ b/toolchains/cc/windows_clang/BUILD.bazel
@@ -94,6 +94,7 @@ cc_toolchain_config(
"@clang//:win_x64_link",
"@clang//:win_x64_archiver",
],
+ compiler_name = "clang-cl",
identifier = "win_clangcl_x64",
target_cpu = "k8",
toolchain_imports = _x64_imports,
diff --git a/toplevel.bazelrc b/toplevel.bazelrc
index fa83662b..d4bd76bd 100644
--- a/toplevel.bazelrc
+++ b/toplevel.bazelrc
@@ -14,10 +14,4 @@ build --nolegacy_external_runfiles
startup --windows_enable_symlinks
build:windows --enable_runfiles
-# See https://github.com/bazelbuild/bazel/issues/4341#issuecomment-758361769
-# Prevent thread-local issues in protobuf.
-build:macos --features=-supports_dynamic_linker
-
-build --proto_compiler=@com_google_protobuf//:protoc
-build --proto_toolchain_for_cc=@com_google_protobuf//:cc_toolchain
-build --define grpc_no_xds=true \ No newline at end of file
+build --define grpc_no_xds=true