anderslanglands / ustr

Fast, FFI-friendly string interning for Rust
Other
151 stars 26 forks source link

Wasm-pack fails with ustr #22

Closed mverleg closed 2 years ago

mverleg commented 3 years ago

I don't know if wasm-pack is supported by ustr, but I think it'd be useful to record this, in case anyone else runs into it. I'm also not sure if the problem is with ustr or wasm-pack or some dependency.

Problem

Building WebAssembly with wasm-pack 0.10.1 fails if the project uses Ustr:

wasm-pack build --target no-modules

The error is (with some paths shortened):

error: cannot import from modules (`env`) with `--no-modules`
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 1
  full command: "..../.cache/.wasm-pack/wasm-bindgen-e63eccbd87203048/wasm-bindgen" ".../target/wasm32-unknown-unknown/release/minimal_ustr_wasmpack_reproduction.wasm" "--out-dir" ".../pkg" "--typescript" "--target" "no-modules"

If the target is web, the error is different and happens at runtime, but I believe it's still related.

Analysis

Looks a bit like rust-lang/rust issue 72758 but I'm not sure.

Minimal example

Wasm-pack is needed: cargo install wasm-pack

Cargo.toml:

[package]
name = "minimal_ustr_wasmpack_reproduction"
version = "0.1.0"
edition = "2021"

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

[dependencies]
ustr = "0.8.1"
wasm-bindgen = "0.2.78"

src/lib/rs

use ::ustr::Ustr;
use ::wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn mre() {
    Ustr::from("hello");
}
anderslanglands commented 3 years ago

Thanks for reporting this. I've not tried using wasm before but I'll try and take a look when I get some time.

IWANABETHATGUY commented 2 years ago

You could try

ustr = { git = "https://github.com/IWANABETHATGUY/ustr", branch = "chore/bump-parking-lot", default-features = false, features = [
  "parkinglot",
] }

I have tested locally, the failed message gone after I bump the parking_lot to 0.12.1