WASM plugin on Unity

Hello all,

We are trying to use rust to make a cross-platform library. It works great on all platforms except we are having some trouble running the wasm code in unity webgl.
To compile this in the unity project we have to use the .a static library file. We use wasm-pack with the following cargo.toml:

[lib]
crate-type = ["cdylib", "staticlib"]

[profile.release]
lto = true

[dependencies]
wasm-bindgen = "0.2"
console_error_panic_hook = { version = "0.1", optional = true }

It compiles and works fine until we try to allocate dynamic memory and it fails with this message:

Hello from unity
webgel.framework.js.gz:3:34890
84
webgel.framework.js.gz:3:34890
<empty string> webgel.framework.js.gz:3:34890
<empty string> webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
<empty string> 2 webgel.framework.js.gz:3:34818
<empty string> webgel.framework.js.gz:3:34890
exception thrown: SyntaxError: Document.querySelector: '' is not a valid selector,_JS_SystemInfo_GetCanvasClientSize@http://localhost:34479/Build/webgel.framework.js.gz:3:57039
@http://localhost:34479/Build/webgel.wasm.gz:wasm-function[8149]:0x26ad7f
@http://localhost:34479/Build/webgel.wasm.gz:wasm-function[15242]:0x43dcac
browserIterationFunc@http://localhost:34479/Build/webgel.framework.js.gz:3:183295
callUserCallback@http://localhost:34479/Build/webgel.framework.js.gz:3:136702
runIter@http://localhost:34479/Build/webgel.framework.js.gz:3:137978
Browser_mainLoop_runner@http://localhost:34479/Build/webgel.framework.js.gz:3:136237
webgel.loader.js:1:6569
    printErr http://localhost:34479/Build/webgel.loader.js:1
    callUserCallback http://localhost:34479/Build/webgel.framework.js.gz:3
    runIter http://localhost:34479/Build/webgel.framework.js.gz:3
    Browser_mainLoop_runner http://localhost:34479/Build/webgel.framework.js.gz:3
Invoking error handler due to
SyntaxError: Document.querySelector: '' is not a valid selector
_JS_SystemInfo_GetCanvasClientSize@http://localhost:34479/Build/webgel.framework.js.gz:3:57039
@http://localhost:34479/Build/webgel.wasm.gz:wasm-function[8149]:0x26ad7f
@http://localhost:34479/Build/webgel.wasm.gz:wasm-function[15242]:0x43dcac
browserIterationFunc@http://localhost:34479/Build/webgel.framework.js.gz:3:183295
callUserCallback@http://localhost:34479/Build/webgel.framework.js.gz:3:136702
runIter@http://localhost:34479/Build/webgel.framework.js.gz:3:137978
Browser_mainLoop_runner@http://localhost:34479/Build/webgel.framework.js.gz:3:136237

I was wondering if anyone knew why this problem occurs. I assume it has to do with the memory allocator used by unity (they use emscripten to compile to wasm).