WebAssembly / WASI

WebAssembly System Interface
Other
4.72k stars 240 forks source link

What module will _start, args, env, and pre-opens be defined in? #508

Closed codefromthecrypt closed 3 months ago

codefromthecrypt commented 1 year ago

I noticed here, several wasi modules being clarified. However, it seems there's not enough defined to actually bootstrap a wasi command. Notably, we're missing definition of the _start function, memory (basically nothing works without it), how to enumerate pre-opens and how to get args and env. Are you thinking a "wasi-bootstrap" all in, or micro modules like wasi-env?

codefromthecrypt commented 1 year ago

It seems maybe it is this, but looks abandoned? e.g. it isn't defined in the new format and untouched recently cc @sunfishcode https://github.com/WebAssembly/wasi-classic-command/blob/main/standard/classic-command/docs.md

SamuraiCrow commented 1 year ago

However, it seems there's not enough defined to actually bootstrap a wasi command.

I'm also curious because WAsm2C and the third-party W2C2 each require that the main function be already be written in C independently from the generated code. This is undesirable in the long term.

I was thinking of replacing the C backend of W2C2 or WAsm2C with calls to LibGCCJIT for more parallel building without the need for back-to-back source generation and immediate reparsing.

SamuraiCrow commented 1 year ago

Does #509 relate to or answer this question?

codefromthecrypt commented 1 year ago

@SamuraiCrow it relates, though it is indirect. For example a "command function" would indeed read things like pre-opens, but pre-opens themselves currently are functions (stat and name). It is still murky to me how this stitches together, particularly how you map snapshot01 to this. I'll try to follow along and thanks for the hint.

sunfishcode commented 1 year ago

The preview1 _start function as used in preview1 is documented here. It has no arguments, and preview1 has functions for retrieving arguments and environment variables.

509 is for preview2, which is expected to have an entrypoint function that has arguments for command-line arguments and environment variables.

sunfishcode commented 1 year ago

I also filed https://github.com/WebAssembly/WASI/pull/510 which hopefully makes the preview1 docs a little easier to navigate. It removes the old "phases", "snapshot", and "ephemeral" terminology, and just calls things "preview0" and "preview1", which are the terminology we tend to refer to them by now.

sunfishcode commented 3 months ago

As commented above, WASIp1 is documented here, and the equivalents in WASIp2 are defined here.