Skip to content

Migrate platform to the new Zig-based Roc compiler#163

Draft
lukewilliamboswell wants to merge 28 commits into
mainfrom
migrate-zig-compiler
Draft

Migrate platform to the new Zig-based Roc compiler#163
lukewilliamboswell wants to merge 28 commits into
mainfrom
migrate-zig-compiler

Conversation

@lukewilliamboswell

@lukewilliamboswell lukewilliamboswell commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

WIP

lukewilliamboswell and others added 2 commits June 26, 2026 17:25
Port basic-webserver from the old Rust-based Roc compiler to the new
Zig-based compiler and its direct-symbol host ABI.

Platform & ABI:
- Rewrite platform/main.roc to the new header: stateful
  `requires { [Model : model] for program { init!, respond! } }`,
  `provides { roc_init_for_host, roc_respond_for_host }`, a `hosted {}`
  block, and a per-target `targets {}` block.
- Generate and commit the Rust glue (src/roc_platform_abi.rs) via
  ci/regenerate_glue.sh.

Host:
- Collapse the 3-crate workspace into a single `staticlib` crate. src/lib.rs
  implements the Roc allocator/handler symbols and every hosted_* effect
  (stdio, file, env, dir, cmd, path, utc); src/http_server.rs runs the
  tokio/hyper loop, calling roc_init_for_host once and roc_respond_for_host
  per request (model boxed with a constant refcount, shared across threads).

Modules & examples:
- Port core modules (Stdout, Stderr, IOErr, File, Env, Dir, Cmd, Path, Utc,
  Http, InternalHttp) and 11 examples + 4 tests to the new syntax.
- Defer rich modules/examples/tests (Sqlite, Tcp, Url, MultipartFormData,
  outbound Http.send!, buffered File reader) to a `.todoroc` extension.

Build & CI:
- Add build.sh (per-target libhost) and commit the musl link inputs.
- Rewrite ci/all_tests.sh and ci.yml to use roc-lang/setup-roc
  (nightly-new-compiler) and remove all legacy old-compiler tooling
  (nix flake, sync-check/release workflows, expect scripts).

Note: the init exit code uses I64 to work around a glue size-assertion bug
for `Try(Box(_), I32)` on stock roc.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The pinned action SHA predated nightly-new-compiler support (only knew
nightly/alpha3/alpha4). Bump to current main.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lukewilliamboswell added a commit to lukewilliamboswell/roc-awesome that referenced this pull request Jun 26, 2026
Graduate basic-webserver from LEGACY into the README Platforms list,
marked 🚧 with a link to roc-lang/basic-webserver#163.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lukewilliamboswell and others added 26 commits June 26, 2026 17:44
Port Sqlite + InternalSqlite from basic-cli (Roc API + the 6 hosted host
functions: prepare/bind/columns/column_value/step/reset), with the opaque
boxed Stmt handle and a thread-local connection cache. Add the
libsqlite3-sys (bundled) dependency, wire the sqlite hosted entries into
platform/main.roc (kept last in the hosted block), regenerate the glue, and
port examples/sqlite.roc.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Port the URL and multipart/form-data helpers (and the SplitList helper they
use) to the new compiler syntax. These are pure Roc (no host functions), so
the generated glue is unchanged. Expose Url and MultipartFormData, port
tests/url.roc and examples/form-url-encoded.roc.

form-file-upload and todos remain deferred (external Base64 package download
fails / large Sqlite app respectively).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Port the deferred `Tcp` module and outbound `Http.send!`/`Http.get_utf8!`
from the old roc_http crate to the direct-symbol host ABI, mirroring the
basic-cli `explore-http` reference.

Platform (Roc):
- Add platform/Tcp.roc (opaque `Stream : Box(U64)` over a host-side
  BufReader<TcpStream>; connect/read_up_to/read_exactly/read_until/write).
- Extend platform/Http.roc with the `host_send_request!` effect plus
  `send!`/`get_utf8!`, reusing InternalHttp's to/from-host converters.
- Expose + import Tcp in platform/main.roc and append the six tcp/http
  hosted entries after sqlite (keeps existing glue numbering stable above).
- Regenerate src/roc_platform_abi.rs; refresh the renumbered boundary and
  sqlite type aliases in src/lib.rs.

Host (Rust):
- Implement hosted_tcp_* (refcounted stream box, ErrorKind->Str mapping,
  BufRead read_until) and hosted_http_send_request (hyper + hyper-rustls
  over a thread-local current-thread runtime, run on the spawn_blocking
  thread; transport failures mapped to reserved status+body sentinels).
- Cargo: add hyper-rustls (ring), hyper-util client features; pin
  zeroize 1.8.2 so the lockfile builds on the stable toolchain.

Examples/tests:
- Un-defer examples/http.roc, examples/error-handling.roc, tests/tcp.roc
  (ported to new syntax).

Validated: musl host build (ring + sqlite + new code), `roc build` of all
examples/tests, and the hello-web smoke test (GET / -> 200).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant