mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add Linux AArch64 Bazel support and simplify. (#3422)
There was a lot of repetition and unnecessary cruft in our Bazel toolchain support. Switch to generating all of it with a single macro that handles everything. This should make no real difference but dramatically simplifies adding a new CPU. Use this simplified system and add `aarch64` which is how Arm 64-bit CPU support shows up on a Linux host. Also teach the basic scripts to map `aarch64` to `arm64` which is used in the released artifact strings.
This commit is contained in:
@@ -17,6 +17,7 @@ load(
|
||||
"variable_with_value",
|
||||
"with_feature_set",
|
||||
)
|
||||
load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite")
|
||||
load(
|
||||
":clang_detected_variables.bzl",
|
||||
"clang_bindir",
|
||||
@@ -886,7 +887,7 @@ def _impl(ctx):
|
||||
|
||||
# Next, add the features based on the target platform. Here too the
|
||||
# features are order sensitive. We also setup the sysroot here.
|
||||
if ctx.attr.target_cpu == "k8":
|
||||
if ctx.attr.target_cpu in ["aarch64", "k8"]:
|
||||
features.append(sanitizer_static_lib_flags)
|
||||
features.append(linux_flags_feature)
|
||||
sysroot = None
|
||||
@@ -906,8 +907,7 @@ def _impl(ctx):
|
||||
else:
|
||||
fail("Unsupported target platform!")
|
||||
|
||||
# TODO: Need to support non-macOS ARM platforms here.
|
||||
if ctx.attr.target_cpu == "darwin_arm64":
|
||||
if ctx.attr.target_cpu in ["aarch64", "darwin_arm64"]:
|
||||
features.append(aarch64_cpu_flags)
|
||||
else:
|
||||
features.append(x86_64_cpu_flags)
|
||||
@@ -954,3 +954,44 @@ cc_toolchain_config = rule(
|
||||
},
|
||||
provides = [CcToolchainConfigInfo],
|
||||
)
|
||||
|
||||
def cc_local_toolchain_suite(name, cpus):
|
||||
"""Create a toolchain suite that uses the local Clang/LLVM install.
|
||||
|
||||
Args:
|
||||
name: The name of the toolchain suite to produce.
|
||||
cpus: An array of CPU strings to support in the toolchain.
|
||||
"""
|
||||
|
||||
# An empty filegroup to use when stubbing out the toolchains.
|
||||
native.filegroup(
|
||||
name = name + "_empty",
|
||||
srcs = [],
|
||||
)
|
||||
|
||||
# Create the individual local toolchains for each CPU.
|
||||
for cpu in cpus:
|
||||
cc_toolchain_config(
|
||||
name = name + "_local_config_" + cpu,
|
||||
target_cpu = cpu,
|
||||
)
|
||||
cc_toolchain(
|
||||
name = name + "_local_" + cpu,
|
||||
all_files = ":" + name + "_empty",
|
||||
ar_files = ":" + name + "_empty",
|
||||
as_files = ":" + name + "_empty",
|
||||
compiler_files = ":" + name + "_empty",
|
||||
dwp_files = ":" + name + "_empty",
|
||||
linker_files = ":" + name + "_empty",
|
||||
objcopy_files = ":" + name + "_empty",
|
||||
strip_files = ":" + name + "_empty",
|
||||
supports_param_files = 1,
|
||||
toolchain_config = ":" + name + "_local_config_" + cpu,
|
||||
toolchain_identifier = name + "_local_" + cpu,
|
||||
)
|
||||
|
||||
# Now build the suite, associating each CPU with its toolchain.
|
||||
cc_toolchain_suite(
|
||||
name = name,
|
||||
toolchains = {cpu: ":" + name + "_local_" + cpu for cpu in cpus},
|
||||
)
|
||||
|
||||
@@ -5,125 +5,16 @@
|
||||
# This file is symlinked into a configured Clang toolchain repository as the
|
||||
# root `BUILD` file for that repository.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_toolchain", "cc_toolchain_suite")
|
||||
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
|
||||
load(":cc_toolchain_config.bzl", "cc_local_toolchain_suite")
|
||||
|
||||
cc_library(
|
||||
name = "malloc",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "empty",
|
||||
srcs = [],
|
||||
)
|
||||
|
||||
cc_toolchain_suite(
|
||||
cc_local_toolchain_suite(
|
||||
name = "bazel_cc_toolchain",
|
||||
toolchains = {
|
||||
"darwin": ":cc-compiler-darwin",
|
||||
"darwin_arm64": ":cc-compiler-darwin-arm64",
|
||||
"freebsd": "cc-compiler-freebsd",
|
||||
"k8": ":cc-compiler-k8",
|
||||
"x64_windows": ":cc-compiler-x64-windows",
|
||||
},
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
name = "cc-compiler-k8",
|
||||
all_files = ":empty",
|
||||
ar_files = ":empty",
|
||||
as_files = ":empty",
|
||||
compiler_files = ":empty",
|
||||
dwp_files = ":empty",
|
||||
linker_files = ":empty",
|
||||
objcopy_files = ":empty",
|
||||
strip_files = ":empty",
|
||||
supports_param_files = 1,
|
||||
toolchain_config = ":local-k8",
|
||||
toolchain_identifier = "local-k8",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "local-k8",
|
||||
target_cpu = "k8",
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
name = "cc-compiler-darwin",
|
||||
all_files = ":empty",
|
||||
ar_files = ":empty",
|
||||
as_files = ":empty",
|
||||
compiler_files = ":empty",
|
||||
dwp_files = ":empty",
|
||||
linker_files = ":empty",
|
||||
objcopy_files = ":empty",
|
||||
strip_files = ":empty",
|
||||
supports_param_files = 1,
|
||||
toolchain_config = ":local-darwin",
|
||||
toolchain_identifier = "local-darwin",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "local-darwin",
|
||||
target_cpu = "darwin",
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
name = "cc-compiler-darwin-arm64",
|
||||
all_files = ":empty",
|
||||
ar_files = ":empty",
|
||||
as_files = ":empty",
|
||||
compiler_files = ":empty",
|
||||
dwp_files = ":empty",
|
||||
linker_files = ":empty",
|
||||
objcopy_files = ":empty",
|
||||
strip_files = ":empty",
|
||||
supports_param_files = 1,
|
||||
toolchain_config = ":local-darwin-arm64",
|
||||
toolchain_identifier = "local-darwin-arm64",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "local-darwin-arm64",
|
||||
target_cpu = "darwin_arm64",
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
name = "cc-compiler-freebsd",
|
||||
all_files = ":empty",
|
||||
ar_files = ":empty",
|
||||
as_files = ":empty",
|
||||
compiler_files = ":empty",
|
||||
dwp_files = ":empty",
|
||||
linker_files = ":empty",
|
||||
objcopy_files = ":empty",
|
||||
strip_files = ":empty",
|
||||
supports_param_files = 1,
|
||||
toolchain_config = ":local-freebsd",
|
||||
toolchain_identifier = "local-freebsd",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "local-freebsd",
|
||||
target_cpu = "freebsd",
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
name = "cc-compiler-x64-windows",
|
||||
all_files = ":empty",
|
||||
ar_files = ":empty",
|
||||
as_files = ":empty",
|
||||
compiler_files = ":empty",
|
||||
dwp_files = ":empty",
|
||||
linker_files = ":empty",
|
||||
objcopy_files = ":empty",
|
||||
strip_files = ":empty",
|
||||
supports_param_files = 1,
|
||||
toolchain_config = ":local-x64-windows",
|
||||
toolchain_identifier = "local-x64-windows",
|
||||
)
|
||||
|
||||
cc_toolchain_config(
|
||||
name = "local-x64-windows",
|
||||
target_cpu = "x64_windows",
|
||||
cpus = [
|
||||
"aarch64",
|
||||
"darwin",
|
||||
"darwin_arm64",
|
||||
"freebsd",
|
||||
"k8",
|
||||
"x64_windows",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -149,6 +149,8 @@ def _get_machine() -> str:
|
||||
machine = platform.machine()
|
||||
if machine == "x86_64":
|
||||
machine = "amd64"
|
||||
elif machine == "aarch64":
|
||||
machine = "arm64"
|
||||
return machine
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user