Skip to content

Commit 1dee401

Browse files
committed
Implement support for macOS Apple Silicon => x86_64 cross compilation
1 parent c761353 commit 1dee401

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.bazelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ build:macos --copt='-femit-dwarf-unwind=no-compact-unwind'
221221
# TODO(soon): File a bazel issue for the flag so we can drop this.
222222
build:macos --experimental_objc_fastbuild_options=""
223223

224+
# Cross-Compilation
225+
# Only cross-compiling on macOS from Apple Silicon to x86_64 is supported – using apple_support
226+
# makes this much easier than on other platforms. We could define a configuration for cross-
227+
# compiling from Intel Mac too, but it lacks a means to run Apple Silicon binaries. We would have to
228+
# change V8 mksnapshot to build in the host configuration again (effectively compiling much of V8
229+
# twice) and couldn't run tests, so it would provide little value.
230+
#
231+
# Define the target platform
232+
build:macos-cross-x86_64 --cpu=darwin_x86_64 --host_cpu=darwin_arm64 --platforms //:macOS_x86
233+
# Some cross-compiled tests are slower when run over Rosetta, increase the medium test size timeout.
234+
# Test performance is still very much satisfactory considering that emulation is being used here.
235+
build:macos-cross-x86_64 --test_timeout=1,30,60,240
236+
224237
# On Linux, always link libc++ statically to avoid compatibility issues with different OS versions.
225238
# macOS links with dynamic libc++ by default, which has good backwards compatibility.
226239
# Drop default link flags, which include libstdc++ for Linux

BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ platform(
4646
],
4747
)
4848

49+
# Used for cross-compilation
50+
platform(
51+
name = "macOS_x86",
52+
constraint_values = [
53+
"@platforms//os:macos",
54+
"@platforms//cpu:x86_64",
55+
],
56+
)
57+
4958
# bazel enables the --ffunction-sections, --gc-sections flags used to remove dead code by default
5059
# on Linux opt builds. Enable the equivalent macOS flag -Wl,-dead_strip here to work around bazel
5160
# idiosyncrasies.

WORKSPACE

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ rules_rust_dependencies()
178178

179179
rust_register_toolchains(
180180
edition = "2021",
181-
# Rust registers wasm targets by default which we don't need, workerd is only built for its native platform.
182-
extra_target_triples = [],
181+
# Add support macOS cross-compilation, the overhead for this is limited with only a few more
182+
# targets being generated for the extra triple as part of the toolchain. Setting this explicitly
183+
# also avoids registering support for the wasm32-unknown-unknown and wasm32-wasi targets, which
184+
# are otherwise added by default.
185+
extra_target_triples = ["x86_64-apple-darwin"],
183186
versions = ["1.81.0"], # LLVM 18
184187
)
185188

0 commit comments

Comments
 (0)