Skip to content

Commit fbc244a

Browse files
committed
fix(smol): use GYP_MSVS_OVERRIDE_PATH to bypass registry detection
Gyp's SelectVisualStudioVersion queries Windows registry even when version is specified. Setting GYP_MSVS_OVERRIDE_PATH bypasses registry detection and directly uses the VS path from vswhere. Changes: - Workflow: Export GYP_MSVS_VERSION=2022 and GYP_MSVS_OVERRIDE_PATH - build.mjs: Remove -G flag, rely on env vars, add gyp vars to debug log https://github.com/nodejs/node/blob/main/tools/gyp/pylib/gyp/MSVSVersion.py
1 parent 135facb commit fbc244a

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

.github/workflows/build-smol.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,25 @@ jobs:
660660
Write-Host ""
661661
Write-Host "Visual Studio environment configured ($exportCount variables exported)"
662662
663+
# ───────────────────────────────────────────────────────────────────
664+
# STEP 7.5: Export gyp-specific environment variables
665+
# ───────────────────────────────────────────────────────────────────
666+
# gyp (used by configure.py) needs these to bypass registry detection.
667+
# GYP_MSVS_VERSION: Tells gyp which VS version to use.
668+
# GYP_MSVS_OVERRIDE_PATH: Bypasses registry check, uses provided path.
669+
#
670+
Write-Host ""
671+
Write-Host "Exporting gyp environment variables:"
672+
673+
# GYP_MSVS_VERSION
674+
$gypVersion = "2022"
675+
Add-Content -Path $env:GITHUB_ENV -Value "GYP_MSVS_VERSION=$gypVersion"
676+
Write-Host " GYP_MSVS_VERSION = $gypVersion"
677+
678+
# GYP_MSVS_OVERRIDE_PATH
679+
Add-Content -Path $env:GITHUB_ENV -Value "GYP_MSVS_OVERRIDE_PATH=$vsPath"
680+
Write-Host " GYP_MSVS_OVERRIDE_PATH = $vsPath"
681+
663682
# ───────────────────────────────────────────────────────────────────
664683
# STEP 8: Verify critical VS environment variables were set
665684
# ───────────────────────────────────────────────────────────────────

packages/node-smol-builder/scripts/build.mjs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,27 +1424,32 @@ async function main() {
14241424
configureFlags.unshift('--dest-cpu=x64')
14251425
}
14261426

1427-
// On Windows, tell gyp to use VS 2022 via generator flag (bypasses auto-detection).
1428-
// https://github.com/nodejs/node/blob/main/BUILDING.md#windows
1429-
// https://github.com/nodejs/node/blob/main/tools/gyp/pylib/gyp/MSVSVersion.py
1430-
if (WIN32) {
1431-
configureFlags.push('-G', 'msvs_version=2022')
1432-
}
1433-
14341427
// Windows uses configure.py directly, Unix uses ./configure wrapper script.
14351428
// Use whichBinSync to resolve full path to python.exe since we use shell: false.
1429+
// Note: VS version is set via GYP_MSVS_VERSION and GYP_MSVS_OVERRIDE_PATH env vars
1430+
// (configured in workflow) which bypasses gyp's registry detection.
1431+
// https://github.com/nodejs/node/blob/main/BUILDING.md#windows
1432+
// https://github.com/nodejs/node/blob/main/tools/gyp/pylib/gyp/MSVSVersion.py
14361433
const configureCommand = WIN32 ? whichBinSync('python') : './configure'
14371434
const configureArgs = WIN32 ? ['configure.py', ...configureFlags] : configureFlags
14381435

14391436
// DEBUG: Verify environment is being passed to subprocess.
14401437
if (WIN32) {
14411438
logger.log('')
14421439
logger.log('DEBUG: Checking environment before exec():')
1443-
const criticalVars = ['VCINSTALLDIR', 'WindowsSDKVersion', 'INCLUDE', 'LIB']
1440+
const criticalVars = [
1441+
'GYP_MSVS_VERSION',
1442+
'GYP_MSVS_OVERRIDE_PATH',
1443+
'VCINSTALLDIR',
1444+
'WindowsSDKVersion',
1445+
'INCLUDE',
1446+
'LIB',
1447+
]
14441448
for (const varName of criticalVars) {
14451449
const value = process.env[varName]
14461450
if (value) {
1447-
logger.log(` ${colors.green('✓')} ${varName} = ${value.substring(0, 60)}...`)
1451+
const preview = value.substring(0, 60) + (value.length > 60 ? '...' : '')
1452+
logger.log(` ${colors.green('✓')} ${varName} = ${preview}`)
14481453
} else {
14491454
logger.log(` ${colors.red('✗')} ${varName} is NOT SET`)
14501455
}

0 commit comments

Comments
 (0)