Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions frameworks/nilo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# nilo — a toolkit for Zig 0.16 whose largest module is an HTTP server on
# nilo, a toolkit for Zig 0.17 whose largest module is an HTTP server on
# zio fibers. One static binary, built from the commit `build.zig.zon` pins.

FROM alpine:3.20 AS build
ARG TARGETARCH
ARG ZIG_VERSION=0.16.0
ARG ZIG_VERSION=0.17.0
RUN apk add --no-cache ca-certificates curl git tar xz

# The official toolchain, for the arch Buildx is building.
Expand All @@ -22,9 +22,11 @@ WORKDIR /server
COPY build.zig build.zig.zon ./
COPY src ./src

# nilo and its one dependency (zio) come from the pin in build.zig.zon; the
# Postgres driver behind nilo_sql is fetched because build.zig asks for it.
# Static against musl, so the runtime image needs nothing.
# nilo comes from the pin in build.zig.zon, and zio from nilo's. build.zig asks nilo for
# four flags, and each fetches what it needs: the Postgres and SQLite drivers
# behind nilo_sql, tls.zig for the TLS listeners, libdeflate for gzip. HTTP/2
# and gRPC (`http2`) fetch nothing. Static against musl, so the runtime image
# needs nothing.
RUN set -eu; \
case "${TARGETARCH:-amd64}" in \
# `+aes+pclmul` is not decoration. Zig's `x86_64_v3` level carries
Expand All @@ -44,5 +46,5 @@ RUN set -eu; \

FROM alpine:3.20
COPY --from=build /server/zig-out/bin/nilo-arena /nilo-arena
EXPOSE 8080 8081
EXPOSE 8080 8081 8082 8443
ENTRYPOINT ["/nilo-arena"]
26 changes: 22 additions & 4 deletions frameworks/nilo/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// `.tls = true` is what makes the TLS listener on 8081 exist at all: the
// Four flags, each of which keeps its dependency out of a build that does
// not ask:
//
// `.tls = true` makes the TLS listeners on 8081 and 8443 exist at all: the
// library behind it is fetched and linked only for a dependent that asks
// (ADR 0288), and a build without it refuses `.tls` at `listen()` rather
// (ADR 212), and a build without it refuses `.tls` at `listen()` rather
// than serving cleartext on a port the entry believed was encrypted.
const nilo = b.dependency("nilo", .{ .target = target, .optimize = optimize, .sql = true, .tls = true });
//
// `.http2 = true` builds HTTP/2 and gRPC into the one server (ADR 259,
// ADR 220): a plain listener tells h2c from HTTP/1.1 by the first bytes,
// and a TLS one offers `h2` and `http/1.1` by ALPN. It brings no
// dependency, only code.
//
// `.libdeflate = true` makes `app.compress` gzip with libdeflate instead of
// `std.flate` (ADR 248), which is what `json-comp` spends its time on.
const nilo = b.dependency("nilo", .{
.target = target,
.optimize = optimize,
.sql = true,
.tls = true,
.http2 = true,
.libdeflate = true,
});

const exe = b.addExecutable(.{
.name = "nilo-arena",
Expand All @@ -24,7 +42,7 @@ pub fn build(b: *std.Build) void {
// A release build strips, the way nilo's own measured binaries
// do: a panic still names the request (`nilo.panic`), and the
// board never opens a debugger.
.strip = optimize != .Debug,
.strip = optimize != .debug,
.imports = &.{
.{ .name = "nilo_http", .module = nilo.module("nilo_http") },
.{ .name = "nilo_sql", .module = nilo.module("nilo_sql") },
Expand Down
6 changes: 3 additions & 3 deletions frameworks/nilo/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.{
.name = .nilo_arena,
.version = "0.0.0",
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.0",
.fingerprint = 0x31b5705688860733,
.dependencies = .{
// Pinned to a commit, not a branch, so the build the board ran is
// the build the row describes. Move both lines together:
// zig fetch --save=nilo git+https://github.com/nevindra/nilo#<commit>
.nilo = .{
.url = "git+https://github.com/nevindra/nilo#224a507209b9d4d66f8d6e90406d00a394d14656",
.hash = "nilo-0.5.0-5HEqwlFaWQCQKkgQTyL_cehVbhjE2VRsdMlX2g2i2H38",
.url = "git+https://github.com/nevindra/nilo?ref=v0.8.0#d3ab2f33bbb8fc2281605c33a12fe3619c63f42d",
.hash = "nilo-0.8.0-5HEqwq58ogBz1MCJR4WuM7uGdb0PznnQgoANOdGFRbPx",
},
},
.paths = .{ "build.zig", "build.zig.zon", "src" },
Expand Down
10 changes: 8 additions & 2 deletions frameworks/nilo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": true,
"response": true
},
"description": "A toolkit for Zig 0.16 whose largest module is an HTTP/1.1 server on zio fibers (io_uring, epoll, kqueue). A plain function is a route: its argument list is the routing, the typed input, the 400 for anything that does not fit, and the OpenAPI document. One allocation per request, 4,669 bytes per idle connection, and a wait parks the fiber rather than the thread. Serves cleartext on 8080 and TLS 1.3 on 8081 from one process. Refuses HTTP/2, HTTP/3, gRPC and templates on the record, which is why it sits out those profiles.",
"description": "A toolkit for Zig 0.17 whose largest module is an HTTP server on zio fibers (io_uring, epoll, kqueue). A plain function is a route: its argument list is the routing, the typed input, the 400 for anything that does not fit, and the OpenAPI document. One allocation per request, 4,669 bytes per idle connection, and a wait parks the fiber rather than the thread. Serves HTTP/1.1 and h2c on 8080, TLS 1.3 on 8081, h2c on 8082 and HTTP/2 over TLS with ALPN on 8443 from one process. HTTP/2 and unary gRPC are behind the -Dhttp2 build flag, which this entry builds with; gRPC is unary only, so the streaming profiles are not subscribed. Refuses HTTP/3 and templates on the record, which is why it sits out those profiles.",
"repo": "https://github.com/nevindra/nilo",
"enabled": true,
"tests": [
Expand All @@ -27,7 +27,13 @@
"8gbit",
"echo-ws",
"echo-ws-pipeline",
"echo-ws-limited"
"echo-ws-limited",
"baseline-h2",
"static-h2",
"baseline-h2c",
"json-h2c",
"unary-grpc",
"unary-grpc-tls"
],
"maintainers": [
"nevindra"
Expand Down
Loading