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 all commits
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
12 changes: 12 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
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
8 changes: 8 additions & 0 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