Skip to content

Commit

Permalink
tooling: define aarch64 toolchain
Browse files Browse the repository at this point in the history
Use gcc to cross-compilation for aarch64, as clang requires
additional setup.
Clang support can be added on a follow-up.
  • Loading branch information
danctorres committed Dec 16, 2024
1 parent d451dbe commit f90f2fb
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 93 deletions.
7 changes: 0 additions & 7 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
filegroup(
name = "clang_tidy_config",
srcs = [
".clang-tidy",
],
visibility = ["//visibility:public"],
)
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ RUN apt-get update && apt-get install -y \
clang-format-18 \
clang-tidy-18 \
lld-18 \
lldb-18 \
&& rm -rf /var/lib/apt/lists/*
lldb-18

# Cross-compilation
RUN apt-get install -y \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu

RUN pip install yamllint

Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ git_override(
bazel_dep(name = "platforms", version = "0.0.10")

register_toolchains(
"//toolchain:cc_toolchain_for_linux_x86_64",
"//toolchain/x86_64_linux",
"//toolchain/aarch64_linux",
)
33 changes: 33 additions & 0 deletions bazel/platforms/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
config_setting(
name = "x86_64_config",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "aarch64_config",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
visibility = ["//visibility:public"],
)

platform(
name = "x86_64_linux",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

platform(
name = "aarch64_linux",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)
14 changes: 8 additions & 6 deletions examples/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ cc_library(
name = "lib",
srcs = ["hello.cpp"],
hdrs = ["hello.hpp"],
features = [
"warnings_critical_code",
],
features = select({
"//bazel/platforms:aarch64_config": ["warnings_critical_code_gcc"],
"//conditions:default": ["warnings_critical_code_clang"],
}),
)

cc_binary(
name = "bin",
srcs = ["main.cpp"],
features = [
"warnings_critical_code",
],
features = select({
"//bazel/platforms:aarch64_config": ["warnings_critical_code_gcc"],
"//conditions:default": ["warnings_critical_code_clang"],
}),
deps = [
":lib",
],
Expand Down
34 changes: 0 additions & 34 deletions toolchain/BUILD
Original file line number Diff line number Diff line change
@@ -1,34 +0,0 @@
load(":cc_toolchain_config.bzl", "cc_toolchain_config")

package(default_visibility = ["//visibility:public"])

filegroup(name = "empty")

cc_toolchain_config(name = "linux_x86_64_toolchain_config")

cc_toolchain(
name = "linux_x86_64_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_config = ":linux_x86_64_toolchain_config",
toolchain_identifier = "linux_x86_64_toolchain",
)

toolchain(
name = "cc_toolchain_for_linux_x86_64",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
toolchain = ":linux_x86_64_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
34 changes: 34 additions & 0 deletions toolchain/aarch64_linux/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//toolchain/aarch64_linux:cc_toolchain_config.bzl", "cc_toolchain_config")

package(default_visibility = ["//visibility:public"])

filegroup(name = "empty")

cc_toolchain_config(name = "toolchain_config")

cc_toolchain(
name = "cc_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_config = ":toolchain_config",
toolchain_identifier = "aarch64_linux_toolchain",
)

toolchain(
name = "aarch64_linux",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
toolchain = "cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
Loading

0 comments on commit f90f2fb

Please sign in to comment.