Skip to content

x/wasihttp: add wasihttp package #305

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Mossaka
Copy link
Member

@Mossaka Mossaka commented Mar 13, 2025

This commit ports the wasihttp package from the wasi-http-go repository to here under the x/wasihttp directory. The wasihttp package provides a WASI HTTP server and client implementation using Go net/http package.

The ./x/wasihttp/internal directory is regenerated using make go-bindings command from the wasihttp Makefile. Examples can be found in the x/wasihttp/examples directory and can be run under the ./x/wasihttp working directory.

This new package has its own CHANGELOG.md, README.md, and RELEASE.md files to document the changes, usage, and release notes.

Signed-off-by: Jiaxiao Zhou [email protected]

@Mossaka Mossaka requested a review from ydnar as a code owner March 13, 2025 22:06
@ydnar
Copy link
Collaborator

ydnar commented Mar 13, 2025

Can we have this share WIT files with the files in testdata?

@ydnar
Copy link
Collaborator

ydnar commented Mar 13, 2025

Should this have its own go.mod file if it has its own CHANGELOG?

@Mossaka
Copy link
Member Author

Mossaka commented Mar 13, 2025

@ydnar I thought testdata is for testing purposes With that said, why do you want to share the WIT files in x/wasihttp with testdata?

@LiamRandall
Copy link

Nice work on this one @Mossaka!

@ydnar
Copy link
Collaborator

ydnar commented Mar 14, 2025

This PR highlights a bug (or a feature, depending on how you look at it) of wit-bindgen-go that I think we should address before merging: unnecessary, duplicative code generation.

TinyGo’s stdlib already includes the generated bindings for wasi:cli/command. The only reason they’re generated again is because the proxy WIT includes wasi:cli/command. Package wasihttp does not need the full CLI world, except for testing, and does not import the generated code.

I’d like to propose a feature for wit-bindgen-go to limit the generated code to a specific WIT package (or world or interface), so the generated bindings in x/wasihttp/internal are more narrowly scoped to what’s necessary to implement wasi-http.

@elewis787
Copy link

This PR highlights a bug (or a feature, depending on how you look at it) of wit-bindgen-go that I think we should address before merging: unnecessary, duplicative code generation.

TinyGo’s stdlib already includes the generated bindings for wasi:cli/command. The only reason they’re generated again is because the proxy WIT includes wasi:cli/command. Package wasihttp does not need the full CLI world, except for testing, and does not import the generated code.

I’d like to propose a feature for wit-bindgen-go to limit the generated code to a specific WIT package (or world or interface), so the generated bindings in x/wasihttp/internal are more narrowly scoped to what’s necessary to implement wasi-http.

@ydnar I am interested in following along on this.

I would add that when developing libraries that intend to wrap imports and exports off shared interfaces, there are also conflicts in generating code. This is not directly related, but it is something I've been attempting to resolve. Happy to write a separate issue for this explaining what I think is the conflict.

Mossaka added 4 commits March 19, 2025 20:46
This commit ports the wasihttp package from the [wasi-http-go](https://github.com/ydnar/wasi-http-go)
repository to here under the `x/wasihttp` directory. The wasihttp package provides a
WASI HTTP server and client implementation using Go net/http package.

The ./x/wasihttp/internal directory is regenerated using `make go-bindings` command
from the wasihttp Makefile. Examples can be found in the `x/wasihttp/examples` directory and
can be run under the ./x/wasihttp working directory.

This new package has its own CHANGELOG.md, README.md, and RELEASE.md files to document
the changes, usage, and release notes.

Signed-off-by: Jiaxiao Zhou <[email protected]>
- also update go.work to include the new package
- slice the proxy.wit to only include the necessary imports
- re-generate the bindings

Signed-off-by: Jiaxiao Zhou <[email protected]>
and update the examples docs to refer to the right working directory and
command to build.

Signed-off-by: Jiaxiao Zhou <[email protected]>
@Mossaka
Copy link
Member Author

Mossaka commented Mar 20, 2025

I’d like to propose a feature for wit-bindgen-go to limit the generated code to a specific WIT package (or world or interface), so the generated bindings in x/wasihttp/internal are more narrowly scoped to what’s necessary to implement wasi-http.

Sounds good to me. I've limited the generated code to this specific WIT world:

world proxy {
	import wasi:clocks/monotonic-clock@0.2.0;
	import wasi:io/streams@0.2.0;
	import wasi:io/error@0.2.0;
	import wasi:io/poll@0.2.0;

	import wasi:http/types@0.2.0;
	import wasi:http/outgoing-handler@0.2.0;
	export wasi:http/incoming-handler@0.2.0;
}

it's much more narrowly scoped than before and wasi:clocks and wasi:io are the only necessary packages that wasi:http/types interface depends on.

@Mossaka
Copy link
Member Author

Mossaka commented Apr 12, 2025

@ydnar please take a look and let me know your thoughts on how to proceed with this PR

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

Successfully merging this pull request may close these issues.

4 participants