Stream: general

Topic: ✔ Cannot compile wasm32-wasi with wit-bindgen-wasmtime


view this post on Zulip Ari Seyhun (Mar 20 2022 at 14:09):

I'm trying to compile my Rust code to wasi (using wit-bindgen-wasmtime::export!) with the command:

cargo build --target wasm32-wasi --release

But I receive some errors from the region-2.2.0 package:

30 |   os::lock(
   |       ^^^^ not found in `os`
60 |   os::unlock(
   |       ^^^^^^ not found in `os`
16 |     INIT.call_once(|| PAGE_SIZE = os::page_size());
   |                                       ^^^^^^^^^ not found in `os`
48 |   os::set_protection(
   |       ^^^^^^^^^^^^^^ not found in `os`
133 |   os::get_region(page::floor(address as usize) as *const u8)
    |       ^^^^^^^^^^ not found in `os`

Running cargo tree --invert region I get:

region v2.2.0
├── wasmtime v0.34.1
   └── wit-bindgen-wasmtime v0.1.0 (https://github.com/bytecodealliance/wit-bindgen#2f46ce4c)
       └── thalo-bank-account v0.1.0 (/private/tmp/thalo-bank-account)
       [build-dependencies]
       └── thalo-bank-account v0.1.0 (/private/tmp/thalo-bank-account)
├── wasmtime-jit v0.34.1
   └── wasmtime v0.34.1 (*)
└── wasmtime-runtime v0.34.1
    ├── wasmtime v0.34.1 (*)
    └── wasmtime-jit v0.34.1 (*)

view this post on Zulip Dan Gohman (Mar 20 2022 at 14:54):

wit-bindgen-wasmtime is for host code, which is typically compiled natively for the host. You likely want to use wit-bindgen-rust instead, which is for wasm code.

view this post on Zulip Ari Seyhun (Mar 20 2022 at 14:56):

I'm planning to compile to wasi and and execute it from rust again rather than the browser. If I'm compiling from Rust and running in Rust too, it should be wit-bindgen-wasmtime right?

view this post on Zulip Dan Gohman (Mar 20 2022 at 14:59):

wit-bindgen-wasmtime is for building host implementations meant to be linked into wasmtime. Are you using wasmtime?

view this post on Zulip Ari Seyhun (Mar 20 2022 at 15:04):

Yes I was planning to run the wasm file with wasmtime, similar to the tutorial here: <https://docs.wasmtime.dev/examples-rust-wasi.html>

view this post on Zulip Dan Gohman (Mar 20 2022 at 15:05):

Ah. So, wasmtime itself is not something that can be compiled to WASI. It uses JIT compilation and other platform features which aren't supported in WASI.

view this post on Zulip Dan Gohman (Mar 20 2022 at 15:07):

If you want to run code in the browser, it's better to look for ways to be able to use the browser's wasm engine. If you need WASI support, something like https://github.com/bjorn3/browser_wasi_shim might help.

A WASI shim for in the browser. Contribute to bjorn3/browser_wasi_shim development by creating an account on GitHub.

view this post on Zulip Ari Seyhun (Mar 20 2022 at 15:12):

Hmm I don't need to run wasi in the browser. Essentially I am using wit_bindgen_rust::export("file.wit"); in one Rust library, and in another Rust binary I want to run it with wit_bindgen_rust::import("file.wit");

view this post on Zulip Dan Gohman (Mar 20 2022 at 15:14):

Ah, ok. To do that, you'll need wasmlink

A language binding generator for WebAssembly interface types - wit-bindgen/crates/wasmlink at main · bytecodealliance/wit-bindgen

view this post on Zulip Ari Seyhun (Mar 20 2022 at 15:17):

Oh interesting. I remember trying to do the same thing I'm trying now a few months and I don't recall needing wasmlink.
My main goal is to let users write wasi modules which I can then run from my Rust code (which I thought would be done with wasmtime).

Is there a difference between wasm and wasi? I thought wasm is for running in the browser, and wasi is for running outside the browser

view this post on Zulip Dan Gohman (Mar 20 2022 at 15:20):

Roughly speaking, wasm is the platform ISA, while wasi is an OS API.

view this post on Zulip Dan Gohman (Mar 20 2022 at 15:21):

In browsers, you have wasm, but browsers don't provide the WASI APIs

view this post on Zulip Ari Seyhun (Mar 20 2022 at 15:35):

Ah okay I realised my issue.
I was using wit-bindgen-gen-wasmtime for the library, when I should've been using wit-bindgen-gen-rust-wasm.

view this post on Zulip Notification Bot (Mar 20 2022 at 15:35):

Ari Seyhun has marked this topic as resolved.

view this post on Zulip Notification Bot (Mar 20 2022 at 15:51):

Ari Seyhun has marked this topic as unresolved.

view this post on Zulip Ari Seyhun (Mar 20 2022 at 15:53):

When running cargo build --target wasm32-wasi --release, I cannot see any wasm or wasi file in target/wasm32-wasi/release...
The only files are:

// some folders...
// These files:
my_lib.d
my_lib.rlib

Should I be compiling to wasm32-unknown-unknown instead? What is the point of compiling to wasm32-wasi?

view this post on Zulip Ari Seyhun (Mar 20 2022 at 15:57):

It seems compining to wasm32-unknown-unknown also doesn't create a wasm file

view this post on Zulip Ari Seyhun (Mar 20 2022 at 16:00):

I think I may be missing a [[lib]] section in my Cargo toml but I can't recall what I need to set it to.

view this post on Zulip Ari Seyhun (Mar 20 2022 at 16:03):

Got it working with crate-type = ['cdylib']

view this post on Zulip Notification Bot (Mar 20 2022 at 16:03):

Ari Seyhun has marked this topic as resolved.


Last updated: Dec 23 2024 at 12:05 UTC