Skip to content

Commit 2aec0fb

Browse files
committed
build: add experimental support for Zig C/C++ compiler.
Note that bazel-zig-cc breaks rules_rust, so the Rust test data cannot be build when using it, which prevents test binaries from being built. See proxy-wasm#243 for a workaround. Signed-off-by: Piotr Sikora <[email protected]>
1 parent 438bf5d commit 2aec0fb

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

.bazelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ build:clang --action_env=BAZEL_COMPILER=clang
88
build:clang --action_env=CC=clang
99
build:clang --action_env=CXX=clang++
1010

11+
# Use Zig C/C++ compiler.
12+
build:zig-cc --incompatible_enable_cc_toolchain_resolution
13+
build:zig-cc --extra_toolchains @zig_sdk//:aarch64-linux-gnu.2.28_toolchain
14+
build:zig-cc --extra_toolchains @zig_sdk//:x86_64-linux-gnu.2.28_toolchain
15+
build:zig-cc --host_copt=-fno-sanitize=undefined
16+
17+
# Use Zig C/C++ compiler (cross-compile to Linux/aarch64).
18+
build:zig-cc-linux-aarch64 --config=zig-cc
19+
build:zig-cc-linux-aarch64 --platforms @zig_sdk//:linux_aarch64_platform
20+
build:zig-cc-linux-aarch64 --run_under=qemu-aarch64-static
21+
build:zig-cc-linux-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
22+
1123
build --enable_platform_specific_config
1224

1325
build:linux --cxxopt=-std=c++17

.github/workflows/cpp.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ jobs:
121121
arch: x86_64
122122
action: test
123123
flags: --config=clang --define=crypto=system
124+
- name: 'V8 on Linux/aarch64'
125+
runtime: 'v8'
126+
repo: 'v8'
127+
os: ubuntu-20.04
128+
arch: aarch64
129+
action: test
130+
flags: --config=zig-cc-linux-aarch64 --@v8//bazel/config:v8_target_cpu=arm64
124131
- name: 'V8 on macOS/x86_64'
125132
runtime: 'v8'
126133
repo: 'v8'
@@ -181,7 +188,7 @@ jobs:
181188
- uses: actions/checkout@v2
182189

183190
- name: Activate Docker/QEMU
184-
if: startsWith(matrix.run_under, 'docker')
191+
if: ${{ matrix.arch != 'x86_64' }}
185192
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
186193

187194
- name: Set cache key

bazel/dependencies.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
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")
1516
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
1617
load("@proxy_wasm_cpp_host//bazel/cargo/wasmsign:crates.bzl", "wasmsign_fetch_remote_crates")
1718
load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime:crates.bzl", "wasmtime_fetch_remote_crates")
@@ -32,6 +33,8 @@ def proxy_wasm_cpp_host_dependencies():
3233
version = "1.58.1",
3334
)
3435

36+
zig_register_toolchains()
37+
3538
# Core dependencies.
3639

3740
protobuf_deps()

bazel/external/v8.patch

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Disable pointer compression (limits the maximum number of WasmVMs).
1+
# 1. Disable pointer compression (limits the maximum number of WasmVMs).
2+
# 2. Don't override v8_target_cpu (https://crrev.com/c/3445204).
23

34
diff --git a/BUILD.bazel b/BUILD.bazel
45
index 1cc0121e60..4947c1dba2 100644
@@ -13,3 +14,29 @@ index 1cc0121e60..4947c1dba2 100644
1314
)
1415

1516
# Default setting for v8_enable_pointer_compression.
17+
diff --git a/bazel/defs.bzl b/bazel/defs.bzl
18+
index fe27db305b..dee5e69cc4 100644
19+
--- a/bazel/defs.bzl
20+
+++ b/bazel/defs.bzl
21+
@@ -372,6 +372,12 @@ def v8_torque(name, noicu_srcs, icu_srcs, args, extras):
22+
)
23+
24+
def _v8_target_cpu_transition_impl(settings, attr):
25+
+ # Check for an existing v8_target_cpu flag.
26+
+ if "@v8//bazel/config:v8_target_cpu" in settings:
27+
+ if settings["@v8//bazel/config:v8_target_cpu"] != "none":
28+
+ return
29+
+
30+
+ # Auto-detect target architecture based on the --cpu flag.
31+
mapping = {
32+
"haswell": "x64",
33+
"k8": "x64",
34+
@@ -395,7 +401,7 @@ def _v8_target_cpu_transition_impl(settings, attr):
35+
# on the command line.
36+
v8_target_cpu_transition = transition(
37+
implementation = _v8_target_cpu_transition_impl,
38+
- inputs = ["//command_line_option:cpu"],
39+
+ inputs = ["@v8//bazel/config:v8_target_cpu", "//command_line_option:cpu"],
40+
outputs = ["@v8//bazel/config:v8_target_cpu"],
41+
)
42+

bazel/repositories.bzl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def proxy_wasm_cpp_host_repositories():
2929
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
3030
)
3131

32+
maybe(
33+
http_archive,
34+
name = "bazel-zig-cc",
35+
sha256 = "ad6384b4d16ebb3e5047df6548a195e598346da84e5f320250beb9198705ac81",
36+
strip_prefix = "bazel-zig-cc-v0.4.4",
37+
url = "https://git.sr.ht/~motiejus/bazel-zig-cc/archive/v0.4.4.tar.gz",
38+
)
39+
3240
maybe(
3341
http_archive,
3442
name = "rules_foreign_cc",
@@ -59,10 +67,10 @@ def proxy_wasm_cpp_host_repositories():
5967
maybe(
6068
http_archive,
6169
name = "boringssl",
62-
# 2022-01-10 (master-with-bazel)
63-
sha256 = "a530919e3141d00d593a0d74cd0f9f88707e35ec58bb62245968fec16cb9257f",
64-
strip_prefix = "boringssl-9420fb54116466923afa1f34a23dd8a4a7ddb69d",
65-
urls = ["https://github.com/google/boringssl/archive/9420fb54116466923afa1f34a23dd8a4a7ddb69d.tar.gz"],
70+
# 2022-02-07 (master-with-bazel)
71+
sha256 = "7dec97795a7ac7e3832228e4440ee06cceb18d3663f4580b0840e685281e28a0",
72+
strip_prefix = "boringssl-eaa29f431f71b8121e1da76bcd3ddc2248238ade",
73+
urls = ["https://github.com/google/boringssl/archive/eaa29f431f71b8121e1da76bcd3ddc2248238ade.tar.gz"],
6674
)
6775

6876
maybe(

0 commit comments

Comments
 (0)