Hey there,
I am wondering if this heuristic is suffice to determine a given Wasm binary is targeting wasi-http/proxy
world:
impl<'a> ComponentTarget<'a> {
fn new<'b, I>(exports: I, func: &'a str) -> Self
where
I: IntoIterator<Item = (&'b str, ComponentItem)> + 'b,
{
// This is heuristic but seems to work
let has_http_handler = exports
.into_iter()
.any(|(name, _)| name.starts_with("wasi:http/incoming-handler"));
match (func, has_http_handler) {
("_start", false) => Self::Command,
("_start", true) => Self::HttpProxy,
_ => Self::Core(func),
}
}
}
Also, why does the wasi:http component's entrypoint is _start
?
CC some experts on this: @Alex Crichton @Joel Dice
The name.starts_with("wasi:http/incoming-handler")
parts looks right, but I don't see how _start
would be involved. If you're trying to see if it's a command, you'd look for name.starts_with("wasi:cli/run")
I guess you'd look for _start
in the case of a WASIp1 command, but in that case you'd be looking at a module rather than a component.
And if you're trying to determine whether a binary targets p1 vs p2, you'd first check whether it's a module or a component.
right, so wasip1 is always a module, and wasip2 is always a component
Thank you so much!
Correct, although wasit2
(or something like it, i.e. a module that uses the component model ABI) will eventually be a thing, also: https://github.com/WebAssembly/component-model/pull/378
oh interesting. wondering what does t
mean in wasit2
"transitional": https://github.com/WebAssembly/WASI/issues/595#issuecomment-2087137863
Thanks for the context!
started to think this might be very useful for Go
@Mossaka (Joe) I assume you're aware of it, but just in case you're not: wasm-tools component targets
might be of interest
Last updated: Dec 23 2024 at 12:05 UTC