Skip to content

Commit 77e5d66

Browse files
committed
feat: Support cross compiles from linux to macos
Upstreaming an internal patch we've been using for cross compiling the aspect CLI from a linux machine to mac. We've been using a slightly different version of this for quite some time now so I cleaned up the logic significatly so it could be upstreamed.
1 parent 69d3996 commit 77e5d66

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

toolchain/cc_toolchain_config.bzl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,17 @@ def cc_toolchain_config(
168168
archive_flags = []
169169

170170
# Linker flags:
171-
if exec_os == "darwin" and not is_xcompile:
172-
# lld is experimental for Mach-O, so we use the native ld64 linker.
173-
# TODO: How do we cross-compile from Linux to Darwin?
174-
use_lld = False
171+
ld = "ld.lld"
172+
if target_os == "darwin":
173+
use_lld = True
174+
175+
ld = "ld64.lld"
176+
ld_path = toolchain_path_prefix + "/bin/" + ld
177+
compile_flags.append("-mmacosx-version-min=12.0")
175178
link_flags.extend([
179+
"-mmacosx-version-min=12.0",
180+
"-Wl,-platform_version,macos,12.0,12.0",
181+
"--ld-path=" + ld_path,
176182
"-headerpad_max_install_names",
177183
"-fobjc-link-runtime",
178184
])
@@ -195,7 +201,9 @@ def cc_toolchain_config(
195201
# not an option because it is not a cross-linker, so lld is the
196202
# only option.
197203
use_lld = True
204+
ld_path = toolchain_path_prefix + "/bin/" + ld
198205
link_flags.extend([
206+
"--ld-path=" + ld_path,
199207
"-fuse-ld=lld",
200208
"-Wl,--build-id=md5",
201209
"-Wl,--hash-style=gnu",
@@ -323,7 +331,7 @@ def cc_toolchain_config(
323331
"dwp": tools_path_prefix + "llvm-dwp",
324332
"gcc": wrapper_bin_prefix + "cc_wrapper.sh",
325333
"gcov": tools_path_prefix + "llvm-profdata",
326-
"ld": tools_path_prefix + "ld.lld" if use_lld else "/usr/bin/ld",
334+
"ld": tools_path_prefix + ld if use_lld else "/usr/bin/ld",
327335
"llvm-cov": tools_path_prefix + "llvm-cov",
328336
"llvm-profdata": tools_path_prefix + "llvm-profdata",
329337
"nm": tools_path_prefix + "llvm-nm",

toolchain/internal/common.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _toolchain_tools = {
2828
for name in [
2929
"clang-cpp",
3030
"ld.lld",
31+
"ld64.lld",
3132
"llvm-ar",
3233
"llvm-dwp",
3334
"llvm-profdata",

0 commit comments

Comments
 (0)