Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use post_config.gypi to use shared libraries #1264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 35 additions & 6 deletions lib/configure.js
Expand Up @@ -28,6 +28,7 @@ function configure (gyp, argv, callback) {
, buildDir = path.resolve('build')
, configNames = [ 'config.gypi', 'common.gypi' ]
, configs = []
, post_configs = []
, nodeDir
, release = processRelease(argv, gyp, process.version, process.release)

Expand Down Expand Up @@ -97,27 +98,42 @@ function configure (gyp, argv, callback) {

var configFilename = 'config.gypi'
var configPath = path.resolve(buildDir, configFilename)
var postConfigFilename = 'post_config.gypi'
var postConfigPath = path.resolve(buildDir, postConfigFilename)

log.verbose('build/' + configFilename, 'creating config file')

var config = process.config || {}
, defaults = config.target_defaults
, variables = config.variables
, fallback_target_defaults = {}
, post_variables = ['cflags', 'defines', 'include_dirs', 'libraries']

// default "config.variables"
if (!variables) variables = config.variables = {}

// default "config.defaults"
if (!defaults) defaults = config.target_defaults = {}

// don't inherit the "defaults" from node's `process.config` object.
if ( variables.node_shared_cares ||
variables.node_shared_http_parser ||
variables.node_shared_libuv ||
variables.node_shared_openssl ||
variables.node_shared_zlib ) {
Object.keys(defaults).forEach(function (entry) {
if (post_variables.indexOf(entry) > 0) {
fallback_target_defaults[entry] = defaults[entry]
}
})
}
// if node engine does not have to rely on shared libraries in the system
// do not inherit the "defaults" from node's `process.config` object.
// doing so could cause problems in cases where the `node` executable was
// compiled on a different machine (with different lib/include paths) than
// the machine where the addon is being built to
defaults.cflags = []
defaults.defines = []
defaults.include_dirs = []
defaults.libraries = []
post_variables.forEach(function (post_var) {
defaults[post_var] = []
})

// set the default_configuration prop
if ('debug' in gyp.opts) {
Expand Down Expand Up @@ -182,7 +198,17 @@ function configure (gyp, argv, callback) {
, json = JSON.stringify(config, boolsToString, 2)
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
configs.push(configPath)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), function() {

var config = {
"target_defaults": fallback_target_defaults
}
, prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
, json = JSON.stringify(config, boolsToString, 2)
log.verbose('build/' + postConfigFilename, 'writing out config file: %s', postConfigPath)
post_configs.push(postConfigPath)
fs.writeFile(postConfigPath, [prefix, json, ''].join('\n'), findConfigs)
})
}

function findConfigs (err) {
Expand Down Expand Up @@ -280,6 +306,9 @@ function configure (gyp, argv, callback) {

argv.push('-I', addon_gypi)
argv.push('-I', common_gypi)
post_configs.forEach(function (config) {
argv.push('-I', config)
})
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
Expand Down