Skip to content

Commit f8e0247

Browse files
committed
configure: supply target_arch define to gyp.js
Since version 1.1.1 gyp.js uses environment files. Set --target_arch command-line option with value of node-gyp --arch option in order to generate proper ninja environment file. Removed findMSVS() function and `vcvars.bat` invocation before building with `ninja` because `gyp.js` supports target environments and the actual `target_arch` is set before on `configure` stage.
1 parent c9303d7 commit f8e0247

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

lib/build.js

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var fs = require('graceful-fs')
1515
, processRelease = require('./process-release')
1616
, win = process.platform == 'win32'
1717

18-
exports.usage = 'Invokes `' + (process.env.npm_config_gypjs? 'ninja' : (win ? 'msbuild' : 'make')) + '` and builds the module'
18+
exports.usage = 'Invokes `' + (process.env.npm_config_gypjs ? 'ninja' : (win ? 'msbuild' : 'make')) + '` and builds the module'
1919

2020
function build (gyp, argv, callback) {
2121
var platformMake = 'make'
@@ -35,7 +35,6 @@ function build (gyp, argv, callback) {
3535
, config
3636
, arch
3737
, nodeDir
38-
, vcDir
3938

4039
if (gyp.opts.gypjs) {
4140
command = gyp.opts.ninja || process.env.NINJA || 'ninja'
@@ -74,41 +73,14 @@ function build (gyp, argv, callback) {
7473
log.verbose('architecture', arch)
7574
log.verbose('node dev dir', nodeDir)
7675

77-
if (win) {
78-
gyp.opts.gypjs? findMSVS() : findSolutionFile()
76+
if (!gyp.opts.gypjs && win) {
77+
findSolutionFile()
7978
} else {
8079
doWhich()
8180
}
8281
})
8382
}
8483

85-
/**
86-
* On Windows, find Visual C++ toolset
87-
*/
88-
89-
function findMSVS () {
90-
var msvs_version = gyp.opts.msvs_version || 'auto'
91-
var vs_versions = (msvs_version === 'auto'? [14, 12, 10] : [msvs_version])
92-
vs_versions.find(function(version) {
93-
var vscomntools = process.env['VS' + version + '0COMNTOOLS']
94-
if (vscomntools) {
95-
// remove quotes to work with path.join()
96-
if (vscomntools.substr(0, 1) === '"' && vscomntools.substr(-1, 1) === '"') {
97-
vscomntools = vscomntools.substr(1, vscomntools.length - 2)
98-
}
99-
vcDir = path.join(vscomntools, '..', '..', 'VC')
100-
if (vcDir) {
101-
log.verbose('found Visual C++ in ', vcDir)
102-
return true
103-
}
104-
}
105-
})
106-
if (!vcDir) {
107-
callback(new Error('Visual C++ not found, please setup a C++ compiler toolset'))
108-
}
109-
doWhich()
110-
}
111-
11284
/**
11385
* On Windows, find the first build/*.sln file.
11486
*/
@@ -280,11 +252,6 @@ function build (gyp, argv, callback) {
280252
argv.push('-j' + j)
281253
}
282254
}
283-
// invoke vcvarsall.bat before build
284-
if (win && vcDir) {
285-
argv.unshift(arch === 'ia32'? 'x86' : arch, '&', command)
286-
command = path.join(vcDir, 'vcvarsall.bat')
287-
}
288255
}
289256

290257
var proc = gyp.spawn(command, argv)

lib/configure.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ var fs = require('graceful-fs')
2323
, findNodeDirectory = require('./find-node-directory')
2424
, gypjs = require('gyp.js')
2525

26-
exports.usage = 'Generates ' + (process.env.npm_config_gypjs? 'ninja build files' : (win ? 'MSVC project files' : 'a Makefile')) + ' for the current module'
26+
exports.usage = 'Generates ' + (process.env.npm_config_gypjs ? 'ninja build files' : (win ? 'MSVC project files' : 'a Makefile')) + ' for the current module'
2727

2828
function configure (gyp, argv, callback) {
2929

3030
var python = gyp.opts.python || process.env.PYTHON || 'python2'
3131
, buildDir = path.resolve('build')
3232
, configNames = [ 'config.gypi', 'common.gypi' ]
3333
, configs = []
34+
, arch
3435
, nodeDir
3536
, release = processRelease(argv, gyp, process.version, process.release)
3637

@@ -130,7 +131,7 @@ function configure (gyp, argv, callback) {
130131
}
131132

132133
// set the target_arch variable
133-
variables.target_arch = gyp.opts.arch || process.arch || 'ia32'
134+
variables.target_arch = arch = gyp.opts.arch || process.arch || 'ia32'
134135

135136
// set the node development directory
136137
variables.nodedir = nodeDir
@@ -193,7 +194,7 @@ function configure (gyp, argv, callback) {
193194
if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
194195
if (win) {
195196
log.verbose('gyp', 'gyp format was not specified; forcing "msvs"')
196-
// force the 'make' target for non-Windows
197+
// force the 'msvs' target for non-Windows
197198
argv.push('-f', 'msvs')
198199
} else {
199200
log.verbose('gyp', 'gyp format was not specified; forcing "make"')
@@ -297,6 +298,7 @@ function configure (gyp, argv, callback) {
297298
var cp = gyp.spawn(python, argv)
298299
cp.on('exit', onCpExit)
299300
} else {
301+
argv.push('-Dtarget_arch=' + arch)
300302
onCpExit(gypjs.main(argv))
301303
}
302304
})

0 commit comments

Comments
 (0)