| #!/usr/bin/env node |
| |
| |
| |
| |
| |
|
|
| |
|
|
| import assert from 'node:assert'; |
| import {parseArgs} from 'node:util'; |
| import { |
| applySettings, |
| loadDefaultSettings, |
| printErr, |
| readFile, |
| timer, |
| } from '../src/utility.mjs'; |
|
|
| timer.start('startup') |
|
|
| loadDefaultSettings(); |
|
|
| const options = { |
| help: {type: 'boolean', short: 'h'}, |
| 'symbols-only': {type: 'boolean'}, |
| output: {type: 'string', short: 'o'}, |
| }; |
| const {values, positionals} = parseArgs({options, allowPositionals: true}); |
|
|
| if (values.help) { |
| console.log(`\ |
| Main entry point for JS compiler |
| |
| If no -o file is specified then the generated code is written to stdout. |
| |
| Usage: compiler.mjs <settings.json> [-o out.js] [--symbols-only]`); |
| process.exit(0); |
| } |
|
|
| timer.start('read settings') |
|
|
| |
| let settingsFile = positionals[0]; |
| assert(settingsFile, 'settings file not specified'); |
| if (settingsFile == '-') { |
| |
| settingsFile = 0; |
| } |
| const userSettings = JSON.parse(readFile(settingsFile)); |
| applySettings(userSettings); |
|
|
| timer.stop('read settings') |
|
|
| export const symbolsOnly = values['symbols-only']; |
|
|
| |
| |
| process.env['EMCC_BUILD_DIR'] = process.cwd(); |
|
|
| |
| |
| if (!ALL_INCOMING_MODULE_JS_API.size) { |
| ALL_INCOMING_MODULE_JS_API = INCOMING_MODULE_JS_API; |
| } |
| if (symbolsOnly) { |
| INCLUDE_FULL_LIBRARY = 1; |
| } |
|
|
| |
| assert( |
| !SIDE_MODULE || (ASYNCIFY && symbolsOnly), |
| 'JS compiler should only run on side modules if asyncify is used.', |
| ); |
|
|
| |
|
|
| timer.start('dynamic imports') |
|
|
| |
| |
| |
| await import('../src/modules.mjs'); |
| await import('../src/parseTools.mjs'); |
| if (!STRICT) { |
| await import('../src/parseTools_legacy.mjs'); |
| } |
| const jsifier = await import('../src/jsifier.mjs'); |
|
|
| timer.stop('dynamic imports') |
|
|
| timer.stop('startup') |
|
|
| |
| |
| |
|
|
| try { |
| timer.start('runJSify') |
| await jsifier.runJSify(values.output, symbolsOnly); |
| timer.stop('runJSify') |
| } catch (err) { |
| if (err.toString().includes('Aborting compilation due to previous errors')) { |
| |
| printErr(err); |
| } else { |
| |
| printErr('Internal compiler error JS compiler'); |
| printErr('Please create a bug report at https://github.com/emscripten-core/emscripten/issues/'); |
| printErr( |
| 'with a log of the build and the input files used to run. Exception message: "' + |
| (err.stack || err), |
| ); |
| } |
|
|
| |
| |
| |
| |
| process.stdout.once('drain', () => process.exit(1)); |
| |
| |
| console.log(' '); |
| |
| |
| |
| setTimeout(() => process.exit(1), 500); |
| } |
|
|