Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/create-config-gypi.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo, python }) {
if (config.variables.clang === 1) {
config.variables.clang = 0
}
// disable LTO for addon builds. node release builds may enable (thin) LTO,
// which leaks clang/lld-only flags like -flto=thin and /opt:lldltojobs into
// addons built with the default MSVC toolchain, which rejects those flags
variables.enable_lto = 'false'
variables.enable_thin_lto = 'false'
}

// loop through the rest of the opts and add the unknown ones as variables.
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/win-lto/include/node/config.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Test configuration simulating a Node.js Windows release built with Thin LTO
{
'variables': {
'enable_lto': 'true',
'enable_thin_lto': 'true',
'lto_jobs': '2'
}
}
19 changes: 19 additions & 0 deletions test/test-create-config-gypi.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ describe('create-config-gypi', function () {
assert.strictEqual(config.variables.build_with_electron, undefined)
})

it('config.gypi disables LTO for addon builds on Windows', async function () {
const nodeDir = path.join(__dirname, 'fixtures', 'win-lto')

const prog = gyp()
prog.parseArgv(['_', '_', `--nodedir=${nodeDir}`])

const originalPlatform = process.platform
Object.defineProperty(process, 'platform', { value: 'win32' })
try {
const config = await getCurrentConfigGypi({ gyp: prog, nodeDir, vsInfo: {} })
// thin LTO leaks clang/lld-only flags into the MSVC addon build, so it
// must be disabled regardless of how node itself was built
assert.strictEqual(config.variables.enable_lto, 'false')
assert.strictEqual(config.variables.enable_thin_lto, 'false')
} finally {
Object.defineProperty(process, 'platform', { value: originalPlatform })
}
})

it('config.gypi parsing', function () {
const str = "# Some comments\n{'variables': {'multiline': 'A'\n'B'}}"
const config = parseConfigGypi(str)
Expand Down
Loading