-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompilermmxapianapi.js
31 lines (26 loc) · 1.15 KB
/
compilermmxapianapi.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
const execSync = require('child_process').execSync;
const { mkdirSync, existsSync } = require('fs');
const xapianDirArgName = '--xapiandir=';
const xapianDirArg = process.argv.find(arg => arg.indexOf(xapianDirArgName)===0);
if (xapianDirArg) {
process.env.XAPIAN = xapianDirArg.substr(xapianDirArgName.length);
console.log('XAPIAN', process.env.XAPIAN);
}
if(!process.env.XAPIAN) {
console.error("Environment variable XAPIAN must be set to the location of xapian_core");
} else {
try {
console.log('Building Runbox Xapian webassembly library');
if(!existsSync('dist')) {
mkdirSync('dist');
}
execSync(`em++ -Oz -s DISABLE_EXCEPTION_CATCHING=0 -s USE_ZLIB=1 ` +
`-s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS','cwrap','stringToUTF8','UTF8ToString','getValue']" ` +
`-std=c++11 -s DEMANGLE_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 ` +
`-I$XAPIAN/include -I$XAPIAN -I$XAPIAN/common rmmxapianapi.cc $XAPIAN/.libs/libxapian.a ` +
`-o dist/xapianasm.js -lidbfs.js -lnodefs.js`, { stdio: 'inherit' });
console.log('Successful build of xapianasm.wasm and xapianasm.js');
} catch(e) {
console.error('Compile failed');
}
}