From b2fbdb93d2be912d040c6e88a7d34ba81a8da7aa Mon Sep 17 00:00:00 2001 From: Hu Jialun Date: Mon, 23 Sep 2024 16:59:28 +0800 Subject: [PATCH] Fix build failure in newer node-gyp versions nodejs/node-gyp#1164 interprets additional node-gyp build parameters as target names, which breaks the current way CL configs are passed to msbuild in install.js. Move the detection logic into configuration phase and pass CL configs as gyp variables. Fixes #321, fixes #377 --- binding.gyp | 6 +++++ package.json | 2 +- scripts/configure.js | 8 +++++++ scripts/install.js | 57 -------------------------------------------- 4 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 scripts/install.js diff --git a/binding.gyp b/binding.gyp index 1ca15925..b117055f 100644 --- a/binding.gyp +++ b/binding.gyp @@ -39,6 +39,12 @@ "libraries": [ "<(lldb_lib_dir)/<(lldb_lib)", ], + "msbuild_settings": { + "ClCompile": { + "CLToolPath": "<(cl_tool_path)", + "CLToolExe": "<(cl_tool_exe)", + }, + }, }], [ "coverage == 'true'", { "cflags": [ "--coverage" ], diff --git a/package.json b/package.json index ab0dd64e..224cff16 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "scripts": { "preinstall": "node scripts/configure.js", - "install": "node scripts/install.js", + "install": "node-gyp rebuild", "postinstall": "node scripts/cleanup.js", "test-plugin": "tape test/plugin/*-test.js", "test-addon": "tape test/addon/*-test.js", diff --git a/scripts/configure.js b/scripts/configure.js index 8b05709a..81908aa8 100644 --- a/scripts/configure.js +++ b/scripts/configure.js @@ -78,6 +78,14 @@ function configureInstallation(osName, buildDir) { installation = require('./windows').getLldbInstallation(); config.variables['lldb_lib_dir%'] = installation.libDir; config.variables['lldb_lib%'] = installation.libName; + const clangExe = 'clang-cl.exe'; + const clangDir = lldb.findWindowsExeDir(clangExe); + if (!clangDir) { + console.log(`Could not find ${clangExe}`); + process.exit(1); + } + config.variables['cl_tool_path%'] = clangDir; + config.variables['cl_tool_exe%'] = clangExe; } else { console.log(`Unsupported OS: ${osName}`); process.exit(1); diff --git a/scripts/install.js b/scripts/install.js deleted file mode 100644 index 508ffac9..00000000 --- a/scripts/install.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -const child_process = require('child_process'); -const os = require('os'); - -const lldb = require('./lldb'); - -main(); - -function main() { - const osName = os.type(); - if (osName === 'Windows_NT') { - return mainWindows(); - } - - runFile('node-gyp', ['rebuild']); -} - -function mainWindows() { - const clangExe = 'clang-cl.exe'; - const clangDir = lldb.findWindowsExeDir(clangExe); - - if (!clangDir) { - console.log(`Could not find ${clangExe}`); - process.exit(1); - } - console.log(`Using ${clangExe} found at ${clangDir}`); - - runShell('node-gyp clean'); - runShell('node-gyp configure'); - runShell(`node-gyp build /p:CLToolExe="${clangExe}" /p:CLToolPath="${clangDir}"`); -} - -/** - * execFileSync wrapper, exits on error. - * @param {string} file Executable to run - * @param {string[]} args List of arguments - */ -function runFile(file, args) { - try { - child_process.execFileSync(file, args, { stdio: 'inherit' }); - } catch (err) { - process.exit(err.status); - } -} - -/** - * execSync wrapper, exits on error. - * @param {string} command Command to run - */ -function runShell(command) { - try { - child_process.execSync(command, { stdio: 'inherit' }); - } catch (err) { - process.exit(err.status); - } -}