Skip to content

Commit 66054cc

Browse files
authored
build: add rust target for macOS cross compiles
When we build the macOS pkg, we build Node.js twice (on arm64): - Once for arm64 (native) - Once for x64, using a combination of Rosetta 2 and compiler flags before combining both into a universal binary. For the x64 case, pass target flag to `rustc` so that the binary is built for the correct target architecture. Signed-off-by: Richard Lau <[email protected]> PR-URL: #63015 Reviewed-By: Stewart X Addison <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent f625c4b commit 66054cc

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

configure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,10 @@ def configure_node(o):
18551855
if flavor == 'win':
18561856
o['variables']['cargo_rust_target'] = \
18571857
'aarch64-pc-windows-msvc' if target_arch == 'arm64' else 'x86_64-pc-windows-msvc'
1858+
# Always set the Rust target for x64 macOS in case we will be building
1859+
# under Rosetta 2.
1860+
if flavor == 'mac' and target_arch == 'x64':
1861+
o['variables']['cargo_rust_target'] = 'x86_64-apple-darwin'
18581862

18591863
# Allow overriding the compiler - needed by embedders.
18601864
if options.use_clang:

deps/crates/crates.gyp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
},
1212
'conditions': [
1313
['cargo_rust_target!=""', {
14+
'variables': {
15+
'cargo_build_flags': ['--target', '<(cargo_rust_target)'],
16+
}
17+
}],
18+
['OS=="win"', {
1419
'variables': {
1520
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/$(Platform)/release/node_crates.lib',
1621
},
1722
}, {
1823
'variables': {
19-
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/release/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
24+
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/<(cargo_rust_target)/release/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
2025
},
2126
}],
2227
],
@@ -25,13 +30,13 @@
2530
'cargo_build_flags': [],
2631
},
2732
'conditions': [
28-
['cargo_rust_target!=""', {
33+
['OS=="win"', {
2934
'variables': {
3035
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/$(Platform)/debug/node_crates.lib',
3136
},
3237
}, {
3338
'variables': {
34-
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/debug/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
39+
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/<(cargo_rust_target)/debug/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
3540
},
3641
}],
3742
],
@@ -62,7 +67,7 @@
6267
],
6368
},
6469
'conditions': [
65-
['cargo_rust_target!=""', {
70+
['OS=="win"', {
6671
'actions': [
6772
{
6873
'action_name': 'cargo_build',

0 commit comments

Comments
 (0)