quic: update the guard to check openssl version · nodejs/node@b2b0bf8
@@ -1308,6 +1308,65 @@ def get_gas_version(cc):
13081308warn(f'Could not recognize `gas`: {gas_ret}')
13091309return '0.0'
131013101311+def get_openssl_version():
1312+"""Parse OpenSSL version from opensslv.h header file.
1313+1314+ Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1315+ 0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1316+ """
1317+1318+try:
1319+# Use the C compiler to extract preprocessor macros from opensslv.h
1320+args = ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1321+if not options.shared_openssl:
1322+args = ['-I', 'deps/openssl/openssl/include'] + args
1323+elif options.shared_openssl_includes:
1324+args = ['-I', options.shared_openssl_includes] + args
1325+1326+proc = subprocess.Popen(
1327+shlex.split(CC) + args,
1328+stdin=subprocess.PIPE,
1329+stdout=subprocess.PIPE,
1330+stderr=subprocess.PIPE
1331+ )
1332+with proc:
1333+proc.stdin.write(b'\n')
1334+out = to_utf8(proc.communicate()[0])
1335+1336+if proc.returncode != 0:
1337+warn('Failed to extract OpenSSL version from opensslv.h header')
1338+return 0
1339+1340+# Parse the macro definitions
1341+macros = {}
1342+for line in out.split('\n'):
1343+if line.startswith('#define OPENSSL_VERSION_'):
1344+parts = line.split()
1345+if len(parts) >= 3:
1346+macro_name = parts[1]
1347+macro_value = parts[2]
1348+macros[macro_name] = macro_value
1349+1350+# Extract version components
1351+major = int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
1352+minor = int(macros.get('OPENSSL_VERSION_MINOR', '0'))
1353+patch = int(macros.get('OPENSSL_VERSION_PATCH', '0'))
1354+1355+# Check if it's a pre-release (has non-empty PRE_RELEASE string)
1356+pre_release = macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
1357+status = 0x0 if pre_release else 0xf
1358+# Construct version number: 0xMNN00PPSL
1359+version_number = ((major << 28) |
1360+ (minor << 20) |
1361+ (patch << 4) |
1362+status)
1363+1364+return version_number
1365+1366+except (OSError, ValueError, subprocess.SubprocessError) as e:
1367+warn(f'Failed to determine OpenSSL version from header: {e}')
1368+return 0
1369+13111370# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13121371# the version check more by accident than anything else but a more rigorous
13131372# check involves checking the build number against an allowlist. I'm not
@@ -1948,6 +2007,8 @@ def without_ssl_error(option):
19482007if options.quic:
19492008o['defines'] += ['NODE_OPENSSL_HAS_QUIC']
195020092010+o['variables']['openssl_version'] = get_openssl_version()
2011+19512012configure_library('openssl', o)
1952201319532014def configure_sqlite(o):