In C:
-shared
means to produce a shared-everything dynamic library (with a dylink.0
, PIC, imported memory, etc.)-mexec-model=reactor
means to produce a "reactor-style" Wasm module (no dylink.0
, no PIC, exported memory, etc.).In Rust:
cdylib
means to produce a "reactor-style" Wasm moduleShould we be thinking about a plan to add shared-everything dynamic linking support for Rust? I don't know of anyone that urgently needs it, but if we will eventually need it, perhaps we should start thinking about how we'll get there?
I think it'd be fine to redefine cdylib
on the wasm32-wasip2
target and beyond, but beyond that I don't know of a great way to deal with -mexec-model
.
The closest equivalent I can think of is #![windows_subsystem = "..."]
at the crate level
How hard would it be to add a new crate-type?
Dan Gohman said:
...
- there is no way to produce a shared-everything dynamic library (AFAICT)
Should we be thinking about a plan to add shared-everything dynamic linking support for Rust? I don't know of anyone that urgently needs it, but if we will eventually need it, perhaps we should start thinking about how we'll get there?
You can do it today with some black magic, e.g.: RUSTFLAGS="-C relocation-model=pic" cargo +nightly build -Zbuild-std=panic_abort,std --release --target=wasm32-wasi
and crate-type = [ "staticlib" ]
to build a PIC .a file, which you can then run through clang -shared -Wl,--whole-archive <name>.a --Wl,--no-whole-archive
. What could be easier? :)
Just making "-C relocation-model=pic" the default for wasm32-wasip2
would be a big step forward
To do even that though, we should have something to migrate existing users to.
I suspect adding a new crate type would be a very big ask
that's integrated in tons and tons of rust tooling
alternatively we could make #![no_main]
work for executables perhaps
to map to the "reactor" case
Ooh, that's an interesting idea.
Hmm, no_start
means something subtly different on other architectures. It looks like what we might want is the #![no_entry]
proposal.
it might be best to have #![wasm_something = "something"]
perhaps to sidestep portability concerns
we don't really want to force any other platform to worry about this
I'm not sure if we want to persist the "command" and "reactor" terminology though?
perhaps #![wasm_no_start]
on the crate
Yeah, I was never a huge fan of "reactor", and would be happy to use some other term.
with wasm_no_start
we perhaps wouldn't have to give it a name even
it's all just wasm binaries with or without a start
What about #![wasm_exec = "exports"]
, which is sort of short for "the way you execute the code is, you call the exports"?
I like the idea of the terminology, but reading #![wasm_exec = "exports"]
as a standalone thing doesn't do a great job of conveying that, so we might want some wordsmithing there
"world"?
#![wasm_entry = "exports"]
maybe? defaulted to "main"
?
Or maybe we can do some more magic and infer this from the world the bindings are generated from.
hm I think we need knowledge before that
b/c right now wasm-component-ld
picks the adapter based on _start
or not
e.g. this
so I think rustc needs to know about the shape of generated code
and rustc won't have total knowledge of linked libraries for example
All we really need to know is if you have wasi:cli/run@0.2.0
that's part of the adapter though, so rustc will never see that
I'd be ok waiting on these changes until we don't have an adapter anymore
If that makes it simpler
but even then where would wasi:cli/run@0.2.0
be referenced?
e.g. as a rust programmer you're "just" doing fn main() {}
so I feel like we need a source-level annotation of whether that's expected or not for the compiler
Hmm, yeah.
Last updated: Dec 23 2024 at 13:07 UTC