From 2aec0fb946d55a41f2cb5e83f5e74da4179028d6 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sun, 6 Feb 2022 23:40:08 -0800 Subject: [PATCH 1/3] 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/proxy-wasm-cpp-host#243 for a workaround. Signed-off-by: Piotr Sikora --- .bazelrc | 12 ++++++++++++ .github/workflows/cpp.yml | 9 ++++++++- bazel/dependencies.bzl | 3 +++ bazel/external/v8.patch | 29 ++++++++++++++++++++++++++++- bazel/repositories.bzl | 16 ++++++++++++---- 5 files changed, 63 insertions(+), 6 deletions(-) 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..b4ea32990 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -121,6 +121,13 @@ 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 - name: 'V8 on macOS/x86_64' runtime: 'v8' repo: 'v8' @@ -181,7 +188,7 @@ jobs: - uses: actions/checkout@v2 - name: Activate Docker/QEMU - if: startsWith(matrix.run_under, 'docker') + if: ${{ matrix.arch != 'x86_64' }} run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - name: Set cache key 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/external/v8.patch b/bazel/external/v8.patch index b13fad255..b062eaedd 100644 --- a/bazel/external/v8.patch +++ b/bazel/external/v8.patch @@ -1,4 +1,5 @@ -# Disable pointer compression (limits the maximum number of WasmVMs). +# 1. Disable pointer compression (limits the maximum number of WasmVMs). +# 2. Don't override v8_target_cpu (https://crrev.com/c/3445204). diff --git a/BUILD.bazel b/BUILD.bazel index 1cc0121e60..4947c1dba2 100644 @@ -13,3 +14,29 @@ index 1cc0121e60..4947c1dba2 100644 ) # Default setting for v8_enable_pointer_compression. +diff --git a/bazel/defs.bzl b/bazel/defs.bzl +index fe27db305b..dee5e69cc4 100644 +--- a/bazel/defs.bzl ++++ b/bazel/defs.bzl +@@ -372,6 +372,12 @@ def v8_torque(name, noicu_srcs, icu_srcs, args, extras): + ) + + def _v8_target_cpu_transition_impl(settings, attr): ++ # Check for an existing v8_target_cpu flag. ++ if "@v8//bazel/config:v8_target_cpu" in settings: ++ if settings["@v8//bazel/config:v8_target_cpu"] != "none": ++ return ++ ++ # Auto-detect target architecture based on the --cpu flag. + mapping = { + "haswell": "x64", + "k8": "x64", +@@ -395,7 +401,7 @@ def _v8_target_cpu_transition_impl(settings, attr): + # on the command line. + v8_target_cpu_transition = transition( + implementation = _v8_target_cpu_transition_impl, +- inputs = ["//command_line_option:cpu"], ++ inputs = ["@v8//bazel/config:v8_target_cpu", "//command_line_option:cpu"], + outputs = ["@v8//bazel/config:v8_target_cpu"], + ) + diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index bef81aa7b..9ef16187a 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", @@ -59,10 +67,10 @@ def proxy_wasm_cpp_host_repositories(): maybe( http_archive, name = "boringssl", - # 2022-01-10 (master-with-bazel) - sha256 = "a530919e3141d00d593a0d74cd0f9f88707e35ec58bb62245968fec16cb9257f", - strip_prefix = "boringssl-9420fb54116466923afa1f34a23dd8a4a7ddb69d", - urls = ["https://github.com/google/boringssl/archive/9420fb54116466923afa1f34a23dd8a4a7ddb69d.tar.gz"], + # 2022-02-07 (master-with-bazel) + sha256 = "7dec97795a7ac7e3832228e4440ee06cceb18d3663f4580b0840e685281e28a0", + strip_prefix = "boringssl-eaa29f431f71b8121e1da76bcd3ddc2248238ade", + urls = ["https://github.com/google/boringssl/archive/eaa29f431f71b8121e1da76bcd3ddc2248238ade.tar.gz"], ) maybe( From 884d7df2f5000453f8b977e52c3811bd9f75bada Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 8 Feb 2022 05:11:22 -0800 Subject: [PATCH 2/3] review: install deps. Signed-off-by: Piotr Sikora --- .github/workflows/cpp.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index b4ea32990..789801043 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -128,6 +128,7 @@ jobs: 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' @@ -187,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: ${{ matrix.arch != 'x86_64' }} run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes From e4e12317362b57cac52d51061e6a1ecb1a432052 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 8 Feb 2022 06:43:26 -0800 Subject: [PATCH 3/3] review: we're calling QEMU directly, so binfmt isn't needed. Signed-off-by: Piotr Sikora --- .github/workflows/cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 789801043..fbccd0c92 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -193,7 +193,7 @@ jobs: run: sudo apt-get install -y ${{ matrix.deps }} - name: Activate Docker/QEMU - if: ${{ matrix.arch != 'x86_64' }} + if: startsWith(matrix.run_under, 'docker') run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - name: Set cache key