aleksmelnikov opened Issue #1440:
Hi,
please advise me how to make:
- I created a simple library crate:
$cat a/src/lib.rs #[no_mangle] pub extern "C" fn funca() { println!("funca"); } #[no_mangle] pub extern "C" fn _start() { }And compiled it:
cargo build --manifest-path=a/Cargo.toml --target=wasm32-wasi
I can invoke
funca
:$wasmtime run --invoke funca a/target/wasm32-wasi/debug/a.wasm funca
- I created a simple binary crate:
$cat d/src/main.rs use anyhow::Result; use wasmtime::*; use wasmtime_wasi::{Wasi, WasiCtx}; fn main() -> Result<()> { let store = Store::default(); let module = Module::from_file(&store, "/at/rust/wasmer/a/target/wasm32-wasi/debug/a.wasm")?; let wasi = Wasi::new(&store, WasiCtx::new(std::env::args())?); let mut imports = Vec::new(); for import in module.imports() { if import.module() == "wasi_snapshot_preview1" { if let Some(export) = wasi.get_export(import.name()) { imports.push(Extern::from(export.clone())); continue; } } panic!( "couldn't find import for `{}::{}`", import.module(), import.name() ); } let instance = Instance::new(&module, &imports)?; // 1 /* let start = instance .get_export("_start") .and_then(|e| e.func()) .unwrap(); let start = start.get0::<()>()?; start()?; */ // 2 let funca = instance .get_export("funca") .expect("export named `answer` not found") .func() .expect("export `answer` was not a function"); let funca = funca.get0::<()>()?; funca()?; Ok(()) }And compiled it:
cargo build --manifest-path=d/Cargo.toml
I ran it and got:
$cargo run --manifest-path=d/Cargo.toml funcaGood! Now I want change d from binary crate to library crate. So, I want wasm lib calls wasm lib.
The first, I tried to compile my bin crate with--target=wasm32-wasi
to getwasm
and failed:$cargo +nightly build --manifest-path=d/Cargo.toml --target=wasm32-wasi Compiling wat v1.0.13 Compiling jobserver v0.1.21 Compiling generic-array v0.12.3 Compiling region v2.1.2 Compiling gimli v0.20.0 error[E0425]: cannot find function `lock` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/lock.rs:30:7 | 30 | os::lock( | ^^^^ not found in `os` | help: possible candidate is found in another module, you can import it into scope | 1 | use lock::lock; | error[E0425]: cannot find function `unlock` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/lock.rs:58:7 | 58 | os::unlock( | ^^^^^^ not found in `os` | help: possible candidate is found in another module, you can import it into scope | 1 | use lock::unlock; | error[E0425]: cannot find function `page_size` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/page.rs:16:39 | 16 | INIT.call_once(|| PAGE_SIZE = os::page_size()); | ^^^^^^^^^ not found in `os` error[E0425]: cannot find function `set_protection` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/protect.rs:40:7 | 40 | os::set_protection( | ^^^^^^^^^^^^^^ not found in `os` error[E0425]: cannot find function `get_region` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/lib.rs:133:7 | 133 | os::get_region(page::floor(address as usize) as *const u8) | ^^^^^^^^^^ not found in `os` error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0425`. error: could not compile `region`. To learn more, run the command again with --verbose. warning: build failed, waiting for other jobs to finish... error: build failedSo, I think doesn't
region
support--target=wasm32-wasi
? How to create wasm calls wasm?
bjorn3 commented on Issue #1440:
You can't compile
wasmtime
for wasm, as wasm doesn't allow any JIT compilation. What do you want to actually do?
aleksmelnikov commented on Issue #1440:
@bjorn3 , ok. Thank you for the notes about
wasmtime
. I see my mistake.
aleksmelnikov closed Issue #1440:
Hi,
please advise me how to make:
- I created a simple library crate:
$cat a/src/lib.rs #[no_mangle] pub extern "C" fn funca() { println!("funca"); } #[no_mangle] pub extern "C" fn _start() { }And compiled it:
cargo build --manifest-path=a/Cargo.toml --target=wasm32-wasi
I can invoke
funca
:$wasmtime run --invoke funca a/target/wasm32-wasi/debug/a.wasm funca
- I created a simple binary crate:
$cat d/src/main.rs use anyhow::Result; use wasmtime::*; use wasmtime_wasi::{Wasi, WasiCtx}; fn main() -> Result<()> { let store = Store::default(); let module = Module::from_file(&store, "/at/rust/wasmer/a/target/wasm32-wasi/debug/a.wasm")?; let wasi = Wasi::new(&store, WasiCtx::new(std::env::args())?); let mut imports = Vec::new(); for import in module.imports() { if import.module() == "wasi_snapshot_preview1" { if let Some(export) = wasi.get_export(import.name()) { imports.push(Extern::from(export.clone())); continue; } } panic!( "couldn't find import for `{}::{}`", import.module(), import.name() ); } let instance = Instance::new(&module, &imports)?; // 1 /* let start = instance .get_export("_start") .and_then(|e| e.func()) .unwrap(); let start = start.get0::<()>()?; start()?; */ // 2 let funca = instance .get_export("funca") .expect("export named `answer` not found") .func() .expect("export `answer` was not a function"); let funca = funca.get0::<()>()?; funca()?; Ok(()) }And compiled it:
cargo build --manifest-path=d/Cargo.toml
I ran it and got:
$cargo run --manifest-path=d/Cargo.toml funcaGood! Now I want change d from binary crate to library crate. So, I want wasm lib calls wasm lib.
The first, I tried to compile my bin crate with--target=wasm32-wasi
to getwasm
and failed:$cargo +nightly build --manifest-path=d/Cargo.toml --target=wasm32-wasi Compiling wat v1.0.13 Compiling jobserver v0.1.21 Compiling generic-array v0.12.3 Compiling region v2.1.2 Compiling gimli v0.20.0 error[E0425]: cannot find function `lock` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/lock.rs:30:7 | 30 | os::lock( | ^^^^ not found in `os` | help: possible candidate is found in another module, you can import it into scope | 1 | use lock::lock; | error[E0425]: cannot find function `unlock` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/lock.rs:58:7 | 58 | os::unlock( | ^^^^^^ not found in `os` | help: possible candidate is found in another module, you can import it into scope | 1 | use lock::unlock; | error[E0425]: cannot find function `page_size` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/page.rs:16:39 | 16 | INIT.call_once(|| PAGE_SIZE = os::page_size()); | ^^^^^^^^^ not found in `os` error[E0425]: cannot find function `set_protection` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/protect.rs:40:7 | 40 | os::set_protection( | ^^^^^^^^^^^^^^ not found in `os` error[E0425]: cannot find function `get_region` in module `os` --> /opt/rust/cargo/registry/src/github.com-1ecc6299db9ec823/region-2.1.2/src/lib.rs:133:7 | 133 | os::get_region(page::floor(address as usize) as *const u8) | ^^^^^^^^^^ not found in `os` error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0425`. error: could not compile `region`. To learn more, run the command again with --verbose. warning: build failed, waiting for other jobs to finish... error: build failedSo, I think doesn't
region
support--target=wasm32-wasi
? How to create wasm calls wasm?
yurydelendik commented on Issue #1440:
Per zullip chat, more notes:
-
wasmtime-cli
does not have a way to configure a linking, (--preload
is not a parameter that does that)
- it is expected that
wasmtime-cli
will automatically resolve and load dependent modules.- currently, the embedding (e.g. https://github.com/bytecodealliance/wasmtime/blob/master/examples/linking.rs) is easiest way to do that
yurydelendik edited a comment on Issue #1440:
Per zullip chat, more notes:
wasmtime-cli
does not have a way to configure a linking, (--preload
is not a parameter that does that)- it is expected that
wasmtime-cli
will automatically resolve and load dependent modules.- currently, the embedding (e.g. https://github.com/bytecodealliance/wasmtime/blob/master/examples/linking.rs) is easiest way to do that
yurydelendik edited a comment on Issue #1440:
Per zullip chat, more notes:
wasmtime-cli
does not have a way to configure linking, (--preload
is not a parameter that does that)- it is expected that
wasmtime-cli
will automatically resolve and load dependent modules.- currently, the embedding (e.g. https://github.com/bytecodealliance/wasmtime/blob/master/examples/linking.rs) is easiest way to do that
Last updated: Nov 22 2024 at 16:03 UTC