Uh oh!
There was an error while loading. Please reload this page.
Add a -Zwasi-exec-model codegen option for emitting WASI reactors - #79997
Conversation
rust-highfive
commented
Dec 13, 2020
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. |
petrochenkov
commented
Dec 13, 2020
LGTM from the linking infrastructure point of view, r? @alexcrichton on WASM specifics. |
alexcrichton
commented
Dec 14, 2020
Thanks! I'd double check with @sunfishcode since I believe you implemented this in Clang, does this look right? |
coolreader18
commented
Dec 19, 2020
@sunfishcode could you take a look at this? |
sunfishcode
commented
Dec 20, 2020
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 |
coolreader18
commented
Dec 20, 2020
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 |
sunfishcode
commented
Dec 20, 2020
"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. |
coolreader18
commented
Dec 20, 2020
Alright, that makes sense. @petrochenkov what do you think would be the best way of doing this? Should LinkOutputKind become a struct, with |
sunfishcode
commented
Dec 21, 2020
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 |
petrochenkov
commented
Dec 21, 2020
Since the set of linked objects is keyed on As for user-facing interface, a new target specific option |
coolreader18
commented
Dec 22, 2020
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Dec 22, 2020
@coolreader18 Could you also squash commits into one before this is merged? |
776c1f3 to
6ab619aComparerust-log-analyzer
commented
Jan 9, 2021
alexcrichton
commented
Jan 11, 2021
@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]pubextern"C"fnfoo(){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? |
coolreader18
commented
Jan 14, 2021
@Ekleog oh, yeah, I changed how you enable reactors but never the title of the PR, so it's misleading. Try removing the |
Ekleog
commented
Jan 14, 2021
That seems to work! So to sum up how this is to be used, for other readers:
Thank you! :D |
coolreader18
commented
Jan 14, 2021
Yep, no problem! Also note that you don't need a |
sunfishcode
commented
Jan 14, 2021
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 <piotrsikora@google.com>
* 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 <piotrsikora@google.com> * review: sort. Signed-off-by: Piotr Sikora <piotrsikora@google.com> Co-authored-by: Marcel Hlopko <hlopko@google.com>
ValeryAntopol
commented
Jun 24, 2022
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.mdEmpty
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
_initializeexport is a very small change.