Add plain WAT Wasm curl clone with WASI 0.2 and portable wasm2c native target #1

Closed
nandi wants to merge 0 commits from geordi/c1a2724f into main
pull from: geordi/c1a2724f
Owner

Summary

Implements a curl clone directly in plain WebAssembly Text format (curl.wat) targeting the WASI 0.2 Component Model, together with build/test tooling and a portable wasm2c native compilation target.

Why & What Changed

  • Plain WAT WASI 0.2 curl clone (curl.wat, curl-wasm, Makefile):
    • Hand-written pure WebAssembly Text component targeting wasi:cli/*@0.2.0, wasi:io/*@0.2.0, wasi:clocks/monotonic-clock@0.2.0, wasi:filesystem/*@0.2.0, and wasi:http/*@0.2.0 (assembles with wasm-tools parse and runs on wasmtime with real HTTP/HTTPS).
    • Supports -X, -H (add/override/suppress Name:/empty Name;), -d/--data-* (@file, @-, --data-raw, --data-binary, --data-urlencode), -G, -T (PUT file/stdin), -i, -I, -L/--max-redirs (RFC 9110 method/body handling, relative/dot-segment resolution, cross-origin auth/cookie stripping), -o/-O/-D, -s/-S/-v/-f, -u/userinfo Basic Auth, -A/-e/-b/-r, --connect-timeout/-m, and -w format variables.
  • Workflow & Portable Native wasm2c Target (justfile, native/extract_core.py, native/build_native.py, native/wasi_host.c):
    • Added justfile with build, test, run, clean, plus native, test-native, and run-native recipes (set positional-arguments).
    • native/extract_core.py extracts the embedded core modules from curl.wasm, and native/build_native.py discovers WABT's wasm2c runtime across system/Homebrew/Pixi/Conda installations (including Pixi trampoline_configuration/wasm2c.json) and automatically fetches version-matched runtime files from WebAssembly/wabt into build/wasm2c-rt-<ver>/ if a binary-only package omitted them (or honors WASM2C_RUNTIME_DIR).
    • Links cleanly with native/wasi_host.c (POSIX + OpenSSL, with _DARWIN_C_SOURCE/_POSIX_C_SOURCE guards and Conda/Pixi OpenSSL/rpath discovery) into ./curl-native without modifying curl.wat.
  • Tests & Docs (tests/test_curl.py, README.md, .gitignore):
    • 27 integration tests (local HTTP servers + live HTTPS smoke test against https://example.com), runnable against both wasmtime (just test) and ./curl-native (just test-native).

Verification

  • just clean && just native (auto-discovered /usr/src/wasm2c) and explicit WASM2C_RUNTIME_DIR with fetched WABT 1.0.36 runtime files: built native ELF x86-64 ./curl-native cleanly.
  • Mock Pixi trampoline_configuration/wasm2c.json prefix resolution verified.
  • just test-native: 27 passed, 0 failed.
  • just test: 27 passed, 0 failed.
## Summary Implements a `curl` clone directly in plain WebAssembly Text format (`curl.wat`) targeting the WASI 0.2 Component Model, together with build/test tooling and a portable `wasm2c` native compilation target. ### Why & What Changed - **Plain WAT WASI 0.2 `curl` clone (`curl.wat`, `curl-wasm`, `Makefile`)**: - Hand-written pure WebAssembly Text component targeting `wasi:cli/*@0.2.0`, `wasi:io/*@0.2.0`, `wasi:clocks/monotonic-clock@0.2.0`, `wasi:filesystem/*@0.2.0`, and `wasi:http/*@0.2.0` (assembles with `wasm-tools parse` and runs on `wasmtime` with real HTTP/HTTPS). - Supports `-X`, `-H` (add/override/suppress `Name:`/empty `Name;`), `-d`/`--data-*` (`@file`, `@-`, `--data-raw`, `--data-binary`, `--data-urlencode`), `-G`, `-T` (`PUT` file/stdin), `-i`, `-I`, `-L`/`--max-redirs` (RFC 9110 method/body handling, relative/dot-segment resolution, cross-origin auth/cookie stripping), `-o`/`-O`/`-D`, `-s`/`-S`/`-v`/`-f`, `-u`/userinfo Basic Auth, `-A`/`-e`/`-b`/`-r`, `--connect-timeout`/`-m`, and `-w` format variables. - **Workflow & Portable Native `wasm2c` Target (`justfile`, `native/extract_core.py`, `native/build_native.py`, `native/wasi_host.c`)**: - Added `justfile` with `build`, `test`, `run`, `clean`, plus `native`, `test-native`, and `run-native` recipes (`set positional-arguments`). - `native/extract_core.py` extracts the embedded core modules from `curl.wasm`, and `native/build_native.py` discovers WABT's `wasm2c` runtime across system/Homebrew/Pixi/Conda installations (including Pixi `trampoline_configuration/wasm2c.json`) and automatically fetches version-matched runtime files from `WebAssembly/wabt` into `build/wasm2c-rt-<ver>/` if a binary-only package omitted them (or honors `WASM2C_RUNTIME_DIR`). - Links cleanly with `native/wasi_host.c` (POSIX + OpenSSL, with `_DARWIN_C_SOURCE`/`_POSIX_C_SOURCE` guards and Conda/Pixi OpenSSL/rpath discovery) into `./curl-native` without modifying `curl.wat`. - **Tests & Docs (`tests/test_curl.py`, `README.md`, `.gitignore`)**: - 27 integration tests (local HTTP servers + live HTTPS smoke test against `https://example.com`), runnable against both `wasmtime` (`just test`) and `./curl-native` (`just test-native`). ## Verification - `just clean && just native` (auto-discovered `/usr/src/wasm2c`) and explicit `WASM2C_RUNTIME_DIR` with fetched WABT 1.0.36 runtime files: built native ELF x86-64 `./curl-native` cleanly. - Mock Pixi `trampoline_configuration/wasm2c.json` prefix resolution verified. - `just test-native`: `27 passed, 0 failed`. - `just test`: `27 passed, 0 failed`.
nandi added 3 commits 2026-11-20 00:07:58 +00:00
Implement a curl clone directly in plain WebAssembly Text format (curl.wat) targeting WASI 0.2 (wasi:cli, wasi:io, wasi:clocks, wasi:filesystem, wasi:http). Includes the executable curl-wasm wrapper script, Makefile, integration test suite (tests/test_curl.py), README.md, and .gitignore.
Add native/extract_core.py to extract embedded core Wasm modules from curl.wasm and native/wasi_host.c providing a POSIX/OpenSSL WASI 0.2 host shim for wasm2c. Add native, test-native, and run-native recipes to justfile (with positional-arguments enabled), support CURL_WASM_NATIVE in tests/test_curl.py, ignore build artifacts in .gitignore, and document native compilation in README.md.
nandi added 1 commit 2026-11-20 00:22:23 +00:00
Add native/build_native.py to auto-discover WABT's wasm2c runtime headers and sources (wasm-rt.h, wasm-rt-*.c, and .inc files, with WASM2C_RUNTIME_DIR override) and OpenSSL flags across Linux distros and macOS, instead of assuming /usr/include/wasm-rt.h and -lwasm-rt-impl. Guard _DARWIN_C_SOURCE vs _POSIX_C_SOURCE in native/wasi_host.c, delegate just native to native/build_native.py, and document WASM2C_RUNTIME_DIR in README.md.
nandi changed title from Add plain WAT Wasm curl clone with WASI 0.2 and wasm2c native target to Add plain WAT Wasm curl clone with WASI 0.2 and portable wasm2c native target 2026-11-20 00:22:45 +00:00
nandi added 1 commit 2026-11-20 00:28:26 +00:00
Resolve Pixi trampoline_configuration/wasm2c.json and Conda/Pixi env prefixes in native/build_native.py, add automatic version-matched runtime download from WebAssembly/wabt into build/wasm2c-rt-<ver>/ when binary-only packages (such as conda-forge wabt) omit wasm-rt.h/wasm-rt-impl.c, search Conda/Pixi prefixes for OpenSSL with rpath, and update README.md.
nandi closed this pull request 2026-11-22 01:48:25 +00:00
nandi deleted branch geordi/c1a2724f 2026-11-22 01:48:25 +00:00

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: geordi/curl-wasm#1