MINGW-packages/mingw-w64-nodejs/0103-node-gyp-support-mingw-toolchain.patch
2025-09-11 23:05:44 +03:00

328 lines
14 KiB
Diff

diff --git a/deps/npm/node_modules/node-gyp/addon.gypi b/deps/npm/node_modules/node-gyp/addon.gypi
index b4ac369a..4f866859 100644
--- a/deps/npm/node_modules/node-gyp/addon.gypi
+++ b/deps/npm/node_modules/node-gyp/addon.gypi
@@ -71,7 +71,7 @@
# that the addon will work regardless of whether the node/iojs binary
# is named node.exe, iojs.exe, or something else.
'conditions': [
- [ 'OS=="win"', {
+ [ 'OS=="msvc"', {
'defines': [ 'HOST_BINARY=\"<(node_host_binary)<(EXECUTABLE_SUFFIX)\"', ],
'sources': [
'<(node_gyp_dir)/src/win_delay_load_hook.cc',
@@ -167,20 +167,21 @@
}
}]
],
+ 'library_dirs': [ '<(node_root_dir)/lib' ],
'libraries': [
- '-lkernel32.lib',
- '-luser32.lib',
- '-lgdi32.lib',
- '-lwinspool.lib',
- '-lcomdlg32.lib',
- '-ladvapi32.lib',
- '-lshell32.lib',
- '-lole32.lib',
- '-loleaut32.lib',
- '-luuid.lib',
- '-lodbc32.lib',
- '-lDelayImp.lib',
- '-l"<(node_lib_file)"'
+ '-lkernel32',
+ '-luser32',
+ '-lgdi32',
+ '-lwinspool',
+ '-lcomdlg32',
+ '-ladvapi32',
+ '-lshell32',
+ '-lole32',
+ '-loleaut32',
+ '-luuid',
+ '-lodbc32',
+ '-ldelayimp',
+ '-lnode'
],
'msvs_disabled_warnings': [
# warning C4251: 'node::ObjectWrap::handle_' : class 'v8::Persistent<T>'
diff --git a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py
index 77800661..3f35afd9 100755
--- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py
+++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py
@@ -533,7 +533,7 @@ def gyp_main(args):
# Nothing in the variable, default based on platform.
elif sys.platform == "darwin":
options.formats = ["xcode"]
- elif sys.platform in ("win32", "cygwin"):
+ elif sys.platform in ("win32", "cygwin") and not "GCC" in sys.version:
options.formats = ["msvs"]
else:
options.formats = ["make"]
diff --git a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py
index e8604790..e199821f 100644
--- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py
+++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py
@@ -103,6 +103,8 @@ def CalculateVariables(default_variables, params):
elif flavor == "zos":
default_variables.setdefault("SHARED_LIB_SUFFIX", ".x")
COMPILABLE_EXTENSIONS.update({".pli": "pli"})
+ elif flavor == "win":
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".dll")
else:
default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
default_variables.setdefault("SHARED_LIB_DIR", "$(builddir)/lib.$(TOOLSET)")
@@ -145,6 +147,26 @@ def CalculateGeneratorInputInfo(params):
SPACE_REPLACEMENT = "?"
+LINK_COMMANDS_WINMINGW = """\
+quiet_cmd_alink = AR($(TOOLSET)) $@
+cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
+
+quiet_cmd_alink_thin = AR($(TOOLSET)) $@
+cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
+
+# Due to circular dependencies between libraries :(, we wrap the
+# special "figure out circular dependencies" flags around the entire
+# input list during linking.
+quiet_cmd_link = LINK($(TOOLSET)) $@
+cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
+
+quiet_cmd_solink = SOLINK($(TOOLSET)) $@
+cmd_solink = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--out-implib,$(builddir)/$(@F).a -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
+
+quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
+cmd_solink_module = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) $(filter-out FORCE_DO_CMD, $^) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
+"""
+
LINK_COMMANDS_LINUX = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
@@ -1585,6 +1607,8 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD
target_ext = ".a"
elif self.flavor == "zos":
target_ext = ".x"
+ elif self.flavor == "win":
+ target_ext = ".dll"
else:
target_ext = ".so"
elif self.type == "none":
@@ -2558,6 +2582,13 @@ def GenerateOutput(target_list, target_dicts, data, params):
elif flavor == "openbsd":
copy_archive_arguments = "-pPRf"
header_params.update({"copy_archive_args": copy_archive_arguments})
+ elif flavor == "win":
+ copy_archive_arguments = "-pPRf"
+ header_params.update(
+ {
+ "link_commands": LINK_COMMANDS_WINMINGW,
+ }
+ )
elif flavor == "aix":
copy_archive_arguments = "-pPRf"
header_params.update(
diff --git a/deps/npm/node_modules/node-gyp/lib/build.js b/deps/npm/node_modules/node-gyp/lib/build.js
index 9c0cca8f..081c57bd 100644
--- a/deps/npm/node_modules/node-gyp/lib/build.js
+++ b/deps/npm/node_modules/node-gyp/lib/build.js
@@ -6,7 +6,7 @@ const path = require('path')
const { glob } = require('tinyglobby')
const log = require('./log')
const which = require('which')
-const win = process.platform === 'win32'
+const win = require('os').type() === 'Windows_NT'
async function build (gyp, argv) {
let platformMake = 'make'
@@ -193,7 +193,7 @@ async function build (gyp, argv) {
}
}
- if (!win) {
+ if (!process.platform === 'win32') {
// Add build-time dependency symlinks (such as Python) to PATH
buildBinsDir = path.resolve('build', 'node_gyp_bins')
process.env.PATH = `${buildBinsDir}:${process.env.PATH}`
diff --git a/deps/npm/node_modules/node-gyp/lib/configure.js b/deps/npm/node_modules/node-gyp/lib/configure.js
index ee672cfb..eb71df4f 100644
--- a/deps/npm/node_modules/node-gyp/lib/configure.js
+++ b/deps/npm/node_modules/node-gyp/lib/configure.js
@@ -5,7 +5,7 @@ const path = require('path')
const log = require('./log')
const os = require('os')
const processRelease = require('./process-release')
-const win = process.platform === 'win32'
+const win = require('os').type() === 'Windows_NT'
const findNodeDirectory = require('./find-node-directory')
const { createConfigGypi } = require('./create-config-gypi')
const { format: msgFormat } = require('util')
@@ -18,7 +18,7 @@ const minorRe = /^#define NODE_MINOR_VERSION (\d+)/m
const patchRe = /^#define NODE_PATCH_VERSION (\d+)/m
async function configure (gyp, argv) {
- const buildDir = path.resolve('build')
+ const buildDir = path.resolve('build').replace(/\\/g, '/')
const configNames = ['config.gypi', 'common.gypi']
const configs = []
let nodeDir
@@ -79,7 +79,7 @@ async function configure (gyp, argv) {
await gyp.commands.install([release.version])
log.verbose('get node dir', 'target node version installed:', release.versionDir)
- nodeDir = path.resolve(gyp.devDir, release.versionDir)
+ nodeDir = path.resolve(path.dirname(path.dirname(process.execPath))).replace(/\\/g, '/')
}
return createBuildDir()
@@ -132,7 +132,7 @@ async function configure (gyp, argv) {
return runGyp()
}
- const fullPath = path.resolve(name)
+ const fullPath = path.resolve(name).replace(/\\/g, '/')
log.verbose(name, 'checking for gypi file: %s', fullPath)
try {
await fs.stat(fullPath)
@@ -163,7 +163,7 @@ async function configure (gyp, argv) {
// include all the ".gypi" files that were found
configs.forEach(function (config) {
- argv.push('-I', config)
+ argv.push('-I', config.replace(/\\/g, '/'))
})
// For AIX and z/OS we need to set up the path to the exports file
@@ -246,9 +246,9 @@ async function configure (gyp, argv) {
}
// this logic ported from the old `gyp_addon` python file
- const gypScript = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py')
- const addonGypi = path.resolve(__dirname, '..', 'addon.gypi')
- let commonGypi = path.resolve(nodeDir, 'include/node/common.gypi')
+ const gypScript = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py').replace(/\\/g, '/')
+ const addonGypi = path.resolve(__dirname, '..', 'addon.gypi').replace(/\\/g, '/')
+ let commonGypi = path.resolve(nodeDir, 'include/node/common.gypi').replace(/\\/g, '/')
try {
await fs.stat(commonGypi)
} catch (err) {
@@ -260,11 +260,11 @@ async function configure (gyp, argv) {
// Windows expects an absolute path
outputDir = buildDir
}
- const nodeGypDir = path.resolve(__dirname, '..')
+ const nodeGypDir = path.resolve(__dirname, '..').replace(/\\/g, '/')
let nodeLibFile = path.join(nodeDir,
- !gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)',
- release.name + '.lib')
+ !gyp.opts.nodedir ? 'lib' : 'lib',
+ 'lib' + release.name + '.dll.a').replace(/\\/g, '/')
argv.push('-I', addonGypi)
argv.push('-I', commonGypi)
@@ -285,7 +285,7 @@ async function configure (gyp, argv) {
nodeLibFile = nodeLibFile.replace(/\\/g, '\\\\')
}
argv.push('-Dnode_lib_file=' + nodeLibFile)
- argv.push('-Dmodule_root_dir=' + process.cwd())
+ argv.push('-Dmodule_root_dir=' + process.cwd().replace(/\\/g, '/'))
argv.push('-Dnode_engine=' +
(gyp.opts.node_engine || process.jsEngine || 'v8'))
argv.push('--depth=.')
@@ -304,7 +304,7 @@ async function configure (gyp, argv) {
argv.unshift(gypScript)
// make sure python uses files that came with this particular node package
- const pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
+ const pypath = [path.join(__dirname, '..', 'gyp', 'pylib').replace(/\\/g, '/')]
if (process.env.PYTHONPATH) {
pypath.push(process.env.PYTHONPATH)
}
diff --git a/deps/npm/node_modules/node-gyp/lib/create-config-gypi.js b/deps/npm/node_modules/node-gyp/lib/create-config-gypi.js
index 01a820e9..7309d04d 100644
--- a/deps/npm/node_modules/node-gyp/lib/create-config-gypi.js
+++ b/deps/npm/node_modules/node-gyp/lib/create-config-gypi.js
@@ -3,6 +3,7 @@
const fs = require('graceful-fs').promises
const log = require('./log')
const path = require('path')
+const win = require('os').type() === 'Windows_NT'
function parseConfigGypi (config) {
// translated from tools/js2c.py of Node.js
@@ -81,7 +82,7 @@ async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo, python }) {
// disable -T "thin" static archives by default
variables.standalone_static_library = gyp.opts.thin ? 0 : 1
- if (process.platform === 'win32') {
+ if (win) {
defaults.msbuild_toolset = vsInfo.toolset
if (vsInfo.sdk) {
defaults.msvs_windows_target_platform_version = vsInfo.sdk
@@ -140,7 +141,7 @@ async function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo, python }) {
const prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
const json = JSON.stringify(config, boolsToString, 2)
- log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
+ log.verbose('build/' + configFilename, 'writing out config file: %s', configPath.replace(/\\/g, '/'))
await fs.writeFile(configPath, [prefix, json, ''].join('\n'))
return configPath
diff --git a/deps/npm/node_modules/node-gyp/lib/find-node-directory.js b/deps/npm/node_modules/node-gyp/lib/find-node-directory.js
index 8838b81d..12b6d64e 100644
--- a/deps/npm/node_modules/node-gyp/lib/find-node-directory.js
+++ b/deps/npm/node_modules/node-gyp/lib/find-node-directory.js
@@ -2,6 +2,7 @@
const path = require('path')
const log = require('./log')
+const win = require('os').type() === 'Windows_NT'
function findNodeDirectory (scriptLocation, processObj) {
// set dirname and process if not passed in
@@ -31,7 +32,7 @@ function findNodeDirectory (scriptLocation, processObj) {
// lib/node_modules/npm/node_modules/node-gyp/lib or
// node_modules/npm/node_modules/node-gyp/lib depending on the
// platform
- if (processObj.platform === 'win32') {
+ if (win) {
nodeRootDir = path.join(npmParentDirectory, '..')
} else {
nodeRootDir = path.join(npmParentDirectory, '../..')
@@ -49,7 +50,7 @@ function findNodeDirectory (scriptLocation, processObj) {
// If we are a recently built node, and the directory structure
// is that of a repository. If we are on Windows then we only need
// to go one level up, everything else, two
- if (processObj.platform === 'win32') {
+ if (win) {
nodeRootDir = path.join(nodeDir, '..')
} else {
nodeRootDir = path.join(nodeDir, '../..')
diff --git a/deps/npm/node_modules/node-gyp/lib/find-python.js b/deps/npm/node_modules/node-gyp/lib/find-python.js
index a71c00c2..2bf245ba 100644
--- a/deps/npm/node_modules/node-gyp/lib/find-python.js
+++ b/deps/npm/node_modules/node-gyp/lib/find-python.js
@@ -3,7 +3,7 @@
const log = require('./log')
const semver = require('semver')
const { execFile } = require('./util')
-const win = process.platform === 'win32'
+const win = require('os').type() === 'Windows_NT'
function getOsUserInfo () {
try {
diff --git a/deps/npm/node_modules/node-gyp/lib/install.js b/deps/npm/node_modules/node-gyp/lib/install.js
index 90be86c8..158778d8 100644
--- a/deps/npm/node_modules/node-gyp/lib/install.js
+++ b/deps/npm/node_modules/node-gyp/lib/install.js
@@ -12,7 +12,7 @@ const semver = require('semver')
const { download } = require('./download')
const processRelease = require('./process-release')
-const win = process.platform === 'win32'
+const win = require('os').type() === 'Windows_NT'
async function install (gyp, argv) {
log.stdout()