zigzap / zap Goto Github PK
View Code? Open in Web Editor NEWblazingly fast backends in zig
License: MIT License
blazingly fast backends in zig
License: MIT License
I see different benchmarks for Rust, Go and Python.
Golang use default http library that asynchronous.
Python use synchronous way.
Rust use sockets, because this language doesn't have http server in standard library.
I think such benchmarks aren't only useful, but also harmful, because they confuse people.
In the latest version of ziglang, build.zig.zon requires path field to be decalred.
akhil@ad:~/practice/immich$ zig fetch --save https://github.com/zigzap/zap/tarball/master
/home/akhil/.cache/zig/tmp/fa6da82352a5a36d/build.zig.zon:1:2: error: missing top-level 'paths' field
.{
^
Zig version:
0.11.0
Machine:
Windows 11
Steps:
$ git clone https://github.com/zigzap/zap.git
$ cd zap
$ zig build run-hello
Truncated output:
zig build-lib facil.io Debug native: error: the following command failed with 15 compilation errors:
C:\Users\mhlun\zig-x64-true-11\zig.exe build-lib -cflags -Wno-return-type-c-linkage -fno-sanitize=undefined -DFIO_HTTP_EXACT_LOGGING -- C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fio.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fio_zig.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\http.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\http1.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\websockets.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\http_internal.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_numbers.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fio_siphash.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_str.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_ary.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_data.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_hash.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_json.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobject.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_mustache.c C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\cli\fio_cli.c -lc --cache-dir C:\Users\mhlun\fun\sys\zig\backend\zap\zig-cache --global-cache-dir C:\Users\mhlun\AppData\Local\zig --name facil.io -static -I C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io -I C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil -I C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj -I C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\cli -I C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http -I C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\parsers --listen=-
Build Summary: 0/4 steps succeeded; 1 failed (disable with --summary none)
run-hello transitive failure
└─ run hello transitive failure
└─ zig build-exe hello Debug native transitive failure
└─ zig build-lib facil.io Debug native 15 errors
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\http1.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\websockets.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_hash.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_mustache.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_json.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_ary.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\http.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fio_zig.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobject.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\cli\fio_cli.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_data.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fio.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_str.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\fiobj\fiobj_numbers.c:1:1: error: unable to build C object: clang exited with code 1
C:\Users\mhlun\fun\sys\zig\backend\zap\facil.io\lib\facil\http\http_internal.c:1:1: error: unable to build C object: clang exited with code 1
I wish i could be more helpful but i genuinely don't know what's going on
RequestHandler
creates a closure over the passed in parameters by defining a new type and assigning to decls in that type. This partially works because Zig creates a new instantiation of the function for each different type passed as the anytype
argument. However, when the function has already been instantiated for the type passed, the type declaration inside the function is re-used, and the decls get overwritten. This affects the simple_router
example in the repo, where /geta
, /getb
, and /inca
all share the same self
type and thus share the same request handler.
zap.Router
will have to find another way to pass the self
argument to the routing functions.
I'm considering using zap for my next project, so I was wondering if it can do hot reloading out of the box.
Just simple zig build file that we can build an app on top of like the starter file which we could get zap on a fly for my project
Hey, I'd like to bring this up for discussion at least.
I didn't even really know any of this myself until fiddling with it last night, but users of zap could pass the -Dopenssl flag to the zap build from their own build.zig via the following:
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = true,
});
I find this approach much more simple than having to pass in the environment variable each time I want to build my own project (or by setting it some other way and having that be a pre-setup step to building my project).
I'd at least like the -Dopenssl flag still so I can continue to do this, but only because I find this solution rather elegant.
Hello,
I am trying to see how many concurrent requests can be served by Zap at a time and conducted the following test. However I am receiving connection reset by peer errors on the load generation tool. I am using hey
(https://github.com/rakyll/hey) as the load generation tool. I followed the following steps:
build.zig
and build.zig.zon
files.const std = @import("std");
const zap = @import("zap");
const User = struct {
first_name: ?[]const u8 = null,
last_name: ?[]const u8 = null,
};
fn on_request(r: zap.Request) void {
if (r.methodAsEnum() != .GET) return;
// /user/n
if (r.path) |the_path| {
if (the_path.len < 7 or !std.mem.startsWith(u8, the_path, "/user/"))
return;
const user_id: usize = @as(usize, @intCast(the_path[6] - 0x30));
const user = users.get(user_id);
var buf: [100]u8 = undefined;
var json_to_send: []const u8 = undefined;
if (zap.stringifyBuf(&buf, user, .{})) |json| {
json_to_send = json;
} else {
json_to_send = "null";
}
//std.debug.print("<< json: {s}\n", .{json_to_send}); // turn off debugging for now
r.setContentType(.JSON) catch return;
r.setContentTypeFromFilename("test.json") catch return;
r.sendBody(json_to_send) catch return;
}
}
const UserMap = std.AutoHashMap(usize, User);
var users: UserMap = undefined;
fn setupUserData(a: std.mem.Allocator) !void {
users = UserMap.init(a);
try users.put(1, .{ .first_name = "renerocksai" });
try users.put(2, .{ .first_name = "Your", .last_name = "Mom" });
}
pub fn main() !void {
const a = std.heap.page_allocator;
try setupUserData(a);
var listener = zap.HttpListener.init(.{
.port = 3000,
.on_request = on_request,
.log = false,
.max_clients = 100000,
});
try listener.listen();
std.debug.print(
\\ Listening on 0.0.0.0:3000
\\
\\ Check out:
\\ http://localhost:3000/user/1 # -- first user
\\ http://localhost:3000/user/2 # -- second user
\\ http://localhost:3000/user/3 # -- non-existing user
\\
, .{});
// start worker threads
zap.start(.{
.threads = 4,
.workers = 4, // although I have 8 cores, keep it for 4 cores for now.
});
}
const std = @import("std");
const CFlags = &.{};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = false,
});
const exe = b.addExecutable(.{
.name = "bootstrap",
.root_source_file = .{ .path = "src/hello_json.zig" },
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zap", zap.module("zap"));
exe.linkLibrary(zap.artifact("facil.io"));
b.installArtifact(exe);
}
.{
.name = "hello-world",
.paths = .{""},
.version = "0.1.0",
.minimum_zig_version = "0.12.0",
.dependencies = .{
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.7.0.tar.gz",
.hash = "12203126ff24e8018655eb7444c91f0d527d1213af16fcf2a578281abc994d01cc46",
},
},
}
Compiled the sample using:
zig build --summary all
Started the program using:
./zig-out/bin/bootstrap
INFO: Listening on port 3000
Listening on 0.0.0.0:3000
Check out:
http://localhost:3000/user/1 # -- first user
http://localhost:3000/user/2 # -- second user
http://localhost:3000/user/3 # -- non-existing user
INFO: Server is running 8 workers X 8 threads with facil.io 0.7.4 (kqueue)
* Detected capacity: 131056 open file limit
* Root pid: 15403
* Press ^C to stop
INFO: 15417 is running.
INFO: 15415 is running.
INFO: 15413 is running.
INFO: 15414 is running.
INFO: 15416 is running.
INFO: 15419 is running.
INFO: 15418 is running.
INFO: 15420 is running.
hey -n 5000 -c 250 -m GET http://localhost:3000/user/1
hey -n 5000 -c 250 -m GET http://localhost:3000/user/1
Summary:
Total: 0.1737 secs
Slowest: 0.0395 secs
Fastest: 0.0001 secs
Average: 0.0078 secs
Requests/sec: 28785.3794
Total data: 222840 bytes
Size/request: 45 bytes
Response time histogram:
0.000 [1] |
0.004 [1804] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.008 [1409] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.012 [842] |■■■■■■■■■■■■■■■■■■■
0.016 [465] |■■■■■■■■■■
0.020 [235] |■■■■■
0.024 [57] |■
0.028 [43] |■
0.032 [79] |■■
0.036 [15] |
0.040 [2] |
Latency distribution:
10% in 0.0032 secs
25% in 0.0035 secs
50% in 0.0067 secs
75% in 0.0095 secs
90% in 0.0153 secs
95% in 0.0183 secs
99% in 0.0310 secs
Details (average, fastest, slowest):
DNS+dialup: 0.0003 secs, 0.0001 secs, 0.0395 secs
DNS-lookup: 0.0002 secs, 0.0000 secs, 0.0084 secs
req write: 0.0000 secs, 0.0000 secs, 0.0081 secs
resp wait: 0.0065 secs, 0.0001 secs, 0.0208 secs
resp read: 0.0005 secs, 0.0000 secs, 0.0099 secs
Status code distribution:
[200] 4952 responses
Error distribution:
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51177->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51178->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51179->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51180->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51181->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51182->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51183->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51184->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51185->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51186->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51187->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51188->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51189->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51190->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51191->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51192->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51193->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51194->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51195->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51196->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51197->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51198->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51199->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51200->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51201->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51202->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51203->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51205->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51206->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51207->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51208->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51209->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51210->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51211->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51212->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51213->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51215->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51216->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51217->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51218->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51219->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51220->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51221->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51222->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51224->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51225->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51226->[::1]:3000: read: connection reset by peer
[1] Get "http://localhost:3000/user/1": read tcp [::1]:51228->[::1]:3000: read: connection reset by peer
I am trying to understand what would be the maximum number of concurrent connection supported by a single instance of Zap. If you would like me to post the question elsewhere, I am happy to do so. Thanks!
When handling request path of multiple levels such as /a/b/c
(my particular case was /oauth2/google/redirect
, setCookie
will automatically set the path to /a/b
. On a subsequent visit, the cookie will only be available when you visit any path below /a/b
so if you are visiting from a path such as /
or /a
the request handler won't see the cookie. This may
be a security feature but there is no way to override it as setCookie({.path = "/" })
will be ignored.
I tried using the following code
try r.setCookie(.{
.name = self.settings.cookie_name,
.value = state,
.max_age_s = self.settings.cookie_maxage,
.path = "/",
}) catch |err| {
Instead I have to use the following workaround to make it work:
const cookie_str = try std.fmt.allocPrint(self.allocator, "{s}={s};Path=/;Max-Age={d}", .{
self.settings.cookie_name, state, self.settings.cookie_maxage
});
defer self.allocator.free(cookie_str);
try r.setHeader("Set-Cookie", cookie_str);
$ zig build run-hello
/home/yonas/git/zap/build.zig:7:23: error: no field or member function named 'standardOptimizeOption' in 'build.Builder'
const optimize = b.standardOptimizeOption(.{});
~^~~~~~~~~~~~~~~~~~~~~~~
/snap/zig/6352/lib/std/build.zig:31:21: note: struct declared here
pub const Builder = struct {
^~~~~~
referenced by:
runBuild: /snap/zig/6352/lib/build_runner.zig:233:32
usage__anon_5064: /snap/zig/6352/lib/build_runner.zig:242:13
remaining reference traces hidden; use '-freference-trace' to see all reference traces
OS: Ubuntu 23.04
Zig: 0.10.1
Currently the only (exposed) way to send response is to create buffer where you write whole response and you send that. However it would be way more useful to have support for std.io.Writer
(and potentially std.io.Reader
for reading body of the request) as it would allow developer to use std.fmt
functions. This however requires changes upstream as calling http_send_body
repeatedly sets incorrect content-length
header (it will be set to length of last chunk instead of length of the whole written data).
When compiling on windows, there isn't the linux related code, macros and includes such as
nanosleep
kill
<arpa/inet.h>
<sys/time.h>
<unistd.h>
etc
When I need the raw HTTP body to parse multipart form data which can contain binary data such as image data, SimpleRequest.body
would not contain the full body. For example, I have a request that has 2661 bytes (content-length is set by the browser), However, the SimpleRequest.body.len
is only 157 bytes. This would only happen when an image file such as PNG is embedded. If a text file is embedded, it would work properly.
The following is the problem (with my own debugging code output but it illustrates the problem).
Because the request cuts off the actual data, when I try to access the data in the request using the []const u8
body, it would complain about out-of-bounds
error.
upload.image: length=2661
upload.image: content-type=multipart/form-data; boundary=----WebKitFormBoundaryC4LA6TmfoOku2M3F
upload.image: boundary=----WebKitFormBoundaryC4LA6TmfoOku2M3F
saving to public/img
body size is 157 == 2661?
body is { 45, 45, 45, 45, 45, 45, 87, 101, 98, 75, 105, 116, 70, 111, 114, 109, 66, 111, 117, 110, 100, 97, 114, 121, 67, 52, 76, 65, 54, 84,
109, 102, 111, 79, 107, 117, 50, 77, 51, 70, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 68, 105, 115, 112, 111, 115, 105, 116, 105, 111,
110, 58, 32, 102, 111, 114, 109, 45, 100, 97, 116, 97, 59, 32, 110, 97, 109, 101, 61, 34, 115, 101, 114, 118, 101, 114, 95, 105, 109, 97, 103, 101, 34, 59, 32, 102, 105, 108, 101, 110, 97, 109, 101, 61, 34, 116, 101, 115, 116, 45, 115, 109, 97, 108, 108, 46, 112, 110, 103, 34, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 105, 109, 97, 103, 101, 47, 112, 110, 103, 13, 10, 13, 10, 137, 80, 78, 71,
13, 10, 26, 10 }
skipped: ------WebKitFormBoundaryC4LA6TmfoOku2M3F
name=server_image
filename=test-small.png
Content-Type=image/png
thread 644033 panic: index out of bounds: index 2659, len 157
/home/edyu/ws/zig/myprogram/src/server_endpoint.zig:172:52: 0x2e6b45 in parseMultiPart (myprogram)
if (!std.mem.eql(u8, stop, body[end + 2 .. length - 2])) {
^
Hi guys, I try to integrate zap
into my project and I want to build the musl
version that runs inside the Alpine
docker container, but I found that it fails on the x86_64-linux-musl
target build.
Here is my custom Cross-compilation build:
//
// Create musl release build
//
const musl_target: CrossTarget = CrossTarget.parse(.{
.arch_os_abi = "x86_64-linux-musl",
}) catch unreachable;
const musl_bin = b.addExecutable(.{
.name = SERVICE_NAME,
.root_source_file = .{ .path = "src/main.zig" },
//
// Cross-compilation
//
.target = musl_target,
//
// Enable release build (best performance)
//
// .optimize = std.builtin.OptimizeMode.ReleaseFast,
//
// Enable release build (best binary size)
//
.optimize = std.builtin.OptimizeMode.ReleaseSmall,
});
//
// Integrate with `zap`
//
const zap = b.dependency("zap", .{
.target = musl_target,
.optimize = std.builtin.OptimizeMode.ReleaseSmall,
});
musl_bin.addModule("zap", zap.module("zap"));
musl_bin.linkLibrary(zap.artifact("facil.io"));
Here is the error:
zig build-exe zig-demo-service ReleaseSmall x86_64-linux-musl: error: the following command failed with 1 compilation errors:
/home/wison/my-shell/zig-nightly/zig build-exe /home/wison/zig/zig-http-server/src/main.zig /home/wison/zig/zig-http-server/zig-cache/o/b13ae56265c6f3a04c951370499bf664/libfacil.io.a /home/wison/zig/zig-http-server/zig-cache/o/b8235fee8479f607b8ae0c422b0e73e9/libfacil.io.a -lc -OReleaseSmall --cache-dir /home/wison/zig/zig-http-server/zig-cache --global-cache-dir /home/wison/.cache/zig --name zig-demo-service -target x86_64-linux-musl -mcpu x86_64 --mod zap::/home/wison/.cache/zig/p/1220e30645c293c943dccc9d4394f7088679cf0969c63a7f4b23f72e375744123729/src/zap.zig --deps zap -I /home/wison/zig/zig-http-server/zig-cache/i/faa100beff85fdd06f2eb0d8196143c1/include --listen=-
Build Summary: 51/55 steps succeeded; 1 failed (disable with --summary none)
service-build transitive failure
└─ run ls transitive failure
└─ install zig-demo-service transitive failure
└─ zig build-exe zig-demo-service ReleaseSmall x86_64-linux-musl 1 errors
error: ld.lld: undefined symbol: sendfile64
note: referenced by fio.c:2691 (/home/wison/.cache/zig/p/12205e49e9c2c6f0dcab9423fc92d8f0450a4dc2706b68a6d45a448a738ebff70103/lib/facil/fio.c:2691)
note: /home/wison/zig/zig-http-server/zig-cache/o/a9b7fc5770a0cd3eb9b5e9619bb49ea6/fio.o:(fio_sock_sendfile_from_fd) in archive /home/wison/zig/zig-http-server/zig-cache/o/b8235fee8479f607b8ae0c422b0e73e9/libfacil.io.a
And I confirm that the libfacil.io.a
exists:
-rw-r--r-- 1 wison wison 1.7M Jul 5 16:48 /home/wison/zig/zig-http-server/zig-cache/o/b8235fee8479f607b8ae0c422b0e73e9/libfacil.io.a
OS: Linux my-arch 6.1.22-1-lts #1 SMP PREEMPT_DYNAMIC Thu, 30 Mar 2023 14:10:04 +0000 x86_64 GNU/Linux
Any idea?:)
akhil@ad:~/practice/immich$ zig build
/home/akhil/practice/immich/zap/build.zig:217:9: error: local variable is never mutated
var announceybot_exe = b.addExecutable(.{
^~~~~~~~~~~~~~~~
/home/akhil/practice/immich/zap/build.zig:217:9: note: consider using 'const'
/home/akhil/practice/immich/zap/build.zig:203:9: error: local variable is never mutated
var pkghash_exe = b.addExecutable(.{
^~~~~~~~~~~
/home/akhil/practice/immich/zap/build.zig:203:9: note: consider using 'const'
/home/akhil/practice/immich/zap/build.zig:15:9: error: local variable is never mutated
var zap_module = b.createModule(.{
^~~~~~~~~~
/home/akhil/practice/immich/zap/build.zig:15:9: note: consider using 'const'
Yo. I'm still looking into this and am going to start digging into zap and facil to see if I can't see what's going on, but I wanted to drop what I'm seeing here first so I don't lose it. I'm also going to try and set up a mini version of this in my efforts to narrow down what's happening... I'll be back here to update with more info, but until then...
(reproducible version @ https://github.com/Vemahk/zap-issue-64)
After plugging in TLS and getting the certs squared away, I immediately noticed maybe a third of the requests made to the server would stall for about 6 seconds, and there was an accompanying "UUID error". The client gets the right response after the stall, but it looks like on the server side, it fails and retries internally:
192.168.0.100 - - [Sat, 06 Jan 2024 03:59:21 GMT] "GET / HTTP/1.1" 200 416b 577us
192.168.0.100 - - [Sat, 06 Jan 2024 03:59:27 GMT] "GET / HTTP/1.1" 200 416b 873us
192.168.0.100 - - [Sat, 06 Jan 2024 03:59:27 GMT] "GET /time HTTP/1.1" 200 33b 649us
UUID error: 0x810 (0)
No errno handler: Success
Above, the first request to / was replayed 6 seconds later. The UUID error I think is just late to the party, and the /time call snuck in.
I looked around in zap and found that the UUID error is probably coming from fio.c:3035, which looks to be something to do with actually writing to the response stream...
Some extra notes: it seems like which requests stall are relatively random. I can spam refresh and some make it through, some stall. Eventually, I segfaulted it by continuing to spam the refresh from the browser:
192.168.0.100 - - [Sat, 06 Jan 2024 03:49:28 GMT] "GET / HTTP/1.1" 200 416b 671us
Segmentation fault at address 0xfff06bf95fb0
???:?:?: 0xffff9d9d28d8 in ??? (libcrypto.so.3)
Unwind information for `libcrypto.so.3:0xffff9d9d28d8` was not available, trace may be incomplete
???:?:?: 0x0 in ??? (???)
run http-test: error: the following command terminated unexpectedly:
cd /home/vemahk/coding/zig/http-test/zig-out && /home/vemahk/coding/zig/http-test/zig-out/bin/http-test
Build Summary: 7/9 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run http-test failure
error: the following build command failed with exit code 1:
/home/vemahk/coding/zig/http-test/zig-cache/o/f6f8278f7afc1bca5b5ecd21b7918d65/build /home/vemahk/.apps/zig/zig /home/vemahk/coding/zig/http-test /home/vemahk/coding/zig/http-test/zig-cache /home/vemahk/.cache/zig run
Which is when I thought I should come back here and start writing things down.
The segfault happened inside libcrypto, which makes me think that it could possibly be something screwy with the version of libcrypto that I have? Geeze, I hope not.
Anyway, gonna go back to investigating. I'll come back to update with anything else I find.
I ran through the demos on an M2 Max today, the one below still fails. Haven't looked at it more carefully, but thought I should mention it.
➜ zap git:(master) zig build run-wrk_zigstd -fno-summary -freference-trace
zig build-exe wrk_zigstd Debug native: error: the following command failed with 1 compilation errors:
/Users/jonas/src/zig/zig/build/stage3/bin/zig build-exe -freference-trace=256 /Users/jonas/src/zig/zap/wrk/zigstd/main.zig /Users/jonas/src/zig/zap/zig-cache/o/d3a562268d75faad3020a7a59f13d9cb/libfacil.io.a -lc --cache-dir /Users/jonas/src/zig/zap/zig-cache --global-cache-dir /Users/jonas/.cache/zig --name wrk_zigstd --mod zap::/Users/jonas/src/zig/zap/src/zap.zig --deps zap -I /Users/jonas/src/zig/zap/zig-cache/i/88557c3f68f5d33d5605fe5573541278/include --listen=-
wrk/zigstd/main.zig:14:41: error: no field named 'dynamic' in struct 'http.Server.AcceptOptions'
var res = try server.accept(.{ .dynamic = max_header_size });
^~~~~~~
/Users/jonas/src/zig/zig/build/stage3/lib/zig/std/http/Server.zig:733:27: note: struct declared here
pub const AcceptOptions = struct {
^~~~~~
referenced by:
comptime_0: /Users/jonas/src/zig/zig/build/stage3/lib/zig/std/start.zig:63:50
The serve and routes examples on macOS x86_64 with zig version 0.11.0-dev.1622+fc48467a9
produces the following error
.../zig/std/mem.zig:654:33: error: invalid type given to std.mem.span: *const [14:0]u8
.One, .Slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../zig/std/mem.zig:679:31: note: called from here
pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
Removing std.mem.span
from the examples works for me. I don't really know what Span does so opened an issue instead of a PR.
That would be really helpful for setting content-type
header to proper values when you deal with something more than just JSON, HTML, and plain text.
With enumerable it makes it way easier to setup routing or in general match against request method. There is even built in std.http.Method
enum that provides set of such methods available.
I've been trying to create a project using Zap and building it, but Zap throws an error making my project unable to compile.
I've tried many things to get it working and verified my build files, but the error persists and comes out of Zap's build file it seems.
and comes from here within Zap (build.zig
)
My build.zig
(shortened)
const std = @import("std");
pub fn build(b: *std.Build) void {
// ...
const exe = b.addExecutable(.{
.name = "api",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// LOADING ZAP
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
.openssl = false, // set to true to enable TLS support
});
exe.addModule("zap", zap.module("zap"));
exe.linkLibrary(zap.artifact("facil.io"));
b.installArtifact(exe);
// ...
}
My build.zig.zon
file (shortened)
.{
.dependencies = .{
// zap v0.5.0
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.5.0.tar.gz",
.hash = "1220aabff84ad1d800f5657d6a49cb90dab3799765811ada27faf527be45dd315a4d",
},
},
}
Version of Zig 0.11.0
Version of Zap 0.5.0
Version of Windows Windows 11 - Build 23620.1000 - 22H2
I'm relatively new to zig so it is likely that I'm doing things wrong.
Follow the basic instructions to add zap to your project:
.{
.name = "zig-web-server",
.version = "0.0.1",
.dependencies = .{
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
.hash = "12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a",
}
}
}
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "zig-web-server",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
});
exe.addModule("zap", zap.module("zap"));
exe.linkLibrary(zap.artifact("facil.io"));
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
As soon as I run zig build run
I get the following output:
thread 81654 panic: unable to find module 'zap'
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/debug.zig:374:22: 0x387999 in panicExtra__anon_47118 (build)
std.builtin.panic(msg, trace, ret_addr);
^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/debug.zig:349:15: 0x35f089 in panic__anon_28781 (build)
panicExtra(null, null, format, args);
^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/Build.zig:1556:18: 0x3350b7 in module (build)
panic("unable to find module '{s}'", .{name});
^
/home/jotunn/Projects/zig/zig-web-server/build.zig:19:36: 0x2f03af in build (build)
exe.addModule("zap", zap.module("zap"));
^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/Build.zig:1638:33: 0x2df313 in runBuild__anon_7164 (build)
.Void => build_zig.build(b),
^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/build_runner.zig:297:29: 0x2db0e2 in main (build)
try builder.runBuild(root);
^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/start.zig:574:37: 0x2c69ee in posixCallMainAndExit (build)
const result = root.main() catch |err| {
^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/start.zig:243:5: 0x2c64d1 in _start (build)
asm volatile (switch (native_arch) {
^
???:?:?: 0x5 in ??? (???)
Unwind information for `???:0x5` was not available, trace may be incomplete
It complains about being unable to find the zap module.
Any help is welcome.
I am trying to build on an M2 Max.
➜ zap git:(master) zig version; sw_vers; clang --version
0.11.0-dev.3177+e584dd806
ProductName: macOS
ProductVersion: 13.3.1
ProductVersionExtra: (a)
BuildVersion: 22E772610a
Homebrew clang version 16.0.3
Target: arm64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
➜ zap git:(master) git log -1 | tee
commit 6e3c9805164acfe7be57f687712ab87e49314e8d
Author: Rene Schallner <[email protected]>
Date: Tue May 16 04:47:08 2023 +0200
Update README.md
What is the zig version to run this project? 0.10.1 fails with silly errors, which one is needed is not listed anywhere...
Another essential feature: does zap as it stands today support HTTP streaming of chunked responses, Transfer-Encoding: chunked
?
Today I've been kicking the tyres of facil.io
in C. It's not bad, the documentation might have been better, but it is not clear at all how to stream HTTP responses in facil (and therefore zap too). Say your code produces a large amount of output data at a "steady" rate that you want to stream via HTTP in response to an HTTP request.
Right now, with libmicrohttpd this is trivial. You open a Unix pipe, pass the write end (the producer) to a separate POSIX thread, and pass the consumer (the read end of a pipe) to an HTTP response handler that accepts a Unix pipe file descriptor (struct MHD_Response * MHD_create_response_from_pipe (int fd)
).
i.e.
// create a response from a pipe by passing the read end of the pipe
struct MHD_Response *response = MHD_create_response_from_pipe(pipefd[0]);
// add headers
MHD_add_response_header(response, "Cache-Control", "no-cache");
MHD_add_response_header(response, "Cache-Control", "no-store");
MHD_add_response_header(response, "Pragma", "no-cache");
MHD_add_response_header(response, "Content-Type", "application/octet-stream");
// queue the response
enum MHD_Result ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response(response);
// the code below should be run in a separate thread
// otherwise libmicrohttpd will not have a chance to read from the pipe
// pass the write end of the pipe to Fortran
// the binary response data will be generated in Fortran
printf("[C] calling video_request with the pipe file descriptor %d\n", pipefd[1]);
struct video_req *req = malloc(sizeof(struct video_req));
if (req != NULL)
{
req->keyframe = keyframe;
req->frame = frame;
req->flux = strdup(flux);
req->len = strlen(req->flux);
req->dmin = dmin;
req->dmax = dmax;
req->dmedian = dmedian;
req->sensitivity = sensitivity;
req->slope = slope;
req->white = white;
req->black = black;
req->width = width;
req->height = height;
req->downsize = downsize;
req->fd = pipefd[1];
req->ptr = item;
// create and detach the thread
int stat = pthread_create(&tid, NULL, &video_request, req);
if (stat == 0)
pthread_detach(tid);
else
{
close(pipefd[1]);
free(req);
}
}
else
close(pipefd[1]);
return ret;
Adding as a TODO for myself (or others, if they find the time). Since it got merged in, there should be a test verifying that it works as expected when zap is compiled.
I have a server running that works totally fine, unless you wait 60+ seconds between queries, then you get a segfault:
Stack trace:
5432
Listening on 0.0.0.0:3333
127.0.0.1 - - [Thu, 28 Mar 2024 17:38:39 GMT] "GET /areas HTTP/1.1" 200 210b 64900us
Segmentation fault at address 0x790716562000
/home/user/zig/0.11.0/files/lib/compiler_rt/memcpy.zig:19:21: 0x667660 in memcpy (compiler_rt)
d[0] = s[0];
^
/home/user/zig/0.11.0/files/lib/std/mem/Allocator.zig:327:20: 0x3eed9c in dupeZ__anon_12285 (server)
@memcpy(new_buf[0..m.len], m);
^
/home/user/zig/0.11.0/files/lib/std/net.zig:858:43: 0x381891 in getAddressList (server)
const name_c = try allocator.dupeZ(u8, name);
^
/home/user/zig/0.11.0/files/lib/std/net.zig:709:36: 0x2aa0e8 in tcpConnectToHost (server)
const list = try getAddressList(allocator, name, port);
^
/home/user/.cache/zig/p/122008c4873ab9964cd1b0df4244a24a36602723aca86d2d601a4a23a7d06bc433d6/src/conn.zig:102:40: 0x2a9656 in open (server)
break :blk try net.tcpConnectToHost(allocator, host, port);
^
/home/user/.cache/zig/p/122008c4873ab9964cd1b0df4244a24a36602723aca86d2d601a4a23a7d06bc433d6/src/pool.zig:218:20: 0x3786be in newConnection (server)
conn.* = Conn.open(allocator, opts.connect) catch |err| {
^
/home/user/.cache/zig/p/122008c4873ab9964cd1b0df4244a24a36602723aca86d2d601a4a23a7d06bc433d6/src/pool.zig:120:31: 0x4b5490 in release (server)
conn_to_add = newConnection(self, true) catch {
^
/home/user/.cache/zig/p/122008c4873ab9964cd1b0df4244a24a36602723aca86d2d601a4a23a7d06bc433d6/src/conn.zig:176:15: 0x446c24 in release (server)
pool.release(self);
^
/home/user/programming/zig/server-repro/src/endpoints/areas.zig:56:23: 0x448162 in queryAreas (server)
defer conn.release();
^
/home/user/programming/zig/server-repro/src/endpoints/areas.zig:48:40: 0x448be6 in _get (server)
const productCodes = try queryAreas(arenaAlloc, companyId);
^
/home/user/programming/zig/server-repro/src/endpoints/areas.zig:34:9: 0x3ba1a0 in get (server)
_get(self, r) catch |err| {
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/src/endpoint.zig:64:36: 0x43d122 in onRequest (server)
.GET => self.settings.get.?(self, r),
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/src/endpoint.zig:320:32: 0x3b9d50 in onRequest (server)
e.onRequest(r);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/src/zap.zig:224:27: 0x37b2be in theOneAndOnlyRequestCallBack (server)
on_request(req);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http_internal.c:53:3: 0x645b7b in http_on_request_handler______internal (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http_internal.c)
settings->on_request(h);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c:553:3: 0x654011 in http1_on_request (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c)
http_on_request_handler______internal(&http1_pr2handle(p), p->p.settings);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/parsers/http1_parser.h:859:9: 0x65360a in http1_parse (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c)
if (((parser->state.reserved & HTTP1_P_FLAG_RESPONSE)
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c:689:9: 0x652fc3 in http1_consume_data (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c)
i = http1_parse(&p->parser, p->buf + (org_len - p->buf_len), p->buf_len);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c:775:3: 0x650d45 in http1_on_data_first_time (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/http/http1.c)
http1_consume_data(uuid, p);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c:2213:3: 0x611755 in deferred_on_data (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c)
pr->on_data((intptr_t)uuid, pr);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c:1011:3: 0x61096a in fio_defer_perform_single_task_for_queue (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c)
task.func(task.arg1, task.arg2);
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c:1049:10: 0x6108f4 in fio_defer_perform (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c)
fio_defer_perform_single_task_for_queue(&task_queue_normal) == 0)
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c:3793:5: 0x616d8b in fio_worker_startup (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c)
fio_defer_perform();
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c:3942:3: 0x616a0b in fio_start (/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/facil.io/lib/facil/fio.c)
fio_worker_startup();
^
/home/user/.cache/zig/p/1220d4802fb09d4e99c0e7265f90d6f3cfdc3e5e31c1b05f0924ee2dd26d9d6dbbf4/src/zap.zig:94:18: 0x37c37a in start (server)
fio.fio_start(args);
^
/home/user/programming/zig/server-repro/src/main.zig:60:18: 0x37bde8 in main (server)
zap.start(.{
^
/home/user/zig/0.11.0/files/lib/std/start.zig:574:37: 0x37ca6e in main (server)
const result = root.main() catch |err| {
^
???:?:?: 0x790716394ccf in ??? (libc.so.6)
Unwind information for `libc.so.6:0x790716394ccf` was not available, trace may be incomplete
I've tried changing the timeout
option for zap.Endpoint.Listener.init
(tried 0, 255, and unset) but the result is the same. Maybe it's something else?
I've created a reproduction here https://github.com/richard-powers/server-error-repro
After the server is up and running, I run:
http 'http://127.0.0.1:3333/areas?companyId=1'; sleep 1m; http 'http://127.0.0.1:3333/areas?companyId=1';
The segfault appears after the 2nd query
After following the instructions in the readme for the build info, attempting to run a zig build
fails. I assume I either did something silly or that the documentation in the readme is missing a step, but I'm not sure which it is. The project is a straight-up zig init-exe
with the modifications indicated in README.md.
zig version
0.11.0
build.zig.zon:
.{
.name = "test",
.version = "0.0.1",
.dependencies = .{
// zap v0.2.0
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.0.tar.gz",
.hash = "1220614483f9638f29c6c1bf07c03e945ea28a1055b82f500d3628f4134dc582b6ed",
},
},
}
build.zig
const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "test",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
});
exe.addModule("zap", zap.module("zap"));
exe.linkLibrary(zap.artifact("facil.io"));
exe.linkLibC();
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);
// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);
// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
Versions:
zig 0.11.0
zap 0.1.14-pre
Steps to reproduce:
zig init-exe
.{
.name = "My example project",
.version = "0.0.1",
.dependencies = .{
// zap v0.1.14-pre
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
.hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",
}
}
}
rm -rf ~/.cache/zig/
on linuxzig build run
Output:
Fetch Packages [1/1] zap... /home/marcus/Downloads/b/build.zig.zon:9:21: error: hash mismatch: expected: 122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3, found: 12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91
.hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For REST, the HTTP method 'PUT' is used if the whole resource gets replaced such as changing the user id 3 from Rene to Ed so that Ed is a completely different struct (person). For updating a field such as the last name or the first name of a user, usually PATCH is preferred. Making this issue so I can link it to a pull request.
Hi,
I am new to zig and got compilation error when trying to build this repo.
zap/build.zig:7:23: error: no field or member function named 'standardOptimizeOption' in 'build.Builder'
const optimize = b.standardOptimizeOption(.{});
~^~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/zig/0.10.1/lib/zig/std/build.zig:31:21: note: struct declared here
pub const Builder = struct {
^~~~~~
referenced by:
runBuild: /opt/homebrew/Cellar/zig/0.10.1/lib/zig/build_runner.zig:233:32
usage__anon_4534: /opt/homebrew/Cellar/zig/0.10.1/lib/zig/build_runner.zig:242:13
remaining reference traces hidden; use '-freference-trace' to see all reference traces
Versions:
Zig: 0.11.0
Zap: 0.2.5
I have a pet-project I'm working on using zap, and I thought I'd try out the TLS stuff when I saw 0.2.5 come out. I tried plugging it in real quickly and immediately ran into a build issue. Thought it was just me, so I cloned the zap repo and ran the zig build run-https
, only to have the same build issue pop up.
vemahk:~/zap$ zig build run-https
zig build-exe https Debug native: error: the following command failed with 1 compilation errors:
/home/vemahk/.apps/zig/zig build-exe /home/vemahk/zap/examples/https/https.zig /home/vemahk/zap/zig-cache/o/6ec5768283debabdd042d8fe36799e77/libfacil.io.a -lc --cache-dir /home/vemahk/zap/zig-cache --global-cache-dir /home/vemahk/.cache/zig --name https --mod zap::/home/vemahk/zap/src/zap.zig --deps zap --listen=-
Build Summary: 1/4 steps succeeded; 1 failed (disable with --summary none)
run-https transitive failure
mq run https transitive failure
mq zig build-exe https Debug native 1 errors
error: ld.lld: undefined symbol: fio_tls_new
note: referenced by tls.zig:27 (/home/vemahk/zap/src/tls.zig:27)
note: /home/vemahk/zap/zig-cache/o/b7e39a688312582a3599d8d94587fe9f/https.o:(tls.init)
Relevant machine specs:
OS: Ubuntu 22.04.3 LTS aarch64
Host: Raspberry Pi 4 Model B Rev 1.2
Kernel: 5.15.0-1044-raspi
CPU: BCM2835 (4) @ 1.500GHz
I figured it might have something to do with running on an ARM raspberry pi... but honestly I'm kinda green to all this, so I've got no idea.
Anyway, would appreciate any help. Thanks for your good work on this stuff, zap's been great.
Note to self: I want a lightweight query param iterator that works on the query string itself and basically just splits between ?/& and =, which never allocates.
I follow the instruct:
in your build.zig's build function, add the following before b.installArtifact(exe):
const zap = b.dependency("zap", .{ .target = target, .optimize = optimize, .openssl = false, // set to true to enable TLS support }); exe.root_module.addImport("zap", zap.module("zap"));
Got the error:
error: ld.lld: undefined symbol: http_listen
ld.lld: undefined symbol: fio_start
If add exe.linkLibrary(zap.artifact("facil.io"));
again, It's OK
Using zip version 0.12.0-dev.934+a241cf90d
(2023-10-16), I try to run sample, following the README:
$ git clone https://github.com/zigzap/zap.git
$ cd zap
$ zig build run-hello
and I get this error:
$ zig build run-hello
.../zap/build.zig.zon:1:2: error: missing top-level 'paths' field
Never used zon, so perhaps I'm missing something (only learning zig).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.