Skip to content

Commit 5a61399

Browse files
authored
build: add experimental support for Zig C/C++ compiler. (proxy-wasm#246)
This currently doesn't work with rules_rust, so Rust targets, including the test data, cannot be built when using it. See proxy-wasm#243 for a workaround. Signed-off-by: Piotr Sikora <[email protected]>
1 parent d4912fa commit 5a61399

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ 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
131+
deps: qemu-user-static libc6-arm64-cross
124132
- name: 'V8 on macOS/x86_64'
125133
runtime: 'v8'
126134
repo: 'v8'
@@ -180,6 +188,10 @@ jobs:
180188
steps:
181189
- uses: actions/checkout@v2
182190

191+
- name: Install dependencies (Linux)
192+
if: ${{ matrix.deps != '' && startsWith(matrix.os, 'ubuntu') }}
193+
run: sudo apt-get install -y ${{ matrix.deps }}
194+
183195
- name: Activate Docker/QEMU
184196
if: startsWith(matrix.run_under, 'docker')
185197
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

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/repositories.bzl

Lines changed: 8 additions & 0 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",

0 commit comments

Comments
 (0)