Closed
Description
This bug was wrongly posted at wasm-bindgen, but it looks like it is a compiler issue.
The following example fails to create a proper module, with either:
- rustc 1.44.0-beta.4 (02c25b3 2020-05-23)
- rustc 1.45.0-nightly (a74d186 2020-05-14)
(stable rustc 1.43.1 works fine).
Cargo.toml
[package]
name = "wasm-env-issue"
version = "0.1.0"
edition = "2018"
[lib]
crate-type=["cdylib"]
[profile.release]
lto = true
panic = "abort"
[dependencies]
wasm-bindgen = "0.2.55"
src/lib.rs
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn wasm_sin(key: i32) -> i32 {
(key as f32).sin() as i32
}
With this command to compile:
wasm-pack build --no-typescript --target no-modules
produces this error:
error: cannot import from modules (env) with --no-modules
Looking at the compiled wasm
, with wasm-dis
, there is this line that doesn't seem correct.
(import "env" "_ZN4core9panicking18panic_bounds_check17hadfb911a22557eccE" (func $_ZN4core9panicking18panic_bounds_check17hadfb911a22557eccE (param i32 i32 i32)))
Switching lto
to false
or changing the sin()
to asin()
, for example, make the "env"
disappear.