Skip to content

Commit 4439be1

Browse files
committed
Print error when emcc.py still block wasm2js with UBSan
1 parent e3eb782 commit 4439be1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bin/compile.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ process.env.RPYTHON_TARGET_FILE = process.argv[2];
8484
process.env.PYPY_USESSION_DIR = platform === 'win32' ? cygpath(tempdir) : tempdir;
8585
process.env.USER = 'current';
8686
child_process.execSync([python, rpython, '--gc=none', '--no-translation-jit', '-s'].concat(process.argv.slice(2)).join(' '), {stdio: 'inherit', env: process.env});
87-
if (process.argv[2] && process.argv[2].indexOf('.py') !== -1) {
87+
async function handle() {
8888
var file = process.argv[2].split('.py')[0];
8989
var directory = path.join(tempdir, 'usession-unknown-0', 'testing_1');
9090
var makefile = path.join(directory, 'Makefile');
@@ -95,7 +95,7 @@ if (process.argv[2] && process.argv[2].indexOf('.py') !== -1) {
9595
if (platform === 'win32') make = make.replace('RPYDIR = ', 'RPYDIR = "' + rpydir + '"#')
9696
make = make.replace(/-lutil/g, '');
9797
make = make.replace(/--export-all-symbols/g, '--export-dynamic');
98-
make = make.replace('CC = ', 'CC = ' + emcc + (!use_wasm ? ' -s WASM=0 ' : ' ') + '-fsanitize=undefined -s ALLOW_MEMORY_GROWTH=1 -s \'EXPORTED_FUNCTIONS=["_main", "_malloc", "_onresolve", "_onfunctioncall"]\' -s \'EXPORTED_RUNTIME_METHODS=["ccall", "wasmMemory"]\'' + (debug_flag ? ' -g3' : (source_flag ? ' -g4' : '')) + ' #');
98+
make = make.replace('CC = ', 'CC = ' + emcc + (!use_wasm ? ' -s WASM=0 ' : ' ') + '-fdiagnostics-color=always -fsanitize=undefined -s ALLOW_MEMORY_GROWTH=1 -s \'EXPORTED_FUNCTIONS=["_main", "_malloc", "_onresolve", "_onfunctioncall"]\' -s \'EXPORTED_RUNTIME_METHODS=["ccall", "wasmMemory"]\'' + (debug_flag ? ' -g3' : (source_flag ? ' -g4' : '')) + ' #');
9999
make = make.replace('TARGET = ', 'TARGET = ' + file + '.js #');
100100
make = make.replace('DEFAULT_TARGET = ', 'DEFAULT_TARGET = ' + file + '.js #');
101101
fs.writeFileSync(makefile, make);
@@ -105,7 +105,12 @@ if (process.argv[2] && process.argv[2].indexOf('.py') !== -1) {
105105
if (platform === 'darwin') {
106106
process.env.C_INCLUDE_PATH = path.join(__dirname, '../dmidecode');
107107
}
108-
child_process.execSync(['make', '-j', cores].join(' '), {env: process.env, stdio: 'inherit', cwd: directory});
108+
var error = '';
109+
var code = await new Promise((resolve) => child_process.spawn('make', ['-j', cores], {env: process.env, stdio: ['inherit', 'inherit', 'pipe'], cwd: directory}).on('close', resolve).stderr.on('data', (data) => process.stderr.write(error += data.toString())));
110+
if (code !== 0) {
111+
if (error.includes('wasm2js is not compatible with USE_OFFSET_CONVERTER')) throw new Error('\x1b[31mYour emcc wasm2js support is not patched yet, add --wasm to rpython command or comment out "wasm2js is not compatible with USE_OFFSET_CONVERTER" in emcc.py\x1b[0m').toString();
112+
process.exit();
113+
}
109114
for (var filename of fs.readdirSync(directory)) {
110115
if (filename.startsWith(file + '.')) {
111116
if (use_wasm || filename !== (file + '.js')) fs.copyFileSync(path.join(directory, filename), path.join(process.cwd(), filename));
@@ -138,3 +143,4 @@ if (process.argv[2] && process.argv[2].indexOf('.py') !== -1) {
138143
console.warn(error);
139144
}
140145
}
146+
if (process.argv[2] && process.argv[2].indexOf('.py') !== -1) handle().catch(console.error);

0 commit comments

Comments
 (0)