Skip to content

Instantly share code, notes, and snippets.

@iceiix
Created January 20, 2019 02:08
Show Gist options
  • Save iceiix/94083aa0025471f37557466e836a4e8d to your computer and use it in GitHub Desktop.
Save iceiix/94083aa0025471f37557466e836a4e8d to your computer and use it in GitHub Desktop.
wasm32-unknown-emscripten bug report draft missing function: emscripten_set_mousemove_callback

IMPORTANT: OUTDATED, SEE rust-windowing/winit#760

Rust stable version 1.32.0 or 1.31.0, wasm32-unknown-emscripten target, compiles with the latest Emscripten SDK, version 1.38.22, but exhibits a binary incompatibility at runtime, crashing with "missing function: emscripten_set_mousemove_callback".

This prevents using popular Rust crates with Emscripten, such as winit: rust-windowing/winit#760 and glutin.

Minimal test case (mousemove.rs):

use std::os::raw::{c_int, c_char, c_void};

pub type EmMouseCallbackFunc = Option<unsafe extern "C" fn(
    eventType: c_int,
    mouseEvent: *const c_void,
    userData: *mut c_void) -> c_int>;

extern "C" {
    pub fn emscripten_set_mousemove_callback(
        target: *const c_char, user_data: *mut c_void,
        use_capture: c_int, callback: EmMouseCallbackFunc)
        -> c_int;
}

fn main() {
    unsafe {
        emscripten_set_mousemove_callback(0 as *const c_char, std::mem::transmute(&0), 0, None);
    }
}

To build:

rustup default 1.32.0
rustup target install wasm32-unknown-emscripten
emsdk install sdk-1.38.16-64bit
emsdk activate sdk-1.38.16-64bit
source ~/emsdk/emsdk_env.sh
rustc mousemove.rs --target wasm32-unknown-emscripten
cat <<'EOF' > mousemove.html
<!DOCTYPE html>
<head><title></title></head><body><canvas id="my_id"></canvas>
<script>window.Module = { canvas: document.getElementById('my_id') };</script>
<script src="mousemove.js"></script></body></html>
EOF
python -m SimpleHTTPServer 8123
open http://localhost:8123/mousemove.html

I expected to see this happen: no error

Instead, this happened:

mousemove.js:5352 missing function: emscripten_set_mousemove_callback
_emscripten_set_mousemove_callback @ mousemove.js:5352
wasm-function[73] @ wasm-0009ad62-73:38
wasm-function[68] @ wasm-0009ad62-68:13
wasm-function[228] @ wasm-0009ad62-228:18
wasm-function[226] @ wasm-0009ad62-226:20
wasm-function[384] @ wasm-0009ad62-384:8
Module.dynCall_vi @ mousemove.js:5824
invoke_vi @ mousemove.js:5535
wasm-function[229] @ wasm-0009ad62-229:9
wasm-function[225] @ wasm-0009ad62-225:122
wasm-function[67] @ wasm-0009ad62-67:25
wasm-function[72] @ wasm-0009ad62-72:8
Module._main @ mousemove.js:5748
callMain @ mousemove.js:5962
doRun @ mousemove.js:6020
run @ mousemove.js:6034
runCaller @ mousemove.js:5939
removeRunDependency @ mousemove.js:1462
receiveInstance @ mousemove.js:1624
receiveInstantiatedSource @ mousemove.js:1649
Promise.then (async)
instantiateArrayBuffer @ mousemove.js:1654
(anonymous) @ mousemove.js:1670
Promise.then (async)
doNativeWasm @ mousemove.js:1665
Module.asm @ mousemove.js:1751
(anonymous) @ mousemove.js:5581
mousemove.js:6120 -1
mousemove.js:6121 -1
abort @ mousemove.js:6121
_emscripten_set_mousemove_callback @ mousemove.js:5352
wasm-function[73] @ wasm-0009ad62-73:38
wasm-function[68] @ wasm-0009ad62-68:13
wasm-function[228] @ wasm-0009ad62-228:18
wasm-function[226] @ wasm-0009ad62-226:20
wasm-function[384] @ wasm-0009ad62-384:8
Module.dynCall_vi @ mousemove.js:5824
invoke_vi @ mousemove.js:5535
wasm-function[229] @ wasm-0009ad62-229:9
wasm-function[225] @ wasm-0009ad62-225:122
wasm-function[67] @ wasm-0009ad62-67:25
wasm-function[72] @ wasm-0009ad62-72:8
Module._main @ mousemove.js:5748
callMain @ mousemove.js:5962
doRun @ mousemove.js:6020
run @ mousemove.js:6034
runCaller @ mousemove.js:5939
removeRunDependency @ mousemove.js:1462
receiveInstance @ mousemove.js:1624
receiveInstantiatedSource @ mousemove.js:1649
Promise.then (async)
instantiateArrayBuffer @ mousemove.js:1654
(anonymous) @ mousemove.js:1670
Promise.then (async)
doNativeWasm @ mousemove.js:1665
Module.asm @ mousemove.js:1751
(anonymous) @ mousemove.js:5581
mousemove.js:5982 exception thrown: abort(-1) at Error
    at jsStackTrace (http://localhost:8123/mousemove.js:1066:13)
    at stackTrace (http://localhost:8123/mousemove.js:1083:12)
    at abort (http://localhost:8123/mousemove.js:6131:44)
    at _emscripten_set_mousemove_callback (http://localhost:8123/mousemove.js:5352:63)
    at wasm-function[73]:75
    at wasm-function[68]:24
    at wasm-function[228]:32
    at wasm-function[226]:39
    at wasm-function[384]:13
    at Object.Module.dynCall_vi (http://localhost:8123/mousemove.js:5824:38)

See explanation for this error at: emscripten-core/emscripten#7525 (comment)

which suggests this is an emscripten version mismatch.

What version of emsdk is used to build the Rust standard library[1]? Could it be updated to 1.38.22?

[1] ~/.rustup/toolchains/1.32.0-x86_64-apple-darwin/lib/rustlib/wasm32-unknown-emscripten/lib/

Meta

~ $ rustc --version --verbose
rustc 1.32.0 (9fda7c223 2019-01-16)
binary: rustc
commit-hash: 9fda7c2237db910e41d6a712e9a2139b352e558b
commit-date: 2019-01-16
host: x86_64-apple-darwin
release: 1.32.0
LLVM version: 8.0

This occurs with both 1.32.0 and 1.31.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment