Skip to content

Commit 743e0d9

Browse files
committed
chore: use toolchains_llvm with clang 18 for cross-compile toolchain
Zig CC had linking errors with -latomic (a seemingly recurrent issue with zig), which is required by the new V8 version. Instead, llvm can be used. Signed-off-by: Matt Leon <[email protected]>
1 parent 482a5cd commit 743e0d9

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

.bazelrc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ build:gcc --action_env=CXX=g++
6969

7070
# Use Zig C/C++ compiler.
7171
build:zig-cc --incompatible_enable_cc_toolchain_resolution
72-
build:zig-cc --extra_toolchains @zig_sdk//:aarch64-linux-gnu.2.28_toolchain
73-
build:zig-cc --extra_toolchains @zig_sdk//:x86_64-linux-gnu.2.28_toolchain
72+
build:zig-cc --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
73+
build:zig-cc --extra_toolchains @llvm_toolchain//:cc-toolchain-x86_64-linux
74+
build:zig-cc --extra_toolchains @llvm_aarch64//:cc-toolchain-aarch64-linux
75+
build:zig-cc --extra_toolchains @emsdk//emscripten_toolchain:cc-toolchain-wasm
7476
build:zig-cc --host_copt=-fno-sanitize=undefined
7577

7678
# Use Zig C/C++ compiler (cross-compile to Linux/aarch64).
7779
build:zig-cc-linux-aarch64 --config=zig-cc
78-
build:zig-cc-linux-aarch64 --platforms @zig_sdk//:linux_aarch64_platform
79-
build:zig-cc-linux-aarch64 --run_under=qemu-aarch64-static
80-
build:zig-cc-linux-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
80+
#build:zig-cc-linux-aarch64 --platforms @zig_sdk//platform:linux_arm64
81+
build:zig-cc-linux-aarch64 --platforms @toolchains_llvm//platforms:linux-aarch64
82+
build:zig-cc-linux-aarch64 --cxxopt --gcc-install-dir=external/sysroot_linux_arm64/usr/lib/gcc/aarch64-linux-gnu/13/
8183

8284
build --enable_platform_specific_config
8385

@@ -86,6 +88,11 @@ build:linux --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
8688
build:macos --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
8789
build:windows --cxxopt="/std:c++20" --host_cxxopt="/std:c++20"
8890

91+
# For Zig C/C++ compiler.
92+
build:linux --sandbox_add_mount_pair=/tmp
93+
build:macos --sandbox_add_mount_pair=/var/tmp
94+
build:windows --sandbox_add_mount_pair=C:\Temp
95+
8996
# Enable symlinks and runfiles on Windows (enabled by default on other platforms).
9097
startup --windows_enable_symlinks
9198
build:windows --enable_runfiles

bazel/dependencies.bzl

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "register_toolchains")
1615
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
16+
load("@envoy_toolshed//sysroot:sysroot.bzl", "setup_sysroots")
1717
load("@proxy_wasm_cpp_host//bazel/cargo/wasmsign/remote:crates.bzl", wasmsign_crate_repositories = "crate_repositories")
1818
load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:crates.bzl", wasmtime_crate_repositories = "crate_repositories")
1919
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
2020
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
2121
load("@rules_rust//rust:repositories.bzl", "rust_repositories", "rust_repository_set")
22+
load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")
23+
load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")
2224

2325
def proxy_wasm_cpp_host_dependencies():
2426
# Bazel extensions.
@@ -52,14 +54,32 @@ def proxy_wasm_cpp_host_dependencies():
5254
)
5355
crate_universe_dependencies(bootstrap = True)
5456

55-
zig_register_toolchains(
56-
version = "0.9.1",
57-
url_format = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.tar.xz",
58-
host_platform_sha256 = {
59-
"linux-aarch64": "5d99a39cded1870a3fa95d4de4ce68ac2610cca440336cfd252ffdddc2b90e66",
60-
"linux-x86_64": "be8da632c1d3273f766b69244d80669fe4f5e27798654681d77c992f17c237d7",
61-
"macos-aarch64": "8c473082b4f0f819f1da05de2dbd0c1e891dff7d85d2c12b6ee876887d438287",
62-
"macos-x86_64": "2d94984972d67292b55c1eb1c00de46580e9916575d083003546e9a01166754c",
57+
setup_sysroots()
58+
bazel_toolchain_dependencies()
59+
llvm_toolchain(
60+
name = "llvm_toolchain",
61+
llvm_version = "18.1.8",
62+
sha256 = {
63+
"linux-x86_64": "54ec30358afcc9fb8aa74307db3046f5187f9fb89fb37064cdde906e062ebf36",
64+
},
65+
strip_prefix = {
66+
"linux-x86_64": "clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04",
67+
},
68+
urls = {
69+
"linux-x86_64": [
70+
"https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz",
71+
],
72+
},
73+
)
74+
75+
llvm_toolchain(
76+
name = "llvm_aarch64",
77+
llvm_version = "18.1.8",
78+
toolchain_roots = {
79+
"": "@llvm_toolchain_llvm//",
80+
},
81+
sysroot = {
82+
"linux-aarch64": "@sysroot_linux_arm64//:sysroot",
6383
},
6484
)
6585

bazel/dependencies_import.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ load("@fuzzing_py_deps//:requirements.bzl", pip_fuzzing_dependencies = "install_
1616
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
1717
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
1818
load("@v8_python_deps//:requirements.bzl", pip_v8_dependencies = "install_deps")
19+
load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
1920

2021
def proxy_wasm_cpp_host_dependencies_import():
22+
llvm_register_toolchains()
23+
2124
rules_foreign_cc_dependencies()
2225
rules_fuzzing_dependencies()
2326

bazel/repositories.bzl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ def proxy_wasm_cpp_host_repositories():
6060

6161
maybe(
6262
http_archive,
63-
name = "bazel-zig-cc",
64-
sha256 = "ff89e0220c72cdc774e451a35e5c3b9f1593d0df71341844b2108c181ac0eef9",
65-
strip_prefix = "hermetic_cc_toolchain-0.4.4",
66-
url = "https://github.com/uber/hermetic_cc_toolchain/archive/refs/tags/v0.4.4.tar.gz",
63+
name = "envoy_toolshed",
64+
sha256 = "e2252e46e64417d5cedd9f1eb34a622bce5e13b43837e5fe051c83066b0a400b",
65+
strip_prefix = "toolshed-bazel-bins-v0.1.13/bazel",
66+
url = "https://github.com/envoyproxy/toolshed/archive/refs/tags/bazel-bins-v0.1.13.tar.gz",
67+
)
68+
maybe(
69+
http_archive,
70+
name = "toolchains_llvm",
71+
sha256 = "b7cd301ef7b0ece28d20d3e778697a5e3b81828393150bed04838c0c52963a01",
72+
strip_prefix = "toolchains_llvm-0.10.3",
73+
canonical_id = "v0.10.3",
74+
url = "https://github.com/grailbio/bazel-toolchain/releases/download/0.10.3/toolchains_llvm-0.10.3.tar.gz",
6775
)
6876

6977
maybe(
@@ -191,6 +199,7 @@ def proxy_wasm_cpp_host_repositories():
191199
maybe(
192200
http_archive,
193201
name = "highway",
202+
sha256 = "7e0be78b8318e8bdbf6fa545d2ecb4c90f947df03f7aadc42c1967f019e63343",
194203
urls = [
195204
"https://github.com/google/highway/archive/refs/tags/1.2.0.tar.gz",
196205
],
@@ -200,6 +209,7 @@ def proxy_wasm_cpp_host_repositories():
200209
maybe(
201210
http_archive,
202211
name = "fast_float",
212+
sha256 = "d2a08e722f461fe699ba61392cd29e6b23be013d0f56e50c7786d0954bffcb17",
203213
urls = [
204214
"https://github.com/fastfloat/fast_float/archive/refs/tags/v7.0.0.tar.gz",
205215
],
@@ -231,6 +241,7 @@ def proxy_wasm_cpp_host_repositories():
231241
maybe(
232242
http_archive,
233243
name = "simdutf",
244+
sha256 = "512374f8291d3daf102ccd0ad223b1a8318358f7c1295efd4d9a3abbb8e4b6ff",
234245
urls = [
235246
"https://github.com/simdutf/simdutf/releases/download/v7.3.0/singleheader.zip",
236247
],

0 commit comments

Comments
 (0)