Skip to content

Commit

Permalink
chore: fix nan spec runner on macOS (#34447)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 7, 2022
1 parent 30d1571 commit 4ec2de6
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions script/nan-spec-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const args = require('minimist')(process.argv.slice(2), {
});

async function main () {
const nodeDir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
const outDir = utils.getOutDir({ shouldLog: true });
const nodeDir = path.resolve(BASE, 'out', outDir, 'gen', 'node_headers');
const env = Object.assign({}, process.env, {
npm_config_nodedir: nodeDir,
npm_config_msvs_version: '2019',
Expand All @@ -31,6 +32,25 @@ async function main () {
const cxx = path.resolve(clangDir, 'clang++');
const ld = path.resolve(clangDir, 'lld');

const platformFlags = [];
if (process.platform === 'darwin') {
const sdkPath = path.resolve(BASE, 'out', outDir, 'sdk', 'xcode_links');
const sdks = (await fs.promises.readdir(sdkPath)).filter(fileName => fileName.endsWith('.sdk'));
const sdkToUse = sdks[0];
if (!sdkToUse) {
console.error('Could not find an SDK to use for the NAN tests');
process.exit(1);
}

if (sdks.length) {
console.warn(`Multiple SDKs found in the xcode_links directory - using ${sdkToUse}`);
}

platformFlags.push(
`-isysroot ${path.resolve(sdkPath, sdkToUse)}`
);
}

// TODO(ckerr) this is cribbed from read obj/electron/electron_app.ninja.
// Maybe it would be better to have this script literally open up that
// file and pull cflags_cc from it instead of using bespoke code here?
Expand All @@ -41,15 +61,17 @@ async function main () {
`-isystem"${path.resolve(BASE, 'buildtools', 'third_party', 'libc++')}"`,
`-isystem"${path.resolve(BASE, 'buildtools', 'third_party', 'libc++', 'trunk', 'include')}"`,
`-isystem"${path.resolve(BASE, 'buildtools', 'third_party', 'libc++abi', 'trunk', 'include')}"`,
'-fPIC'
'-fPIC',
...platformFlags
].join(' ');

const ldflags = [
'-stdlib=libc++',
'-fuse-ld=lld',
`-L"${path.resolve(BASE, 'out', `${utils.getOutDir({ shouldLog: true })}`, 'obj', 'buildtools', 'third_party', 'libc++abi')}"`,
`-L"${path.resolve(BASE, 'out', `${utils.getOutDir({ shouldLog: true })}`, 'obj', 'buildtools', 'third_party', 'libc++')}"`,
'-lc++abi'
`-L"${path.resolve(BASE, 'out', outDir, 'obj', 'buildtools', 'third_party', 'libc++abi')}"`,
`-L"${path.resolve(BASE, 'out', outDir, 'obj', 'buildtools', 'third_party', 'libc++')}"`,
'-lc++abi',
...platformFlags
].join(' ');

if (process.platform !== 'win32') {
Expand All @@ -66,6 +88,7 @@ async function main () {
cwd: NAN_DIR,
stdio: 'inherit'
});

if (buildStatus !== 0) {
console.error('Failed to build nan test modules');
return process.exit(buildStatus);
Expand Down

0 comments on commit 4ec2de6

Please sign in to comment.