Skip to content
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
13 changes: 13 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ build:macos --copt='-femit-dwarf-unwind=no-compact-unwind'
# TODO(soon): File a bazel issue for the flag so we can drop this.
build:macos --experimental_objc_fastbuild_options=""

# Cross-Compilation
# Only cross-compiling on macOS from Apple Silicon to x86_64 is supported – using apple_support
# makes this much easier than on other platforms. We could define a configuration for cross-
# compiling from Intel Mac too, but it lacks a means to run Apple Silicon binaries. We would have to
# change V8 mksnapshot to build in the host configuration again (effectively compiling much of V8
# twice) and couldn't run tests, so it would provide little value.
#
# Define the target platform
build:macos-cross-x86_64 --cpu=darwin_x86_64 --host_cpu=darwin_arm64 --platforms //:macOS_x86
# Some cross-compiled tests are slower when run over Rosetta, increase the medium test size timeout.
# Test performance is still very much satisfactory considering that emulation is being used here.
build:macos-cross-x86_64 --test_timeout=1,30,60,240

# On Linux, always link libc++ statically to avoid compatibility issues with different OS versions.
# macOS links with dynamic libc++ by default, which has good backwards compatibility.
# Drop default link flags, which include libstdc++ for Linux
Expand Down
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ platform(
],
)

# Used for cross-compilation
platform(
name = "macOS_x86",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

# bazel enables the --ffunction-sections, --gc-sections flags used to remove dead code by default
# on Linux opt builds. Enable the equivalent macOS flag -Wl,-dead_strip here to work around bazel
# idiosyncrasies.
Expand Down
7 changes: 5 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ rules_rust_dependencies()

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

Expand Down