Skip to content

Commit fd650ee

Browse files
committed
Add aarch64 support
I could not find a way to read out the host architecture in `lowrisc_rv32imcb_repos`. Using `load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")` at that stage leads to cycles in the workspace file. Instead I now download both the ARM and X86 toolchains. Next I register both and finally I let Bazel decide which one to use as part of the automatic toolchain resolution.
1 parent 7b0acb2 commit fd650ee

File tree

6 files changed

+59
-41
lines changed

6 files changed

+59
-41
lines changed

bazelisk.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ readonly release="v1.11.0"
2323
declare -A hashes=(
2424
# sha256sums for v1.11.0. Update this if you update the release.
2525
[linux-amd64]="231ec5ca8115e94c75a1f4fbada1a062b48822ca04f21f26e4cb1cd8973cd458"
26+
[linux-arm64]="f9119deb1eeb6d730ee8b2e1a14d09cb45638f0447df23144229c5b3b3bc2408"
2627
)
2728

2829
declare -A architectures=(
2930
# Map `uname -m -o` to bazelisk's precompiled binary target names.
3031
[x86_64 GNU/Linux]="linux-amd64"
32+
[aarch64 GNU/Linux]="linux-arm64"
3133
)
3234

3335
function os_arch() {

config/compiler.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def setup(
111111
"[SYSTEM_INCLUDES]": listify_flags(isystem, include_directories),
112112
}
113113
subst.update(substitutions)
114+
if "host_arch" not in params:
115+
params["host_arch"] = "x86_64"
114116

115117
toolchain_config(
116118
name = name + "_config",
@@ -141,7 +143,7 @@ def setup(
141143
native.toolchain(
142144
name = "cc_toolchain_" + name,
143145
exec_compatible_with = [
144-
"@platforms//cpu:x86_64",
146+
"@platforms//cpu:" + params["host_arch"],
145147
],
146148
target_compatible_with = constraints,
147149
toolchain = ":" + name,

config/registration.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def crt_register_toolchains(
3737
native.register_toolchains("@crt//toolchains/cc65:all")
3838

3939
if riscv32:
40-
lowrisc_rv32imcb_repos(local = _maybe_archive(riscv32))
40+
lowrisc_rv32imcb_repos(local = _maybe_archive(riscv32), host_arch = "x86_64")
41+
lowrisc_rv32imcb_repos(local = _maybe_archive(riscv32), host_arch = "aarch64")
4142
native.register_execution_platforms("@crt//platforms/riscv32:all")
4243
native.register_toolchains("@crt//toolchains/lowrisc_rv32imcb:all")
4344

toolchains/lowrisc_rv32imcb/BUILD.bazel

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,51 @@ load("//platforms/riscv32:devices.bzl", "DEVICES")
88
package(default_visibility = ["//visibility:public"])
99

1010
SYSTEM_INCLUDE_PATHS = [
11-
"external/lowrisc_rv32imcb_files/lib/clang/16/include",
12-
"external/lowrisc_rv32imcb_files/riscv32-unknown-elf/include",
13-
"external/lowrisc_rv32imcb_files/riscv32-unknown-elf/include/c++/10.2.0",
14-
"external/lowrisc_rv32imcb_files/riscv32-unknown-elf/include/c++/10.2.0/backward",
15-
"external/lowrisc_rv32imcb_files/riscv32-unknown-elf/include/c++/10.2.0/riscv32-unknown-elf",
11+
"external/lowrisc_rv32imcb_{}_files/lib/clang/16/include",
12+
"external/lowrisc_rv32imcb_{}_files/riscv32-unknown-elf/include",
13+
"external/lowrisc_rv32imcb_{}_files/riscv32-unknown-elf/include/c++/10.2.0",
14+
"external/lowrisc_rv32imcb_{}_files/riscv32-unknown-elf/include/c++/10.2.0/backward",
15+
"external/lowrisc_rv32imcb_{}_files/riscv32-unknown-elf/include/c++/10.2.0/riscv32-unknown-elf",
1616
]
1717

18-
filegroup(
19-
name = "compiler_components",
18+
HOST_ARCHS = [
19+
"x86_64",
20+
"aarch64",
21+
]
22+
23+
[filegroup(
24+
name = "compiler_components" + host_arch,
2025
srcs = [
2126
"//toolchains/lowrisc_rv32imcb/wrappers:all",
22-
"@lowrisc_rv32imcb_files//:all",
27+
"@lowrisc_rv32imcb_{}_files//:all".format(host_arch),
2328
],
24-
)
29+
) for host_arch in HOST_ARCHS]
2530

26-
[setup(
27-
name = device.name,
28-
architecture = device.architecture,
29-
artifact_naming = device.artifact_naming,
30-
compiler_components = ":compiler_components",
31-
constraints = device.constraints,
32-
feature_set = device.feature_set,
33-
include_directories = SYSTEM_INCLUDE_PATHS,
34-
params = {
35-
"compiler": "clang",
36-
},
37-
substitutions = device.substitutions,
38-
tools = {
39-
"ar": "wrappers/ar",
40-
"cpp": "wrappers/cpp",
41-
"gcc": "wrappers/clang",
42-
"gcov": "wrappers/gcov",
43-
"ld": "wrappers/ld",
44-
"nm": "wrappers/nm",
45-
"objcopy": "wrappers/objcopy",
46-
"objdump": "wrappers/objdump",
47-
"strip": "wrappers/strip",
48-
},
49-
) for device in DEVICES]
31+
[
32+
[setup(
33+
name = "{}_{}".format(device.name, host_arch),
34+
architecture = device.architecture,
35+
artifact_naming = device.artifact_naming,
36+
compiler_components = ":compiler_components" + host_arch,
37+
constraints = device.constraints,
38+
feature_set = device.feature_set,
39+
include_directories = [path.format(host_arch) for path in SYSTEM_INCLUDE_PATHS],
40+
params = {
41+
"compiler": "clang",
42+
"host_arch": host_arch,
43+
},
44+
substitutions = device.substitutions,
45+
tools = {
46+
"ar": "wrappers/ar",
47+
"cpp": "wrappers/cpp",
48+
"gcc": "wrappers/clang",
49+
"gcov": "wrappers/gcov",
50+
"ld": "wrappers/ld",
51+
"nm": "wrappers/nm",
52+
"objcopy": "wrappers/objcopy",
53+
"objdump": "wrappers/objdump",
54+
"strip": "wrappers/strip",
55+
},
56+
) for device in DEVICES]
57+
for host_arch in HOST_ARCHS
58+
]

toolchains/lowrisc_rv32imcb/repository.bzl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
load("@crt//rules:repo.bzl", "http_archive_or_local")
66

7-
def lowrisc_rv32imcb_repos(local = None):
7+
def lowrisc_rv32imcb_repos(local = None, host_arch = "x86_64"):
8+
sha256_by_arch = {
9+
"x86_64": "e8cb05d8050773330c61a254f2a6b0fce75da4d4a8951d15570b18429fd21a98",
10+
"aarch64": "1b5df51abe85fb6d3cad24c62082046ab02788ef15e491040b680fcaa35a29ec",
11+
}
812
http_archive_or_local(
9-
name = "lowrisc_rv32imcb_files",
13+
name = "lowrisc_rv32imcb_{}_files".format(host_arch),
1014
local = local,
11-
url = "https://github.com/lowRISC/lowrisc-toolchains/releases/download/20240923-1/lowrisc-toolchain-rv32imcb-20240923-1.tar.xz",
12-
sha256 = "aeea1983553f4c81c6409abcf0d6ca33b5ed4716b2b694e7ff030523cf13486a",
13-
strip_prefix = "lowrisc-toolchain-rv32imcb-20240923-1",
15+
url = "https://github.com/troibe/lowrisc-toolchains/releases/download/20250225-1/lowrisc-toolchain-rv32imcb-{}-20250225-1.tar.xz".format(host_arch),
16+
sha256 = sha256_by_arch[host_arch],
17+
strip_prefix = "lowrisc-toolchain-rv32imcb-{}-20250225-1".format(host_arch),
1418
build_file = Label("//toolchains:BUILD.export_all.bazel"),
1519
)

toolchains/lowrisc_rv32imcb/wrappers/driver.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
PROG=${0##*/}
7-
TOOLCHAIN="lowrisc_rv32imcb_files"
7+
TOOLCHAIN="lowrisc_rv32imcb_$(uname -m)_files"
88
PREFIX="riscv32-unknown-elf"
99

1010
ARGS=()

0 commit comments

Comments
 (0)