Stream: wasmtime

Topic: ✔ wamtim run --wasm component-model and start


view this post on Zulip Scott Waye (Dec 10 2023 at 02:36):

I'm trying to manually add a startsection to the final composed wasm. My wat then ends with :

  (func $___start (canon lift
    (core func 3 "___start")
  ))
  (start $___start

I put that back through wasm-tools parse and run it with wasmtime run --wasm component-model c:\tmp\calculator.start.wasm and get the message

Error: failed to parse WebAssembly module

Caused by:
    unknown core instance 3: instance index out of bounds (at offset 0x11711d4)

Which indicates it can't find instance 3, but even if I put 0 there (and I think 3 is correct), I get the same error. I must have a t least one instance in the wasm, in fact it looks like there are up to 26 core instance sections, so confused that the error is index out of bounds.

view this post on Zulip Scott Waye (Dec 10 2023 at 23:33):

I think the problem is there are no "core component" sections at this level. There are "component" sections, so maybe the func should not have core func but something else.

view this post on Zulip Alex Crichton (Dec 11 2023 at 16:03):

If it works I'd recommend using $-names instead of raw indices. For example tag the core instance with "__start" with $foo and then use $foo there and that might help surface whether the $foo instance is in or out of scope

view this post on Zulip Scott Waye (Dec 11 2023 at 16:05):

Thanks I will try that, I also need to understand better the composed structure

view this post on Zulip Scott Waye (Dec 12 2023 at 00:56):

I'm still trying to get this wat right for defining a start. I have a question about

(instance (;20;) (instantiate 0

(there are indices because it is the output of wasm-tools print and changing them to names is not trivial). If component 0 exports a function, does the instance automatically export that funciton, or does it need to be an inline export? I did try

(with "____start" (instance (export "____start" )))

but that doesn't seem to be the right syntax:

error: expected `(`
     --> c:\tmp\calculator.wat:6674915:55
      |
 6674915 |       (with "____start" (instance (export "____start" func)))
      |

view this post on Zulip Scott Waye (Dec 12 2023 at 01:08):

ah sorry, got that wrong (with "____start" (instance (export "____start" (func 18)))) seems to parse ok. Now to work out how to reference that for the start ....

view this post on Zulip Scott Waye (Dec 12 2023 at 01:37):

Should I alias it again in the outer scope, something like

  (instance (;20;) (instantiate 0
      (with "____start" (instance (export "____start" (func 18))))
    )
  )
  (alias export 20 "____start" (func))
  (start $____start)

(this doesn't parse, btw, I'm just trying things :-)

view this post on Zulip Scott Waye (Dec 12 2023 at 02:25):

maybe I should be asking a more fundamental question, if a component has a start section, does it need to be exposed all the way up through the composition, or should the host call start functions whatever level they are at?

view this post on Zulip Alex Crichton (Dec 12 2023 at 15:04):

The start section can appear anywhere in a component, but I should probably also confirm that you're aware that this is (or at least should be) a gated feature and is largely unimplemented in Wasmtime/tooling.

view this post on Zulip Scott Waye (Dec 12 2023 at 15:05):

Right, but I'm running out of ideas of how to solve this. One of the ideas I have left is to fill out the implementations for start at least for functions without values

view this post on Zulip Notification Bot (Dec 12 2023 at 15:06):

A message was moved here from #wasmtime > compontent model wasm -> core wasm by Alex Crichton.

view this post on Zulip Alex Crichton (Dec 12 2023 at 15:07):

If you require the component-model start function to work it won't be easy and I'd recommend trying to avoid it. It's got some pretty fundamental design questions associated with it so it's not as simple as just implementing a few unimplemented!() blocks in Wasmtime

view this post on Zulip Scott Waye (Dec 12 2023 at 15:15):

Thanks, ok point taken. I can probably disable getting all the environment variables from dotnet and then Wasi libc should lazy load. That might be acceptable upstream as long as it is temporary.

view this post on Zulip Scott Waye (Dec 12 2023 at 15:16):

I mean make https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariables?view=net-8.0 throw a PlatformNotSupportedException for Wasm/Wasi

Retrieves all environment variable names and their values.

view this post on Zulip Notification Bot (Dec 13 2023 at 13:04):

Scott Waye has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC