The following Rust compiled to WASM, based on the Wasmer exports_global.rs WASM example, produces incorrect WASM (with cargo build --target=wasm32-wasi
):
// (module
// (global $one (export "one") f32 (f32.const 1))
// (global $some (export "some") (mut f32) (f32.const 0))
// (func (export "get_one") (result f32) (global.get $one))
// (func (export "get_some") (result f32) (global.get $some))
// (func (export "set_some") (param f32) (global.set $some (local.get 0))))
#[no_mangle]
pub static one: f32 = 1.0;
#[no_mangle]
pub static mut some: f32 = 0.0;
#[no_mangle]
pub extern "C" fn get_one() -> f32 {
one
}
#[no_mangle]
pub extern "C" fn get_some() -> f32 {
unsafe { some }
}
#[no_mangle]
pub extern "C" fn set_some(value: f32) {
unsafe {
some = value;
}
}
Inspecting the compiled module, I get:
wasmer inspect .\target\wasm32-wasi\debug\rust_wasm.wasm
Type: wasm
Size: 2.1 MB
Imports:
Functions:
Memories:
Tables:
Globals:
Exports:
Functions:
"get_one": [] -> [F32]
"get_some": [] -> [F32]
"set_some": [F32] -> []
Memories:
"memory": not shared (17 pages..)
Tables:
Globals:
"some": I32 (constant)
"one": I32 (constant)
Specifically, the Globals
are wrong. They should both be F32
and some
should be mutable. Why is this happening?