Skip to content

Commit

Permalink
build: fix arm64 host cross-compilation in GN
Browse files Browse the repository at this point in the history
Should use `current_cpu` instead of `target_cpu` in GN build files,
otherwise the host build may use wrong configs when doing cross
compilation.

PR-URL: nodejs#51903
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
zcbenz committed Mar 6, 2024
1 parent d96606d commit 384fd17
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
20 changes: 10 additions & 10 deletions deps/base64/unofficial.gni
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ template("base64_gn_build") {
} else {
defines = []
}
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
defines += [
"HAVE_SSSE3=1",
"HAVE_SSE41=1",
Expand All @@ -29,10 +29,10 @@ template("base64_gn_build") {
"HAVE_AVX512=1",
]
}
if (target_cpu == "arm") {
if (current_cpu == "arm") {
defines += [ "HAVE_NEON32=1" ]
}
if (target_cpu == "arm64") {
if (current_cpu == "arm64") {
defines += [ "HAVE_NEON64=1" ]
}
if (is_clang || !is_win) {
Expand Down Expand Up @@ -69,7 +69,7 @@ template("base64_gn_build") {
source_set("base64_ssse3") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/ssse3/codec.c" ]
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_clang || !is_win) {
cflags_c = [ "-mssse3" ]
}
Expand All @@ -79,7 +79,7 @@ template("base64_gn_build") {
source_set("base64_sse41") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/sse41/codec.c" ]
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_clang || !is_win) {
cflags_c = [ "-msse4.1" ]
}
Expand All @@ -89,7 +89,7 @@ template("base64_gn_build") {
source_set("base64_sse42") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/sse42/codec.c" ]
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_clang || !is_win) {
cflags_c = [ "-msse4.2" ]
}
Expand All @@ -99,7 +99,7 @@ template("base64_gn_build") {
source_set("base64_avx") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/avx/codec.c" ]
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_clang || !is_win) {
cflags_c = [ "-mavx" ]
} else if (is_win) {
Expand All @@ -111,7 +111,7 @@ template("base64_gn_build") {
source_set("base64_avx2") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/avx2/codec.c" ]
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_clang || !is_win) {
cflags_c = [ "-mavx2" ]
} else if (is_win) {
Expand All @@ -123,7 +123,7 @@ template("base64_gn_build") {
source_set("base64_avx512") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/avx512/codec.c" ]
if (target_cpu == "x86" || target_cpu == "x64") {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_clang || !is_win) {
cflags_c = [
"-mavx512vl",
Expand All @@ -138,7 +138,7 @@ template("base64_gn_build") {
source_set("base64_neon32") {
configs += [ ":base64_internal_config" ]
sources = [ "base64/lib/arch/neon32/codec.c" ]
if (target_cpu == "arm") {
if (current_cpu == "arm") {
if (is_clang || !is_win) {
cflags_c = [ "-mfpu=neon" ]
}
Expand Down
22 changes: 11 additions & 11 deletions deps/openssl/unofficial.gni
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,29 @@ template("openssl_gn_build") {

config_path_name = ""
if (is_win) {
if (target_cpu == "x86") {
if (current_cpu == "x86") {
config_path_name = "VC-WIN32"
} else if (target_cpu == "x64") {
} else if (current_cpu == "x64") {
config_path_name = "VC-WIN64A"
} else if (target_cpu == "arm64") {
} else if (current_cpu == "arm64") {
config_path_name = "VC-WIN64-ARM"
}
} else if (is_linux) {
if (target_cpu == "x86") {
if (current_cpu == "x86") {
config_path_name = "linux-elf"
} else if (target_cpu == "x64") {
} else if (current_cpu == "x64") {
config_path_name = "linux-x86_64"
} else if (target_cpu == "arm") {
} else if (current_cpu == "arm") {
config_path_name = "linux-armv4"
} else if (target_cpu == "arm64") {
} else if (current_cpu == "arm64") {
config_path_name = "linux-aarch64"
}
} else if (is_apple) {
if (target_cpu == "x86") {
if (current_cpu == "x86") {
config_path_name = "darwin-i386-cc"
} else if (target_cpu == "x64") {
} else if (current_cpu == "x64") {
config_path_name = "darwin64-x86_64-cc"
} else if (target_cpu == "arm64") {
} else if (current_cpu == "arm64") {
config_path_name = "darwin64-arm64-cc"
}
}
Expand All @@ -132,7 +132,7 @@ template("openssl_gn_build") {
# TODO(zcbenz): Check gas_version and nasm_version.
asm_name = "asm_avx2"
}
if (is_win && target_cpu == "arm64") {
if (is_win && current_cpu == "arm64") {
asm_name = "no-asm"
}
config_path = "config/archs/" + config_path_name + "/" + asm_name
Expand Down
6 changes: 4 additions & 2 deletions node.gni
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ declare_args() {
node_use_node_code_cache = host_os == target_os && host_cpu == target_cpu

# Use snapshot to speed up startup.
# TODO(zcbenz): node_mksnapshot is not ready for cross-os compilation.
node_use_node_snapshot = host_os == target_os
# TODO(zcbenz): There are few broken things for now:
# 1. cross-os compilation is not supported.
# 2. node_mksnapshot crashes when cross-compiling for x64 from arm64.
node_use_node_snapshot = (host_os == target_os) && !(host_cpu == "arm64" && target_cpu == "x64")
}

assert(!node_enable_inspector || node_use_openssl,
Expand Down
4 changes: 2 additions & 2 deletions unofficial.gni
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ template("node_gn_build") {
"-Wno-unused-function",
]

if (target_cpu == "x86") {
if (current_cpu == "x86") {
node_arch = "ia32"
} else {
node_arch = target_cpu
node_arch = current_cpu
}
if (target_os == "win") {
node_platform = "win32"
Expand Down

0 comments on commit 384fd17

Please sign in to comment.