-
Notifications
You must be signed in to change notification settings - Fork 37
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
Zig updates #271
Closed
Closed
Zig updates #271
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces `kits/zig/wws`, with the intention of replacing `kits/zig/worker`. The design of the new SDK improves upon the previous one by exposing utilities for parsing wws requests and serializing wws responses, to give the user more control over memory while still keeping the SDK easy to use. The name was changed to make it more ergonomic within the Zig ecosystem (the developer will pull in a `wws` dependency to interface with wws, rather than a `worker` dependency).
The dependency `zig-router` doesn't yet support the latest Zig. Once that library is updated, we can uncomment this example. `std.fs.Dir.openFileWasi` has been removed, so we can just use `std.fs.Dir.openFile`.
Oops, wrong repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: See previous discussion/code review in the PR from the archived repository: #264
Summary
This PR reworks the Zig SDK to provide more control to the user w.r.t. dynamic allocation (fixes #218) and also provides facilities to write the worker config directly from the Zig
build.zig
, so Zig developers can run e.g.zig build; wws zig-out root
and be up and running with wws in a matter of seconds.TODO
kits/zig/worker
) and new SDK (in my initial testing, the new method is way faster)Details
A summary of changes, so far:
examples/zig-examples
to ease maintenance of Zig example workers and also demonstrate composition of multiple wws workers in a single serverworker
towws
wws
module exposes some build-time functions to build a Zig worker and associated configwws
module exposes functions to read the request object from stdin (or any reader) and write the request object to stdout (or any writer)I believe these changes align with the goals of a worker:
Overall, with the new API surface, developing wws workers with Zig looks like this:
wws
as a dependencyconst worker = try wws.addWorker(...)
to build your Zig program as a WASM moduleworker.addToWriteFiles(b, write_files)
to copy the worker and its associated config to a WWS server directorysrc/main.zig
), usewws.parseStream(allocator, parse_config)
to decode the requestwws.Response
wws.writeResponse(response, writer)
to write the responseMinimal Zig worker now looks like this (click to expand)
To build/run the server:
Outstanding questions:
build.zig
to the root of this repository, but that may be confusing.