From 12e32e5559be7427483f8520a58dce34046f020c Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Sun, 26 May 2024 22:10:03 +0100 Subject: Add post on zigvm Fixup for zig master --- build.zig.zon | 6 +++--- comments/build.zig | 6 ++---- comments/build.zig.zon | 15 ++++++++++----- comments/src/main.zig | 16 ++++++++-------- content/posts/2024-05-23-zigvm.md | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 content/posts/2024-05-23-zigvm.md diff --git a/build.zig.zon b/build.zig.zon index 268ad8d..aee0286 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,9 +3,9 @@ .version = "0.0.0", .dependencies = .{ .zine = .{ - .url = "git+https://github.com/kristoff-it/zine.git#e33a1d79b09e8532db60347a7ec4bd3413888977", - .hash = "12209f9be74fcc805c0f086e4a81ccca041354448f5b3592e04b6a6d1b4a95da5a26", - //.path = "../zine", + //.url = "git+https://github.com/kristoff-it/zine.git#e33a1d79b09e8532db60347a7ec4bd3413888977", + //.hash = "12209f9be74fcc805c0f086e4a81ccca041354448f5b3592e04b6a6d1b4a95da5a26", + .path = "../zine", }, }, .paths = .{"."}, diff --git a/comments/build.zig b/comments/build.zig index 3293e4c..c978095 100644 --- a/comments/build.zig +++ b/comments/build.zig @@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void { .name = "comments", // 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" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -40,8 +40,6 @@ pub fn build(b: *std.Build) void { const smtp = b.dependency("smtp", opts); exe.root_module.addImport("smtp", smtp.module("smtp")); - - // 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`). @@ -73,7 +71,7 @@ pub fn build(b: *std.Build) void { // 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" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); diff --git a/comments/build.zig.zon b/comments/build.zig.zon index edc18d7..54d1e35 100644 --- a/comments/build.zig.zon +++ b/comments/build.zig.zon @@ -3,16 +3,21 @@ .version = "0.0.1", .dependencies = .{ .pq = .{ .url = "https://code.mfashby.net/pq-zig/snapshot/pq-zig-main.tar.xz", - .hash = "12201517d080461a76f4b26ff78a810d80b1d58e2d3f382da30de1055ebdcea3feaf", + .hash = "1220895045b9a9333a385a0329d9c11604036f28a2150d10c3ed711d4bab21d4a218", + //.path = "../../pq-zig" }, .smtp = .{ .url = "https://code.mfashby.net/smtp-zig/snapshot/smtp-zig-main.tar.xz", - .hash = "1220b85b46b525e725f8fdb6e23189aa365976acf388e3b2a5a4da364851c3ec4252", + .hash = "1220b42673da5f313d4ce816e41de2f17e4b7ebbae1669904b9c17a385d9997e72ed", + //.path = "../../smtp-zig" }, .mustache = .{ - .url = "https://github.com/batiati/mustache-zig/archive/refs/heads/master.tar.gz", - .hash = "12205538be57d7c0b92806e87c500c50bfcecb9b083adea8b2fdbec99f46598c922d", + // TODO revert to balati when https://github.com/batiati/mustache-zig/pull/21 is merged + .url = "https://github.com/MFAshby/mustache-zig/archive/refs/heads/master.tar.gz", + .hash = "1220910fce41f46c0f652c3bfe19ca83940b1b26e046d8bdb901e3a9fd0f2b480b1b", + //.path = "../../mustache-zig" }, .zigwebserver = .{ .url = "https://code.mfashby.net/zigwebserver/snapshot/zigwebserver-main.tar.xz", - .hash = "122084fc67129e92544a86f10ca9a64f2667682aa7dfd6a12a80c374015a33555df6", + .hash = "122065d7f71c3788d59e952a283f714e5df90d50b170a3dc5066dd9cd1d104319831", + //.path = "../../zigwebserver" } }, .paths = .{""}, } diff --git a/comments/src/main.zig b/comments/src/main.zig index a5008b8..165dff0 100644 --- a/comments/src/main.zig +++ b/comments/src/main.zig @@ -84,7 +84,7 @@ const Response = struct { fn do(self: @This()) !void { const wtr = std.io.getStdOut().writer(); if (self.status.phrase()) |phrase| { - try std.fmt.format(wtr, "status: {} {s}\r\n", .{@intFromEnum(self.status), phrase}); + try std.fmt.format(wtr, "status: {} {s}\r\n", .{ @intFromEnum(self.status), phrase }); } else { try std.fmt.format(wtr, "status: {}\r\n", .{@intFromEnum(self.status)}); } @@ -196,7 +196,7 @@ fn get_comment(res: *Response, ctx: Ctx, _: Params) Err!void { } const rr = @embedFile("templates/comments.html"); - const tt = comptime mustache.parseComptime(rr, .{}, .{}); + const tt = mustache.parseText(res.allocator, rr, .{}, .{ .copy_strings = false }) catch unreachable; res.transfer_encoding = .chunked; try res.headers.append("content-type", "text/html"); try res.do(); @@ -204,7 +204,7 @@ fn get_comment(res: *Response, ctx: Ctx, _: Params) Err!void { const data = struct { comments: []const Comment, }; - try mustache.render(tt, data{ + try mustache.render(tt.success, data{ .comments = comments.items, }, res.writer()); try res.finish(); @@ -243,7 +243,7 @@ fn post_comment(res: *Response, ctx: Ctx, _: Params) Err!void { } const ans = try stmt.read_column(0, []const u8); if (!std.mem.eql(u8, ans, form_val.capcha_answer)) { - std.log.err("bad capcha answer {s} expected {s}", .{form_val.capcha_answer, ans}); + std.log.err("bad capcha answer {s} expected {s}", .{ form_val.capcha_answer, ans }); try constresponse(res, @embedFile("templates/capchainvalid.html"), std.http.Status.unauthorized); return; } @@ -261,9 +261,9 @@ fn post_comment(res: *Response, ctx: Ctx, _: Params) Err!void { // Send me an email const rr = @embedFile("templates/notification.txt"); - const tt = comptime mustache.parseComptime(rr, .{}, .{}); + const tt = mustache.parseText(res.allocator, rr, .{}, .{ .copy_strings = false }) catch unreachable; const Data = struct { url: []const u8, author: []const u8, comment: []const u8 }; - const notification = try mustache.allocRender(res.allocator, tt, Data{ + const notification = try mustache.allocRender(res.allocator, tt.success, Data{ .url = form_val.url, .author = form_val.author, .comment = form_val.comment, @@ -306,7 +306,7 @@ fn get_form(res: *Response, ctx: Ctx, _: Params) Err!void { const capcha = try stmt.read_struct(Capcha); const rr = @embedFile("templates/form.html"); - const tt = comptime mustache.parseComptime(rr, .{}, .{}); + const tt = mustache.parseText(res.allocator, rr, .{}, .{ .copy_strings = false }) catch unreachable; res.transfer_encoding = .chunked; try res.headers.append("content-type", "text/html"); @@ -317,7 +317,7 @@ fn get_form(res: *Response, ctx: Ctx, _: Params) Err!void { capcha_question: []const u8, url: []const u8, }; - try mustache.render(tt, data{ + try mustache.render(tt.success, data{ .capcha_id = capcha.id, .capcha_question = capcha.question, .url = url, diff --git a/content/posts/2024-05-23-zigvm.md b/content/posts/2024-05-23-zigvm.md new file mode 100644 index 0000000..43a4855 --- /dev/null +++ b/content/posts/2024-05-23-zigvm.md @@ -0,0 +1,18 @@ +--- +.title = "zigvm", +.author = "Martin Ashby", +.date = @date("2024-05-23T22:24:34+01:00"), +.layout = "single.html", +.custom = {"comments": true}, +--- + +I wrote a tool to download and manage Zig versions ... in zig. + +It uses the [JSON](https://ziglang.org/download/index.json) metadata available for zig downloads. It has one third party dependency on [minisign](https://github.com/jedisct1/zig-minisign). JSON parsing, HTTPS client, and tar/compression were all available in the standard library. + +Downloads: +* [Code](https://code.mfashby.net/zigvm/) +* [aarch64-linux](https://dl.mfashby.net/zigvm/v0.0.1/aarch64-linux) [SHA256 checksum](https://dl.mfashby.net/zigvm/v0.0.1/aarch64-linux.sha256) [minisig](https://dl.mfashby.net/zigvm/v0.0.1/aarch64-linux.minisig) +* [x86_64-linux](https://dl.mfashby.net/zigvm/v0.0.1/x86_64-linux) [SHA256 checksum](https://dl.mfashby.net/zigvm/v0.0.1/x86_64-linux.sha256) [minisig](https://dl.mfashby.net/zigvm/v0.0.1/x86_64-linux.minisig) + +Binaries are signed with [minisign](https://jedisct1.github.io/minisign/), public key `RWTsE4a/BXFWjmzxWB0Kko+w47ZRfQhxkF21Zfh7BxRzZm2q6l4GssRa` \ No newline at end of file -- cgit v1.2.3-ZIG