Emscripten: Cannot compile sql.js

Created on 1 Mar 2017  路  3Comments  路  Source: emscripten-core/emscripten

Hi,

I cloned krypken's repo kripken/sql.js and updated emscripten and binaryen through emsdk (incoming branch of emscripten, commit 47c2c82; and master branch of binaryen, commit 9607b1b).

Here is the command I use (inspired from the one found in the Makefile).

emcc --memory-init-file 0 \
     -s INLINING_LIMIT=50 \
     -s RESERVED_FUNCTION_POINTERS=64 \
     -s EXPORTED_FUNCTIONS=@exported_functions \
     c/extension-functions.bc \
     c/sqlite3.bc \
     --post-js js/api.js \
     -o build/index.html

In total I generate 4 different kinds of builds:

  • asm.js
  • asm.js optimized (-O3)
  • WebAssembly (-s WASM=1)
  • WebAssembly optimized (-O3 -s WASM=1)

I tested each of them with the following browsers, on a Macbook Pro with macOS Sierra:

  • Chrome stable (56)
  • Chrome canary (58)
  • Firefox stable (51)
  • Firefox nightly (54)

Here are my results:

| Browser | asm.js | asm.js -O3 | wasm | wasm -O3 |
| -------- | ------- | ---------- | ------ | ----------- |
| Chrome stable | Assertion failed1 | Works | WebAssembly.instantiate is not a function2 | WebAssembly.instantiate is not a function3 |
| Chrome canary | Assertion failed | Works | Assertion failed4 | Cannot read property apply of undefined5 |
| Firefox stable | Assertion failed6 | Works | WebAssembly.instantiate is not a function | unreachable code after the return statement7 |
| Firefox nightly | Assertion failed | Works | Assertion failed | unreachable code after the return statement |

If you want to run the same commands or see the builts, everything is on my repo: the commands are in package.json and the compiled files are in build.

Any idea about what's wrong? Thank you very much.


Below are the console logs from the browsers.

    1.
build-asm.html:1237 Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)
build-asm.html:1249 Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)
printErr @ build-asm.html:1249
abort @ build-asm.js:275250
assert @ build-asm.js:400
asm.stackAlloc @ build-asm.js:274817
(anonymous) @ build-asm.js:275304
build-asm.js:275267 Uncaught abort("Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)") at Error
    at jsStackTrace (http://localhost:3000/build-asm.js:1100:13)
    at stackTrace (http://localhost:3000/build-asm.js:1117:12)
    at abort (http://localhost:3000/build-asm.js:275261:44)
    at assert (http://localhost:3000/build-asm.js:400:5)
    at Object.asm.stackAlloc (http://localhost:3000/build-asm.js:274817:1)
    at http://localhost:3000/build-asm.js:275304:19
abort @ build-asm.js:275267
assert @ build-asm.js:400
asm.stackAlloc @ build-asm.js:274817
(anonymous) @ build-asm.js:275304
    2.
build-wasm.html:1249 trying binaryen method: native-wasm
printErr @ build-wasm.html:1249
Module.asm @ build-wasm.js:1900
(anonymous) @ build-wasm.js:6176
build-wasm.html:1249 asynchronously preparing wasm
printErr @ build-wasm.html:1249
doNativeWasm @ build-wasm.js:1741
Module.asm @ build-wasm.js:1903
(anonymous) @ build-wasm.js:6176
build-wasm.js:1743 Uncaught TypeError: WebAssembly.instantiate is not a function
    at doNativeWasm (build-wasm.js:1743)
    at Object.Module.asm (build-wasm.js:1903)
    at build-wasm.js:6176
doNativeWasm @ build-wasm.js:1743
Module.asm @ build-wasm.js:1903
(anonymous) @ build-wasm.js:6176
  1. Same as 2. Only the line numbers are different.

  2. 4.
Canary wasm
Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)
build-wasm.html:1249 Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)
build-wasm.js:6792 Uncaught abort("Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)") at Error
    at jsStackTrace (http://localhost:3000/build-wasm.js:1100:13)
    at stackTrace (http://localhost:3000/build-wasm.js:1117:12)
    at abort (http://localhost:3000/build-wasm.js:6786:44)
    at assert (http://localhost:3000/build-wasm.js:400:5)
    at asm.stackAlloc (http://localhost:3000/build-wasm.js:6317:1)
    at Object.Module.stackAlloc (http://localhost:3000/build-wasm.js:6497:89)
    at http://localhost:3000/build-wasm.js:6829:19
build-wasm.html:1249 [post-exception status] All downloads complete.
build-wasm.html:1249 [post-exception status] Running...
    5.
build-wasm-O3.js:6067 Uncaught TypeError: Cannot read property 'apply' of undefined
    at Object.Module.stackAlloc (build-wasm-O3.js:6067)
    at build-wasm-O3.js:6386
build-wasm-O3.html:1249 [post-exception status] All downloads complete.
build-wasm-O3.html:1249 [post-exception status] Running...
    6.
Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)  build-asm.html:1249:13
Stack
abort:275267
assert:400
asm.stackAlloc:274817
(global):275304
    7.
unreachable code after return statement[Learn More]
Stack:
integrateWasmJS/Module.asm:1823
(global):6038

If you need more logs, please let me know. Thank you.

Most helpful comment

sql.js hasn't been updated in a while, I guess. The issues are:

  • The "runtime isn't ready" assert means we need to refactor so we wait until it is ready. Startup can be async, and definitely is with wasm. See http://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions which mentions that error message.
  • "instantiate is not a function" probably means your browser is not new enough. Need latest firefox nightly or chrome canary, as instantiate is a pretty new addition to wasm.
  • "unreachable code" - that's just a warning I think.

All 3 comments

sql.js hasn't been updated in a while, I guess. The issues are:

  • The "runtime isn't ready" assert means we need to refactor so we wait until it is ready. Startup can be async, and definitely is with wasm. See http://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions which mentions that error message.
  • "instantiate is not a function" probably means your browser is not new enough. Need latest firefox nightly or chrome canary, as instantiate is a pretty new addition to wasm.
  • "unreachable code" - that's just a warning I think.

Thanks Alon. We were able to compile everything with your recommendation. PR incoming on sql.js.

This PR https://github.com/kripken/sql.js/pull/189 should fix all the issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nerddan picture nerddan  路  4Comments

answer1103 picture answer1103  路  4Comments

napalm272 picture napalm272  路  4Comments

juj picture juj  路  3Comments

yahsaves picture yahsaves  路  4Comments