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 <richard.lau@ibm.com>
PR-URL: https://github.com/nodejs/node/pull/63015
Reviewed-By: Stewart X Addison <sxa@redhat.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Richard Lau authored and GitHub committed 2026-04-30 15:23:41 +00:00
1 parent f625c4b9e3
commit 66054cc90e
2 files changed
+13 -4

No files matched your search

+4
View File
@@ -1855,6 +1855,10 @@ def configure_node(o):
if flavor == 'win':
o['variables']['cargo_rust_target'] = \
'aarch64-pc-windows-msvc' if target_arch == 'arm64' else 'x86_64-pc-windows-msvc'
# Always set the Rust target for x64 macOS in case we will be building
# under Rosetta 2.
if flavor == 'mac' and target_arch == 'x64':
o['variables']['cargo_rust_target'] = 'x86_64-apple-darwin'
# Allow overriding the compiler - needed by embedders.
if options.use_clang:
+9 -4
View File
@@ -11,12 +11,17 @@
},
'conditions': [
['cargo_rust_target!=""', {
'variables': {
'cargo_build_flags': ['--target', '<(cargo_rust_target)'],
}
}],
['OS=="win"', {
'variables': {
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/$(Platform)/release/node_crates.lib',
},
}, {
'variables': {
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/release/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/<(cargo_rust_target)/release/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
},
}],
],
@@ -25,13 +30,13 @@
'cargo_build_flags': [],
},
'conditions': [
['cargo_rust_target!=""', {
['OS=="win"', {
'variables': {
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/$(Platform)/debug/node_crates.lib',
},
}, {
'variables': {
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/debug/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
'node_crates_libpath': '<(SHARED_INTERMEDIATE_DIR)/<(cargo_rust_target)/debug/<(STATIC_LIB_PREFIX)node_crates<(STATIC_LIB_SUFFIX)',
},
}],
],
@@ -62,7 +67,7 @@
],
},
'conditions': [
['cargo_rust_target!=""', {
['OS=="win"', {
'actions': [
{
'action_name': 'cargo_build',