-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathbuild.js
More file actions
146 lines (128 loc) · 3.74 KB
/
build.js
File metadata and controls
146 lines (128 loc) · 3.74 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import childProcess from 'node:child_process';
import { getEffectiveArch } from './lib/arch.js';
const exe = process.platform === 'win32' ? '.exe' : '';
const binDir = path.join(import.meta.dirname, 'bin', `${process.platform}-${getEffectiveArch()}`);
const minidumpStackwalkDest = path.join(binDir, 'minidump_stackwalk') + exe;
const minidumpDumpDest = path.join(binDir, 'minidump_dump') + exe;
const dumpSymsDest = path.join(binDir, 'dump_syms') + exe;
// do not build if executables already exist
if (
fs.existsSync(minidumpStackwalkDest) &&
fs.existsSync(minidumpDumpDest) &&
fs.existsSync(dumpSymsDest)
) {
process.exit(0);
}
function spawnSync(...args) {
const result = childProcess.spawnSync(...args);
if (result.error) throw result.error;
if (result.status !== 0) {
process.exit(result.status);
}
}
const buildDir = path.join(import.meta.dirname, 'build', getEffectiveArch());
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir, { recursive: true });
}
let overrideArch = '';
let crossCompileHost = '';
if (getEffectiveArch() !== process.arch && process.platform === 'darwin') {
overrideArch = getEffectiveArch() === 'arm64' ? 'arm64' : 'x86_64';
crossCompileHost = 'x86_64-apple-darwin20.6.0';
}
spawnSync(
path.join(import.meta.dirname, 'deps', 'breakpad', 'configure'),
crossCompileHost ? [`--host=${crossCompileHost}`] : [],
{
cwd: buildDir,
env: {
...process.env,
CPPFLAGS: [
`-I${path.relative(buildDir, path.join(import.meta.dirname, 'deps'))}`,
...(overrideArch ? [`-arch ${overrideArch}`] : []),
].join(' '),
LDFLAGS: overrideArch ? `-arch ${overrideArch}` : undefined,
},
stdio: 'inherit',
},
);
const targets = ['src/processor/minidump_stackwalk', 'src/processor/minidump_dump'];
if (process.platform === 'linux') {
targets.push('src/tools/linux/dump_syms/dump_syms');
}
spawnSync('make', ['-C', buildDir, '-j', os.cpus().length, ...targets], {
stdio: 'inherit',
});
if (process.platform === 'darwin') {
spawnSync(
'xcodebuild',
[
'-project',
path.join(
import.meta.dirname,
'deps',
'breakpad',
'src',
'tools',
'mac',
'dump_syms',
'dump_syms.xcodeproj',
),
'build',
],
{
stdio: 'inherit',
},
);
}
// copy to bin folder
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
const minidumpStackwalk = path.resolve(buildDir, 'src', 'processor', 'minidump_stackwalk') + exe;
fs.copyFileSync(minidumpStackwalk, minidumpStackwalkDest);
const minidumpDump = path.resolve(buildDir, 'src', 'processor', 'minidump_dump') + exe;
fs.copyFileSync(minidumpDump, minidumpDumpDest);
const dumpSyms = (() => {
if (process.platform === 'darwin') {
return path.resolve(
import.meta.dirname,
'deps',
'breakpad',
'src',
'tools',
'mac',
'dump_syms',
'build',
'Release',
'dump_syms',
);
} else if (process.platform === 'linux') {
return path.resolve(buildDir, 'src', 'tools', 'linux', 'dump_syms', 'dump_syms');
}
})();
fs.copyFileSync(dumpSyms, dumpSymsDest);
fs.readdirSync(binDir).forEach((file) => {
const absFile = path.join(binDir, file);
stripBin(absFile);
maybeSignBin(absFile);
});
function stripBin(file) {
return childProcess.execFileSync(process.env.STRIP || 'strip', [
file,
process.platform === 'darwin' ? '-Sx' : '--strip-all',
]);
}
function maybeSignBin(file) {
if (process.platform !== 'darwin') return;
return childProcess.execFileSync('codesign', [
'--sign',
'-',
'--force',
'--preserve-metadata=entitlements,requirements,flags,runtime',
file,
]);
}