From e4e8b609760b1ac82aa695de6d25f4abf1c1f6f7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Apr 2024 08:37:50 +0100 Subject: [PATCH] Fix building on Windows --- scripts/bootstrap.js | 18 ++++++++++-------- scripts/build.js | 4 ++-- scripts/common.js | 6 ------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/bootstrap.js b/scripts/bootstrap.js index 5fa3bbb..dc61c26 100755 --- a/scripts/bootstrap.js +++ b/scripts/bootstrap.js @@ -2,24 +2,26 @@ const path = require('path') -const {targetCpu, cmake, mkdir, spawnSync} = require('./common') +const {targetCpu, mkdir, spawnSync} = require('./common') + +const cmake = path.resolve('node_modules', '@yogalayout', 'cmake-bin', 'bin', 'cmake') mkdir('out') if (process.platform == 'win32') { - process.exit(spawnSync(cmake, - ['-S', '.', '-B', 'out', - '-G', 'Visual Studio 19 2022', + process.exit(spawnSync(process.execPath, + [cmake, '-S', '.', '-B', 'out', + '-G', 'Visual Studio 17 2022', '-A', targetCpu == 'x64' ? 'x64' : 'Win32']).status) } else { mkdir('out/Release') - let code = spawnSync(cmake, - ['-D', `CMAKE_BUILD_TYPE=Release`, '../..'], + let code = spawnSync(process.execPath, + [cmake, '-D', `CMAKE_BUILD_TYPE=Release`, '../..'], {cwd: 'out/Release'}).status if (code != 0) process.exit(code) mkdir('out/Debug') - process.exit(spawnSync(cmake, - ['-D', `CMAKE_BUILD_TYPE=Debug`, '../..'], + process.exit(spawnSync(process.execPath, + [cmake, '-D', `CMAKE_BUILD_TYPE=Debug`, '../..'], {cwd: 'out/Debug'}).status) } diff --git a/scripts/build.js b/scripts/build.js index 2d0beed..bafd98f 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -10,8 +10,8 @@ const config = process.argv[2] ? process.argv[2] : 'Debug' if (process.platform == 'win32') { const vsPaths = [ - 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin', - 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin', + 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin', + 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin', process.env.PATH ] const env = Object.assign(process.env, {PATH: vsPaths.join(path.delimiter)}) diff --git a/scripts/common.js b/scripts/common.js index ec577ce..4a8a074 100644 --- a/scripts/common.js +++ b/scripts/common.js @@ -16,11 +16,6 @@ const targetCpu = { arm64: 'arm64', }[narch] -// Find the path of cmake. -let cmake = path.resolve('node_modules', '@yogalayout', 'cmake-bin', 'bin', 'cmake') -if (process.platform == 'win') - cmake += '.exe' - // Make dir and ignore error. function mkdir(dir) { if (fs.existsSync(dir)) return @@ -52,7 +47,6 @@ const spawnSyncWrapper = (exec, args, options = {}) => { // Export public APIs. module.exports = { targetCpu, - cmake, mkdir, execSync: execSyncWrapper, spawnSync: spawnSyncWrapper,