Stream: wasi

Topic: heuristic to determine if a component tagets wasi-http


view this post on Zulip Mossaka (Joe) (Oct 15 2024 at 16:58):

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

view this post on Zulip Joel Dice (Oct 15 2024 at 17:03):

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")

view this post on Zulip Joel Dice (Oct 15 2024 at 17:04):

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.

view this post on Zulip Joel Dice (Oct 15 2024 at 17:05):

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.

view this post on Zulip Mossaka (Joe) (Oct 15 2024 at 17:07):

right, so wasip1 is always a module, and wasip2 is always a component

view this post on Zulip Mossaka (Joe) (Oct 15 2024 at 17:07):

Thank you so much!

view this post on Zulip Joel Dice (Oct 15 2024 at 17:08):

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

This PR adds BuildTargets.md to define this new concept of "build targets" as presented in both CG-06 and WASI-06-12, which itself was a revision of the earlier "wasit2" idea th...

view this post on Zulip Mossaka (Joe) (Oct 15 2024 at 17:11):

oh interesting. wondering what does t mean in wasit2

view this post on Zulip Joel Dice (Oct 15 2024 at 17:12):

"transitional": https://github.com/WebAssembly/WASI/issues/595#issuecomment-2087137863

Do apologize in advance if this is not the right repository for this issue; happy to move it somewhere else I added an item to the agenda for the next WASI meeting to discuss this topic: WebAssembl...

view this post on Zulip Mossaka (Joe) (Oct 15 2024 at 17:13):

Thanks for the context!

view this post on Zulip Mossaka (Joe) (Oct 15 2024 at 17:13):

started to think this might be very useful for Go

view this post on Zulip Till Schneidereit (Oct 16 2024 at 20:00):

@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