Skip to content

Commit bef0663

Browse files
richardlauaduh95
authored andcommitted
build: add cargo and rustc checks for Temporal
If opting into building Node.js with statically linked Temporal (`configure --v8-enable-temporal-support`), check for the presence of `cargo` and `rustc` and compare the detected versions against the documented toolchain versions in `BUILDING.md`.
1 parent 363758c commit bef0663

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

configure.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,50 @@ def get_openssl_version(o):
13911391
warn(f'Failed to determine OpenSSL version from header: {e}')
13921392
return 0
13931393

1394+
def get_cargo_version(cargo):
1395+
try:
1396+
proc = subprocess.Popen(shlex.split(cargo) + ['--version'],
1397+
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
1398+
stdout=subprocess.PIPE)
1399+
except OSError:
1400+
error('''No acceptable cargo found!
1401+
1402+
Please make sure you have cargo installed on your system.''')
1403+
1404+
with proc:
1405+
cargo_ret = to_utf8(proc.communicate()[0])
1406+
1407+
match = re.match(r"cargo ([0-9]+\.[0-9]+\.[0-9]+)", cargo_ret)
1408+
1409+
if match:
1410+
return match.group(1)
1411+
1412+
warn(f'Could not recognize `cargo`: {cargo_ret}')
1413+
return '0.0'
1414+
1415+
def get_rustc_version(rustc):
1416+
try:
1417+
proc = subprocess.Popen(shlex.split(rustc) + ['--version'],
1418+
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
1419+
stdout=subprocess.PIPE)
1420+
except OSError:
1421+
error('''No acceptable rustc compiler found!
1422+
1423+
Please make sure you have a rust compiler installed on your system and/or
1424+
consider adjusting the RUSTC environment variable if you have installed
1425+
it in a non-standard prefix.''')
1426+
1427+
with proc:
1428+
rustc_ret = to_utf8(proc.communicate()[0])
1429+
1430+
match = re.match(r"rustc ([0-9]+\.[0-9]+\.[0-9]+)", rustc_ret)
1431+
1432+
if match:
1433+
return match.group(1)
1434+
1435+
warn(f'Could not recognize `rustc`: {rustc_ret}')
1436+
return '0.0'
1437+
13941438
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13951439
# the version check more by accident than anything else but a more rigorous
13961440
# check involves checking the build number against an allowlist. I'm not
@@ -1438,6 +1482,24 @@ def check_compiler(o):
14381482

14391483
o['variables']['llvm_version'] = get_llvm_version(CC) if is_clang else '0.0'
14401484

1485+
# cargo and rustc are needed for Temporal.
1486+
if options.v8_enable_temporal_support and not options.shared_temporal_capi:
1487+
# Minimum cargo and rustc versions should match values in BUILDING.md.
1488+
min_cargo_ver_tuple = (1, 82)
1489+
min_rustc_ver_tuple = (1, 82)
1490+
cargo_ver = get_cargo_version('cargo')
1491+
print_verbose(f'Detected cargo: {cargo_ver}')
1492+
cargo_ver_tuple = tuple(map(int, cargo_ver.split('.')))
1493+
if cargo_ver_tuple < min_cargo_ver_tuple:
1494+
warn(f'cargo {cargo_ver} too old, need cargo {".".join(map(str, min_cargo_ver_tuple))}')
1495+
# cargo supports RUSTC environment variable to override "rustc".
1496+
rustc = os.environ.get('RUSTC', 'rustc')
1497+
rustc_ver = get_rustc_version(rustc)
1498+
print_verbose(f'Detected rustc (RUSTC={rustc}): {rustc_ver}')
1499+
rust_ver_tuple = tuple(map(int, rustc_ver.split('.')))
1500+
if rust_ver_tuple < min_rustc_ver_tuple:
1501+
warn(f'rustc {rustc_ver} too old, need rustc {".".join(map(str, min_rustc_ver_tuple))}')
1502+
14411503
# Need xcode_version or gas_version when openssl asm files are compiled.
14421504
if options.without_ssl or options.openssl_no_asm or options.shared_openssl:
14431505
return

0 commit comments

Comments
 (0)