forked from parcel-bundler/parcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-native.js
53 lines (45 loc) · 1.54 KB
/
build-native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable no-console */
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const {spawn, execSync} = require('child_process');
let release = process.argv.includes('--release');
build();
async function build() {
if (process.platform === 'darwin') {
setupMacBuild();
}
let packages = glob.sync('packages/*/*');
for (let pkg of packages) {
try {
let pkgJSON = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json')));
if (!pkgJSON.napi) continue;
} catch (err) {
continue;
}
console.log(`Building ${pkg}...`);
await new Promise((resolve, reject) => {
let args = [release ? 'build-release' : 'build'];
if (process.env.RUST_TARGET) {
args.push('--target', process.env.RUST_TARGET);
}
let yarn = spawn('yarn', args, {
stdio: 'inherit',
cwd: pkg,
shell: true,
});
yarn.on('close', code => (code === 0 ? resolve() : reject()));
}).catch(() => process.exit(1));
}
}
// This forces Clang/LLVM to be used as a C compiler instead of GCC.
// This is necessary for cross-compilation for Apple Silicon in GitHub Actions.
function setupMacBuild() {
process.env.CC = execSync('xcrun -f clang', {encoding: 'utf8'}).trim();
process.env.CXX = execSync('xcrun -f clang++', {encoding: 'utf8'}).trim();
let sysRoot = execSync('xcrun --sdk macosx --show-sdk-path', {
encoding: 'utf8',
}).trim();
process.env.CFLAGS = `-isysroot ${sysRoot} -isystem ${sysRoot}`;
process.env.MACOSX_DEPLOYMENT_TARGET = '10.9';
}