build: use CARGO environment variable if set

When enabling support for Temporal, check for the `CARGO` environment
variable to locate the `cargo` binary (defaulting to `cargo` if not
set) and use this to build `deps/crates`.

This will allow using Cargo on systems where the Cargo binary name is
suffixed with the version, e.g. `cargo-1.82` on Ubuntu 24.04.

PR-URL: https://github.com/nodejs/node/pull/62421
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Richard Lau authored and GitHub committed 2026-04-01 07:31:10 +00:00
1 parent f8ee196c15
commit 7b8934d2e4
2 files changed
+13 -4

No files matched your search

+11 -3
View File
@@ -1452,7 +1452,9 @@ def get_cargo_version(cargo):
except OSError:
error('''No acceptable cargo found!
Please make sure you have cargo installed on your system.''')
Please make sure you have cargo installed on your system and/or
consider adjusting the CARGO environment variable if you have installed
it in a non-standard prefix.''')
with proc:
cargo_ret = to_utf8(proc.communicate()[0])
@@ -1540,8 +1542,9 @@ def check_compiler(o):
# Minimum cargo and rustc versions should match values in BUILDING.md.
min_cargo_ver_tuple = (1, 82)
min_rustc_ver_tuple = (1, 82)
cargo_ver = get_cargo_version('cargo')
print_verbose(f'Detected cargo: {cargo_ver}')
cargo = os.environ.get('CARGO', 'cargo')
cargo_ver = get_cargo_version(cargo)
print_verbose(f'Detected cargo (CARGO={cargo}): {cargo_ver}')
cargo_ver_tuple = tuple(map(int, cargo_ver.split('.')))
if cargo_ver_tuple < min_cargo_ver_tuple:
warn(f'cargo {cargo_ver} too old, need cargo {".".join(map(str, min_cargo_ver_tuple))}')
@@ -2751,6 +2754,11 @@ if flavor == 'win' and python.lower().endswith('.exe'):
# will fail to run python scripts.
gyp_args += ['-Dpython=' + python]
if options.v8_enable_temporal_support and not options.shared_temporal_capi:
cargo = os.environ.get('CARGO')
if cargo:
gyp_args += ['-Dcargo=' + cargo]
if options.use_ninja:
gyp_args += ['-f', 'ninja-' + flavor]
elif flavor == 'win' and sys.platform != 'msys':
+2 -1
View File
@@ -1,5 +1,6 @@
{
'variables': {
'cargo%': 'cargo',
'cargo_vendor_dir': './vendor',
},
'conditions': [
@@ -48,7 +49,7 @@
'<(node_crates_libpath)'
],
'action': [
'cargo',
'<(cargo)',
'rustc',
'<@(cargo_build_flags)',
'--frozen',