-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add a -Zwasi-exec-model codegen option for emitting WASI reactors #79997
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matthewjasper (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
LGTM from the linking infrastructure point of view, r? @alexcrichton on WASM specifics. |
Thanks! I'd double check with @sunfishcode since I believe you implemented this in Clang, does this look right? |
@sunfishcode could you take a look at this? |
My main concern here is with the re-use of the "dylib" concept. In clang, for comparison, we didn't re-use Real dynamic libraries are coming, and I expect we'll want to use "dylib" and |
Would it make sense to add a new |
Although, maybe it would make sense for a reactor to be a dylib and vice versa? It should obviously be left to the wasi repo to determine the spec (and only after the dynamic linking proposal gets merged), but ELF |
"Reactor" is indeed an evolving concept, but it currently looks like a Reactor is indeed a kind of Exe. It's not yet clear if we'll have a concept of Pic|NoPic, but Static|Dynamic will apply, once we have dynamic linking. |
Alright, that makes sense. @petrochenkov what do you think would be the best way of doing this? Should LinkOutputKind become a struct, with |
Yes, the For context, much of this will change when module-linking and interface-types are ready, and we rebase the "Reactor" concept on top of them. I should be clear that everything I'm saying here about Reactors is based on my best guesses as to how we're going to want things to work once module-linking and interface-types are ready, rather than any kind of complete plan. With that said, I think it doesn't make sense to think of making |
Since the set of linked objects is keyed on As for user-facing interface, a new target specific option |
Alright, this works. The one thing that is notable is that since it's an exe but doesn't really have a main function, it errors if there's no w.r.t the |
This comment has been minimized.
This comment has been minimized.
@coolreader18 Could you also squash commits into one before this is merged? |
776c1f3
to
6ab619a
Compare
@bors: retry |
Rollup of 9 pull requests Successful merges: - rust-lang#79997 (Emit a reactor for cdylib target on wasi) - rust-lang#79998 (Use correct ABI for wasm32 by default) - rust-lang#80042 (Split a func into cold/hot parts, reducing binary size) - rust-lang#80324 (Explain method-call move errors in loops) - rust-lang#80864 (std/core docs: fix wrong link in PartialEq) - rust-lang#80870 (resolve: Simplify built-in macro table) - rust-lang#80885 (rustdoc: Resolve `&str` as `str`) - rust-lang#80904 (Fix small typo) - rust-lang#80923 (Merge different function exits) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Hey, Thank you for this PR! It comes just in time, at the moment I actually wanted to try to use that, so that's a great timing! That said, I'm trying to use this without success. I'm using
with this source code: #[no_mangle]
pub extern "C" fn foo() {
println!("before read");
println!("read: {:?}", std::fs::read_to_string("foo.txt"));
println!("after read");
} and this Cargo.toml: [package]
name = "foo"
version = "0.1.0"
[lib]
crate-type = ["cdylib"] I don't see the
What am I missing? |
@Ekleog oh, yeah, I changed how you enable reactors but never the title of the PR, so it's misleading. Try removing the |
That seems to work! So to sum up how this is to be used, for other readers:
Thank you! :D |
Yep, no problem! Also note that you don't need a |
Also for other readers, keep in mind that this area is still in development, so some parts of the above may change over time 🙂 |
@coolreader18 When I compile a WASM-WASI module with |
The ability to build Wasm libraries as executables is needed to support WASI reactors (Wasm executables with multiple entrypoints). This is a temporary workaround, and we should be able to use crate-type "bin" when a proper support for WASI reactors (rust-lang/rust#79997) is stabilised is Rust. This feature was added in bazelbuild#312, and most recently broken in bazelbuild#592. Signed-off-by: Piotr Sikora <[email protected]>
* Re-add support for building Wasm libraries as executables. The ability to build Wasm libraries as executables is needed to support WASI reactors (Wasm executables with multiple entrypoints). This is a temporary workaround, and we should be able to use crate-type "bin" when a proper support for WASI reactors (rust-lang/rust#79997) is stabilised is Rust. This feature was added in #312, and most recently broken in #592. Signed-off-by: Piotr Sikora <[email protected]> * review: sort. Signed-off-by: Piotr Sikora <[email protected]> Co-authored-by: Marcel Hlopko <[email protected]>
Are there any estimations or places to track about stabilizing this feature? We are using "handmade" wasm reactors, and suddenly realized that any call to our wasm reactors leads to a memory leak if the module was build with rustc 1.56 or higher. That is quite sad and we have to make a workaround instead of using this feature, because we really don't want to switch to nightly for our wasm SDK. I know about adding an explicit call to |
Fixes #79199, and relevant to #73432
Implements wasi reactors, as described in WebAssembly/WASI#13 and
design/application-abi.md
Empty
lib.rs
,lib.crate-type = ["cdylib"]
:reactor.wat
:I went with repurposing cdylib because I figured that it doesn't make much sense to have a wasi shared library that can't be initialized, and even if someone was using it adding an
_initialize
export is a very small change.