build, win: use target_arch to link with node.lib

Using `target_arch` in addon.gypi to link against Node.js library. This
variable was written into build/config.gypi on the `configure` stage.

Do not copy node.lib into node_root_dir/Release or node_root_dir/Debug
on Windows, link it from node_root_dir/target_arch directory.

PR-URL: https://github.com/nodejs/node-gyp/pull/964
Reviewed-By: João Reis <reis@janeasystems.com>
This commit is contained in:
Pavel Medvedev 2016-06-19 02:12:17 +03:00 committed by João Reis
parent c307b302f7
commit 0913b2dd99
3 changed files with 3 additions and 33 deletions

View file

@ -109,7 +109,7 @@
'-luuid.lib', '-luuid.lib',
'-lodbc32.lib', '-lodbc32.lib',
'-lDelayImp.lib', '-lDelayImp.lib',
'-l"<(node_root_dir)/$(ConfigurationName)/<(node_lib_file)"' '-l"<(node_root_dir)/<(target_arch)/<(node_lib_file)"'
], ],
'msvs_disabled_warnings': [ 'msvs_disabled_warnings': [
# warning C4251: 'node::ObjectWrap::handle_' : class 'v8::Persistent<T>' # warning C4251: 'node::ObjectWrap::handle_' : class 'v8::Persistent<T>'

View file

@ -11,7 +11,6 @@ var fs = require('graceful-fs')
, glob = require('glob') , glob = require('glob')
, log = require('npmlog') , log = require('npmlog')
, which = require('which') , which = require('which')
, mkdirp = require('mkdirp')
, exec = require('child_process').exec , exec = require('child_process').exec
, processRelease = require('./process-release') , processRelease = require('./process-release')
, win = process.platform === 'win32' , win = process.platform === 'win32'
@ -36,7 +35,6 @@ function build (gyp, argv, callback) {
, config , config
, arch , arch
, nodeDir , nodeDir
, copyDevLib
loadConfigGypi() loadConfigGypi()
@ -60,7 +58,6 @@ function build (gyp, argv, callback) {
buildType = config.target_defaults.default_configuration buildType = config.target_defaults.default_configuration
arch = config.variables.target_arch arch = config.variables.target_arch
nodeDir = config.variables.nodedir nodeDir = config.variables.nodedir
copyDevLib = config.variables.copy_dev_lib == 'true'
if ('debug' in gyp.opts) { if ('debug' in gyp.opts) {
buildType = gyp.opts.debug ? 'Debug' : 'Release' buildType = gyp.opts.debug ? 'Debug' : 'Release'
@ -115,7 +112,7 @@ function build (gyp, argv, callback) {
return return
} }
log.verbose('`which` succeeded for `' + command + '`', execPath) log.verbose('`which` succeeded for `' + command + '`', execPath)
copyNodeLib() doBuild()
}) })
} }
@ -180,36 +177,12 @@ function build (gyp, argv, callback) {
return return
} }
command = msbuildPath command = msbuildPath
copyNodeLib() doBuild()
}) })
})() })()
}) })
} }
/**
* Copies the node.lib file for the current target architecture into the
* current proper dev dir location.
*/
function copyNodeLib () {
if (!win || !copyDevLib) return doBuild()
var buildDir = path.resolve(nodeDir, buildType)
, archNodeLibPath = path.resolve(nodeDir, arch, release.name + '.lib')
, buildNodeLibPath = path.resolve(buildDir, release.name + '.lib')
mkdirp(buildDir, function (err, isNew) {
if (err) return callback(err)
log.verbose('"' + buildType + '" dir needed to be created?', isNew)
var rs = fs.createReadStream(archNodeLibPath)
, ws = fs.createWriteStream(buildNodeLibPath)
log.verbose('copying "' + release.name + '.lib" for ' + arch, buildNodeLibPath)
rs.pipe(ws)
rs.on('error', callback)
ws.on('error', callback)
rs.on('end', doBuild)
})
}
/** /**
* Actually spawn the process and compile the module. * Actually spawn the process and compile the module.

View file

@ -144,9 +144,6 @@ function configure (gyp, argv, callback) {
// set the node development directory // set the node development directory
variables.nodedir = nodeDir variables.nodedir = nodeDir
// don't copy dev libraries with nodedir option
variables.copy_dev_lib = !gyp.opts.nodedir
// disable -T "thin" static archives by default // disable -T "thin" static archives by default
variables.standalone_static_library = gyp.opts.thin ? 0 : 1 variables.standalone_static_library = gyp.opts.thin ? 0 : 1