-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.cpp.js
More file actions
100 lines (88 loc) · 2.36 KB
/
build.cpp.js
File metadata and controls
100 lines (88 loc) · 2.36 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
/* eslint-env node */
/* eslint-disable no-console */
const { spawn } = require('child_process')
const { join } = require('path')
const glob = require('glob')
const DEBUG = process.env.NODE_ENV === 'development'
const INCLUDE_DIR = join('/usr', 'local', 'include')
const LIBRARY_DIR = join('/usr', 'local', 'lib')
const bitFile = 'dcgp.bc'
const optimalisation = DEBUG ? '-O0' : '-O3'
const bitArgs = [
`-I${INCLUDE_DIR}`,
'-I/usr/include/eigen3',
'-std=c++11',
'-g4',
optimalisation,
'-o',
bitFile,
DEBUG && '--source-map-base',
DEBUG && 'http://localhost:8080/',
].filter(item => !!item)
const wasmArgs = [
bitFile,
join(LIBRARY_DIR, 'libmpfr.a'),
join(LIBRARY_DIR, 'libgmpxx.a'),
join(LIBRARY_DIR, 'libgmp.a'),
join(LIBRARY_DIR, 'libboost_chrono.so'),
join(LIBRARY_DIR, 'libboost_iostreams.so'),
join(LIBRARY_DIR, 'libboost_prg_exec_monitor.so'),
join(LIBRARY_DIR, 'libboost_regex.so'),
join(LIBRARY_DIR, 'libboost_serialization.so'),
join(LIBRARY_DIR, 'libboost_system.so'),
join(LIBRARY_DIR, 'libboost_timer.so'),
join(LIBRARY_DIR, 'libboost_wserialization.so'),
optimalisation,
'-g4',
'-s',
'EXPORT_ES6=1',
'-s',
'MODULARIZE=1',
'-o',
'dcgp.js',
DEBUG && '--source-map-base',
DEBUG && 'http://localhost:8080/',
].filter(item => !!item)
const attachOutput = (commandClass, command) =>
new Promise((resolve, reject) => {
commandClass.stdout.on('data', data => {
console.log(data.toString('utf8'))
})
commandClass.stderr.on('data', data => {
console.error(data.toString('utf8'))
reject()
})
commandClass.on('close', code => {
if (code !== 0) {
throw new Error(`${command} command failed`)
}
console.log(`${command} command succeeded`)
resolve()
})
})
const build = async files => {
{
const args = files.concat(bitArgs)
const emccProcess = spawn('emcc', args)
await attachOutput(emccProcess, 'bitcode')
}
{
const wasm = spawn('emcc', wasmArgs)
await attachOutput(wasm, 'wasm')
}
}
const resolveCppFiles = () =>
new Promise((resolve, reject) => {
glob('src/cpp/**/*.cpp', null, (error, files) => {
if (error) {
reject(error)
return
}
resolve(files)
})
})
const main = async () => {
const files = await resolveCppFiles()
await build(files)
}
main().catch(error => console.warn(error))