Skip to content

build: add experimental support for Zig C/C++ compiler. #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bazel/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -32,6 +33,8 @@ def proxy_wasm_cpp_host_dependencies():
version = "1.58.1",
)

zig_register_toolchains()

# Core dependencies.

protobuf_deps()
Expand Down
29 changes: 28 additions & 1 deletion bazel/external/v8.patch
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"],
)

16 changes: 12 additions & 4 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down