Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More non-trivial examples #1848

Open
james-lawrence opened this issue Nov 25, 2023 · 4 comments
Open

More non-trivial examples #1848

james-lawrence opened this issue Nov 25, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@james-lawrence
Copy link

james-lawrence commented Nov 25, 2023

most of the examples currently are either) specific to the compiler (tinygo, rust, zig) and don't work with golang 1.21 or are so trivial to be essentially useless (add).

add examples that show the following:

  • returning dynamically sized bytes/strings from a host function.
  • sending/returning arrays of strings and bytes.
  • returning multiple of the above.
  • reading/writing files (file created by guest, written to from host and the reverse)

currently its hard to mplement dynamic data from the host and none of it is well documented. only successful method I'd managed so far is to pre-allocate a buffer in the guest and use that which sucks since it needs to be sized large enough to hold any possible return data.

reading/writing files are not documented and don't work via the FD.

having working examples of these would ensure that at least normal usage of wazero is documented and working.

@james-lawrence james-lawrence added the enhancement New feature or request label Nov 25, 2023
@ncruces
Copy link
Collaborator

ncruces commented Nov 25, 2023

only successful method I'd managed so far is to pre-allocate a buffer in the guest and use that which sucks since it needs to be sized large enough to hold any possible return data.

This really depends on your guest environment, which is why good samples are hard to come by.

But generally, guests manage linear memory, so you need to export a function that allocates memory on demand, and have the host call it. If your guest can't export a function (like Go wasip1) that's really a guest limitation; there's no getting around that.

@james-lawrence
Copy link
Author

@ncruces has wazero brought this to the attention of golang's implementation of wasip1? (note: golang potential limitation here isn't really relevant to the overall lack of good example code it doesn't exist for tinygo/rust/zig etc)

@ncruces
Copy link
Collaborator

ncruces commented Nov 25, 2023

The Go team is aware of this limitation; the semantics are complicated.

W.r.t. samples in other languages, this is precisely what the allocation examples want to convey.

The WASM ABI forces you to design a C like API, where you have to decide things like who allocs memory (the caller/callee). A well designed C API is “easy” to wrap. If you want a more streamlined experience, something like go-plugin may be what you're after.

Having said that, we can always improve documentation and examples; I'd argue that this is precisely the kind of area where new contributors can help the most.

@james-lawrence
Copy link
Author

james-lawrence commented Dec 1, 2023

@ncruces add an example for golang proper. I have no issues with exposing an allocation function. im asserting that the examples in this repo are very trivial or make assumptions based on the compiler. the allocations are just one tiny bit and hand waves everthing else is based on that. so have good examples for intended usage that isn't trivial is important.

feel free to ignore the issue i'm just asserting the pain points of getting started and having to reverse engineer the expectations. even when looking at the examples.

edit: the big issue is when using golang's compiler is i'm unsure if what I'm thinking of exposing is safe to do or if it'll interfere with assumptions by the gc. this means people have to spend a ton of time investigating whats say or take less than ideal approaches.

and the allocation doesn't resolve the FD issues I ran into due to lack of examples etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants