Skip to content

Document CommonJS/AMD supportΒ #6442

@mbasso

Description

@mbasso

Hi,
first of all thank you for working on emscripten πŸ˜„
I've just updated my emscripten version from 1.37.22 to 1.37.36 and all works fine without changes, except 1 command. In my project I use emcc to compile some C++ code in this way:

βœ… .cpp => .a
βœ… .cpp => .bc
βœ… .bc => .asm.js
❌ .bc => .js (and .wasm, using BYNARIEN)

Unfortunately the last step gives me an error. I've tried to change some flags and I noticed that it might be caused by -O3, using -O2 no error is thrown. I'll copy here my command and the error:

emcc
  -O3
  --bind
  --memory-init-file 1
  --llvm-lto 3
  --llvm-opts 3
  --js-opts 1
  --closure 1
  --pre-js prefix.js
  --post-js postfix.js
  -s ALLOW_MEMORY_GROWTH=1
  -s "EXPORTED_RUNTIME_METHODS=['UTF8ToString']"
  -s AGGRESSIVE_VARIABLE_ELIMINATION=1
  -s ABORTING_MALLOC=1
  -s NO_EXIT_RUNTIME=1
  -s NO_FILESYSTEM=1
  -s DISABLE_EXCEPTION_CATCHING=2
  -s BINARYEN=1
  -s "BINARYEN_TRAP_MODE='allow'"
  input.bc
  -o output.js

and here is the error (with EMCC_DEBUG=1):

DEBUG:root:emcc step "asm2wasm" took 0.51 seconds
DEBUG:root:running cleanup on shell code: noPrintMetadata AJSDCE minifyWhitespace
DEBUG:root:running meta-DCE

Stack: Error
    at assertTrue (eval at globalEval (/path/to/emsdk/emscripten/1.37.36/tools/js-optimizer.js:114:8), <anonymous>:59:26)
    at Object.emitDCEGraph (/path/to/emsdk/emscripten/1.37.36/tools/js-optimizer.js:8144:3)
    at /path/to/emsdk/emscripten/1.37.36/tools/js-optimizer.js:8368:14
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/path/to/emsdk/emscripten/1.37.36/tools/js-optimizer.js:8367:21)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

undefined:60
    throw msg;
    ^
Assertion failed: undefined
Traceback (most recent call last):
  File "/path/to/emsdk/emscripten/1.37.36/emcc", line 10, in <module>
    python_selector.run(__file__, profile=True)
  File "/path/to/emsdk/emscripten/1.37.36/tools/python_selector.py", line 43, in run
    sys.exit(run_by_import(filename, main) if on_allowed_version() else run_by_subprocess(filename))
  File "/path/to/emsdk/emscripten/1.37.36/tools/python_selector.py", line 13, in run_by_import
    return getattr(importlib.import_module(os.path.basename(filename)), main)()
  File "/path/to/emsdk/emscripten/1.37.36/emcc.py", line 1885, in run
    wasm_text_target, misc_temp_files, optimizer)
  File "/path/to/emsdk/emscripten/1.37.36/emcc.py", line 2423, in do_binaryen
    emit_symbol_map=emit_symbol_map)
  File "/path/to/emsdk/emscripten/1.37.36/tools/shared.py", line 2224, in minify_wasm_js
    js_file = Building.metadce(js_file, wasm_file, minify_whitespace=minify_whitespace, debug_info=debug_info)
  File "/path/to/emsdk/emscripten/1.37.36/tools/shared.py", line 2244, in metadce
    txt = Building.js_optimizer_no_asmjs(js_file, ['emitDCEGraph', 'noEmitAst'], return_output=True)
  File "/path/to/emsdk/emscripten/1.37.36/tools/shared.py", line 2096, in js_optimizer_no_asmjs
    return run_process(NODE_JS + [js_optimizer.JS_OPTIMIZER, filename] + passes, stdout=PIPE).stdout
  File "/path/to/emsdk/emscripten/1.37.36/tools/shared.py", line 131, in run_process
    return run_base(cmd, universal_newlines=universal_newlines, check=check, *args, **kw)
  File "/path/to/emsdk/emscripten/1.37.36/tools/shared.py", line 127, in run_base
    result.check_returncode()
  File "/path/to/emsdk/emscripten/1.37.36/tools/shared.py", line 114, in check_returncode
    raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
tools.shared.Py2CalledProcessError: Command '['/path/to/emsdk/node/8.9.1_64bit/bin/node', '/path/to/emsdk/emscripten/1.37.36/tools/js-optimizer.js', '/tmp/tmpIF1UzW/asm-dom.bc.o.js.pp.js.mem.js.jsopted.js.jsopted.js.jsopted.js.jso.js', 'emitDCEGraph', 'noEmitAst']' returned non-zero exit status 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions