-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·74 lines (63 loc) · 1.93 KB
/
build.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/env node
// Copyright (c) 2022, Eugene Gershnik
// SPDX-License-Identifier: BSD-3-Clause
const fs = require('fs');
const path = require('path');
const { spawn } = require('node:child_process');
dotEnvFile = path.join(__dirname, '.env')
try {
const data = fs.readFileSync(dotEnvFile, 'utf8');
data.split(/\r?\n/).forEach(line => {
line = line.trim()
if (line.length == 0 || line.match(/.*#/))
return;
m = line.match(/\s*([^= \t]+)\s*=\s*([^= \t]+)/)
if (m) {
process.env[m[1]] = m[2]
} else {
console.warn(`Ignoring invalid line in .env: ${line}`)
}
});
} catch (err) {
; //ignore
}
if (process.env['EMSCRIPTEN_CMAKE_TOOLCHAIN'] === undefined) {
console.error('EMSCRIPTEN_CMAKE_TOOLCHAIN variable not defined. \
Either set it up in shell or put it in a .env file')
process.exit(1)
}
const toolchainFile = process.env['EMSCRIPTEN_CMAKE_TOOLCHAIN'];
const codeDir = path.join(__dirname, 'code');
const buildDir = path.join(__dirname, 'cmake-build');
function run(cmd, args) {
return new Promise(function (resolve, reject) {
const process = spawn(cmd, args, { stdio: 'inherit' });
process.on('close', function (code) {
resolve(code);
});
process.on('error', function (err) {
reject(err);
});
});
}
run('cmake', [
'-S', codeDir,
'-B', buildDir,
`-DCMAKE_TOOLCHAIN_FILE=${toolchainFile}`,
'-DCMAKE_BUILD_TYPE=Release',
`-DSPR_JAVASCRIPT_PACKAGE_DIR=${__dirname}`
]).then(exitCode => {
if (exitCode != 0)
process.exit(1)
return run('cmake', ['--build', buildDir, '--target', 'spreader.js' ]);
}).then(exitCode => {
if (exitCode != 0)
process.exit(1)
return run('cmake', ['--install', buildDir]);
}).then(exitCode => {
if (exitCode != 0)
process.exit(1)
}).catch(ex => {
console.log(ex)
process.exit(1)
});