-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support no_main wasi binaries #1716
Comments
Not an avid Rust user, but maybe you can use |
I use no_main, but wasmer + wasi fails with the error above |
@Yamakaky last I worked on that part of our WASI implementation, it was a requirement to have an empty main. This is because WASI binaries need to do setup of their filesystem and other resources on the Wasm side (done in WASI libc) before env vars, files, and other features like that can be used. The last I looked, this set up code was called in I just compiled a WASI program with Rust 1.47.0 and I see
In the Wasm. That function is called by |
In regards to
It sounds like that's possibly a bug in the WASI generating code. It looks like it unconditionally expects a main function and treats it as an import if it can't find one in the Wasm. Which may be intentional, actually, if the library use case isn't supported yet. |
I see. So the best practice would be to call the empty main after instantiation, then call my entry points? Or do you have to be in main to call fs functions for example |
No, once the set up is done you can call these fs related things from other functions. Wasi-libc seems to have partial support for this https://reviews.llvm.org/D81689 ; but I tried compiling some Rust with latest nightly and latest stable and neither call the fs set up code on other entrypoints. Perhaps this is the job of the runtime as it can act like a linker. I'm not sure, this is something we'll have to look into later.
I think that's the best course of action for now!
I don't know specifically, but I'd assume it's similar to |
I did some testing. stdout always works, but the only way to use fs functions is to call the empty main via _start. cdylib, no_main and not calling _start doesn't work. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
We want to work on this.
|
We need to reproduce this with a WASI example |
I cannot reproduce this issue, the example in the original post works as intended. This issue is extremely old (> 2 years now), it may have gotten fixed in the meantime. Maybe this issue can be closed now.
I am confused by the issue title, because the example in the linked code has a
... because the
// lib.rs, build with:
// cargo +nightly build -Zbuild-std --release --target wasm32-wasi
// ar -x target/wasm32-wasi/release/project.rlib
// wasmer run ./project.8cd299b3f128130.project.2a7776b6-cgu.0.rcgu.o
#![no_std]
#![no_main]
#![feature(lang_items, core_intrinsics)]
#[panic_handler]
#[no_mangle]
pub fn panic(_info: &core::panic::PanicInfo) -> ! {
core::intrinsics::abort();
}
#[lang = "eh_personality"]
extern "C" fn rust_eh_personality() {}
extern "C" {
pub fn foo(ptr: *const u8);
} ... which compiles to:
... which fails with So in summary, the only problem is that |
Summary
I'm working on a distributed computing framework using wasm. The computing part is compiled from rust to wasm and exposes multiple entrypoints that are executed on the remote workers. I added wasi support to be able to println from wasm and for file access in the future.
If I build the wasm with a main function, everything works fine. If I use the
no_main
attribute,Instance::new
fails with this error :Error while importing "env"."main": unknown import. Expected Function(FunctionType { params: [I32, I32], results: [I32] })
.Current API (gets compiled to both native and wasm : https://github.com/Yamakaky/distilled/blob/master/wasm/src/main.rs
Wasi setup : https://github.com/Yamakaky/distilled/blob/master/src/lib.rs#L92-L99
Am I missing something? Is
main
required to properly use wasi or can I just have an emptymain
and never call it?Additional details
The text was updated successfully, but these errors were encountered: