diff --git a/.bazelrc b/.bazelrc index 4dd21abda..4168ef49b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -8,6 +8,18 @@ build:clang --action_env=BAZEL_COMPILER=clang build:clang --action_env=CC=clang build:clang --action_env=CXX=clang++ +# Use Zig C/C++ compiler. +build:zig-cc --incompatible_enable_cc_toolchain_resolution +build:zig-cc --extra_toolchains @zig_sdk//:aarch64-linux-gnu.2.28_toolchain +build:zig-cc --extra_toolchains @zig_sdk//:x86_64-linux-gnu.2.28_toolchain +build:zig-cc --host_copt=-fno-sanitize=undefined + +# Use Zig C/C++ compiler (cross-compile to Linux/aarch64). +build:zig-cc-linux-aarch64 --config=zig-cc +build:zig-cc-linux-aarch64 --platforms @zig_sdk//:linux_aarch64_platform +build:zig-cc-linux-aarch64 --run_under=qemu-aarch64-static +build:zig-cc-linux-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/ + build --enable_platform_specific_config build:linux --cxxopt=-std=c++17 diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index b85d0ffdc..fbccd0c92 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -121,6 +121,14 @@ jobs: arch: x86_64 action: test flags: --config=clang --define=crypto=system + - name: 'V8 on Linux/aarch64' + runtime: 'v8' + repo: 'v8' + os: ubuntu-20.04 + arch: aarch64 + action: test + flags: --config=zig-cc-linux-aarch64 --@v8//bazel/config:v8_target_cpu=arm64 + deps: qemu-user-static libc6-arm64-cross - name: 'V8 on macOS/x86_64' runtime: 'v8' repo: 'v8' @@ -180,6 +188,10 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install dependencies (Linux) + if: ${{ matrix.deps != '' && startsWith(matrix.os, 'ubuntu') }} + run: sudo apt-get install -y ${{ matrix.deps }} + - name: Activate Docker/QEMU if: startsWith(matrix.run_under, 'docker') run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes diff --git a/bazel/dependencies.bzl b/bazel/dependencies.bzl index f484c94d5..58fb30306 100644 --- a/bazel/dependencies.bzl +++ b/bazel/dependencies.bzl @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel-zig-cc//toolchain:defs.bzl", zig_register_toolchains = "register_toolchains") load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") load("@proxy_wasm_cpp_host//bazel/cargo/wasmsign:crates.bzl", "wasmsign_fetch_remote_crates") load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime:crates.bzl", "wasmtime_fetch_remote_crates") @@ -32,6 +33,8 @@ def proxy_wasm_cpp_host_dependencies(): version = "1.58.1", ) + zig_register_toolchains() + # Core dependencies. protobuf_deps() diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 376b9cba1..ffa3a22b2 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -29,6 +29,14 @@ def proxy_wasm_cpp_host_repositories(): sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d", ) + maybe( + http_archive, + name = "bazel-zig-cc", + sha256 = "ad6384b4d16ebb3e5047df6548a195e598346da84e5f320250beb9198705ac81", + strip_prefix = "bazel-zig-cc-v0.4.4", + url = "https://git.sr.ht/~motiejus/bazel-zig-cc/archive/v0.4.4.tar.gz", + ) + maybe( http_archive, name = "rules_foreign_cc",