Skip to content

Commit cb1c2f5

Browse files
committed
build system
1 parent 5cc673b commit cb1c2f5

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

build.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { stat } = require('fs/promises');
2+
const path = require('path');
3+
const {promises: fs, constants } = require('fs');
4+
const { promisify } = require('util');
5+
const execFile = promisify(require('child_process').execFile);
6+
7+
const { spawn, paths, exists } = require('./util');
8+
9+
(async () => {
10+
if (await exists(paths.exeFinal)) {
11+
return;
12+
}
13+
14+
if (!(await exists(paths.bin))) {
15+
await fs.mkdir(paths.bin, { recursive: true });
16+
}
17+
18+
await spawn('cargo', [
19+
'build',
20+
`--manifest-path=${path.join(paths.submodule, 'Cargo.toml')}`,
21+
`--target-dir=${paths.build}`,
22+
'--release'
23+
]);
24+
await fs.copyFile(
25+
paths.exeOut,
26+
paths.exeFinal
27+
);
28+
})();

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
"name": "node-dump-syms",
33
"version": "0.0.1",
44
"main": "index.js",
5-
"license": "MIT"}
5+
"license": "MIT",
6+
"scripts": {
7+
"install": "node ./build.js"
8+
}
9+
}

util.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const path = require('path');
2+
const { promises: fs } = require('fs');
3+
const { spawn: spawnSync } = require('child_process');
4+
5+
const spawn = (...args) => new Promise((resolve, reject) => {
6+
let stdout = Buffer.alloc(0);
7+
let stderr = Buffer.alloc(0);
8+
const child = spawnSync(...args);
9+
const concat = (o) => (b) => o = Buffer.concat([o, b]);
10+
child.stdout.on('data', concat(stdout));
11+
child.stderr.on('data', concat(stderr));
12+
child.on('close', function (code) {
13+
if (code !== 0) {
14+
reject(stderr ? new Error(stderr.toString()) : new Error(`Command ${command} failed ${code}`));
15+
} else {
16+
resolve(stdout);
17+
}
18+
});
19+
child.on('error', function (error) {
20+
reject(error);
21+
})
22+
});
23+
24+
module.exports.spawn = spawn;
25+
26+
const exists = async (filePath) => fs.access(filePath).then(() => true).catch(e => e.code !== 'ENOENT');
27+
28+
module.exports.exists = exists;
29+
30+
const exe = process.platform === 'win32' ? '.exe' : '';
31+
const paths = {
32+
submodule: path.join(__dirname, 'deps', 'dump_syms'),
33+
bin: path.join(__dirname, 'bin', `${process.platform}-${process.arch}`),
34+
build: path.join(__dirname, 'build'),
35+
exeOut: path.join(__dirname, 'build', 'release', `dump_syms${exe}`),
36+
exeFinal: path.join(__dirname, 'bin', `${process.platform}-${process.arch}`, `dump_syms${exe}`),
37+
};
38+
39+
module.exports.paths = paths;

0 commit comments

Comments
 (0)