Skip to content

Conversation

@ringtailsoftware
Copy link

I'm not sure whether this is useful to others, but offering a PR just in case.
I've added a pure Zig static webserver to serve files generated by the wasm examples, including an index.html with a list to pick from, rather than relying on emrun.py to serve a single example.

…ttpFileServer) rather than rely on emrun.py

Generates an index.html with links to all built samples
@floooh
Copy link
Owner

floooh commented Nov 7, 2025

Heh, nice. I wonder if we should merge this:

zig build examples -Dtarget=wasm32-emscripten && zig build serve -- zig-out/web -p 8000

...into an 'all-in-one-step' like this (couldn't come up with a better step-name)...

zig build serve-wasm

E.g. this would build the examples for wasm32-emscripten and the web server for the host platform and then run server with zig-out/web -p 8000...

@floooh floooh self-assigned this Nov 7, 2025
@floooh floooh added this to sokol todo Nov 7, 2025
@floooh floooh moved this to Review in sokol todo Nov 7, 2025
…ds all wasm examples and serves on localhost:8000
@floooh
Copy link
Owner

floooh commented Nov 7, 2025

Oki thanks! It might take a few days until I get around to merging, most likely Monday.

@floooh
Copy link
Owner

floooh commented Nov 10, 2025

There seems to be some chicken-egg-situation now when running zig run serve-wasm where the output directories don't exist yet when the web server is trying to start:

unable to open directory 'zig-out/web': FileNotFound
serve-wasm
└─ run exe serve failure
error: the following command exited with error code 1:
./.zig-cache/o/32ecab056c7c68975b793aee9d22d5da/serve zig-out/web -p 8000

...maybe a missing dependency between building the examples and starting the web server?

…les, then serve using native web server.

This would potentially allow for a different target for the examples, so makes sense - though a longer command.
@ringtailsoftware
Copy link
Author

I've split things up, so that the main -Dtarget= controls the target for the examples, but the web server is always built for the host target.

zig build -Dtarget=wasm32-emscripten serve-wasm is a bit wordier, but makes sense as it would allow web serving of a different target too.

@floooh
Copy link
Owner

floooh commented Nov 13, 2025

Oki doki, I'll give it another whirl 'soon-ish' (not today though).

@floooh
Copy link
Owner

floooh commented Nov 14, 2025

Hmm I still see a weird problem. All the sample links get a 404.

Here's what I do (on macOS):

> rm -rf zig-out .zig-cache
> zig build -Dtarget=wasm32-emscripten serve-wasm
Listening at http://127.0.0.1:8000/

...click on the link so the browser opens, and I see the list of samples.

But clicking on any of the links produces a 404 and instead of the sample I see the index.html webpage again:

image

Looking into zig-out/web the sample files are definitely there though.

When I do zig build -Dtarget=wasm32-emscripten serve-wasm a second time it works as expected though...

Not sure what's going on there though, skimming over the code the step-dependencies look correct to me...

Can you reproduce what I'm seeing?

@ringtailsoftware
Copy link
Author

Building the examples and serve-wasm targets works for me.
Apologies for the multiple attempts at this. If it's still a problem, feel free to close the PR.
zig build -Dtarget=wasm32-emscripten examples serve-wasm

@floooh
Copy link
Owner

floooh commented Nov 15, 2025

Hmm same problem also when running zig build -Dtarget=wasm32-emscripten examples serve-wasm, I'll keep the PR open, maybe I'll get around at a later time to investigate the issue. In general I like the idea of a 'table-of-content' page for the web samples, I'm just not sure yet about the added build complexity and the additional dependency.

In general I'd like to move some things out of the sokol-zig project because the actual bindings would not require the emsdk and sokol-shdc dependencies, but I think the only realistic way is to move the examples into a separate build.zig and build.zig.zon, maybe even a separate github repo... but I haven't made up my mind yet :)

@floooh floooh moved this from Review to Parked in sokol todo Nov 15, 2025
robboito added a commit to robboito/sokol-zig that referenced this pull request Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Parked

Development

Successfully merging this pull request may close these issues.

2 participants