aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosa <rosaontheweb@proton.me>2026-05-11 16:31:43 -0400
committerRosa <rosaontheweb@proton.me>2026-05-11 16:31:43 -0400
commit6143a710c142cf6704527ae32a7c90c02e83fe4a (patch)
treebebd50bd9c160fe6fdf12bbd14b4f512d84c047e
parent710bfe5ddb769d9c6f15497928638f1aed3bc45a (diff)
start work on zig build system
-rw-r--r--.gitignore2
-rw-r--r--Justfile5
-rw-r--r--build.zig23
-rw-r--r--flake.nix5
-rw-r--r--src/static/hello.txt1
-rw-r--r--util/website.zig37
6 files changed, 67 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 1a3ccd3..e73df20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
/.direnv
/.envrc
+/html-out
+/.zig-cache
*.tar.gz
diff --git a/Justfile b/Justfile
deleted file mode 100644
index df17baa..0000000
--- a/Justfile
+++ /dev/null
@@ -1,5 +0,0 @@
-serve:
- lighttpd -Df util/lighttpd.conf
-
-package:
- tar -czvf etc.tar.gz src/*
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..7f8dec1
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,23 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+ const generate_html = b.addExecutable(.{
+ .name = "generate_html",
+ .root_module = b.createModule(.{
+ .root_source_file = b.path("util/website.zig"),
+ .target = b.graph.host,
+ }),
+ });
+
+ const run_generate_html = b.addRunArtifact(generate_html);
+ run_generate_html.setCwd(b.path("")); // make sure we always run from buildroot
+ b.getInstallStep().dependOn(&run_generate_html.step);
+
+ const bundle_html = b.addSystemCommand(&[_][]const u8{ "tar", "--exclude=pages.tar.gz", "-czvf", "html-out/pages.tar.gz", "html-out" });
+ const run_bundle_html = b.step("bundle", "Creates a tarball of the HTML output");
+ bundle_html.step.dependOn(b.getInstallStep());
+ run_bundle_html.dependOn(&bundle_html.step);
+
+ const publish_to_prod = b.step("publish", "Publish the website to production");
+ _ = publish_to_prod;
+}
diff --git a/flake.nix b/flake.nix
index b875fd9..618bd3d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -19,9 +19,12 @@
{
devShells.default = pkgs.mkShellNoCC {
nativeBuildInputs = with pkgs; [
- just
+ gnutar
lighttpd
+ openssh
vscode-langservers-extracted
+ zig
+ zls
];
};
diff --git a/src/static/hello.txt b/src/static/hello.txt
new file mode 100644
index 0000000..4effa19
--- /dev/null
+++ b/src/static/hello.txt
@@ -0,0 +1 @@
+hello!
diff --git a/util/website.zig b/util/website.zig
new file mode 100644
index 0000000..837a51c
--- /dev/null
+++ b/util/website.zig
@@ -0,0 +1,37 @@
+const std = @import("std");
+
+pub fn main(init: std.process.Init) !void {
+ const sources_dir = try std.Io.Dir.cwd().createDirPathOpen(init.io, "src", .{});
+ defer sources_dir.close(init.io);
+ const templates_dir = try sources_dir.createDirPathOpen(init.io, "templates", .{ .open_options = .{ .iterate = true } });
+ defer templates_dir.close(init.io);
+ const pages_dir = try sources_dir.createDirPathOpen(init.io, "pages", .{ .open_options = .{ .iterate = true } });
+ defer pages_dir.close(init.io);
+ const out_dir = try std.Io.Dir.cwd().createDirPathOpen(init.io, "html-out", .{});
+ defer out_dir.close(init.io);
+ const static_dir = try sources_dir.createDirPathOpen(init.io, "static", .{ .open_options = .{ .iterate = true } });
+ defer static_dir.close(init.io);
+
+ try copyStaticFiles(init.io, init.gpa, static_dir, out_dir);
+}
+
+fn copyStaticFiles(io: std.Io, ally: std.mem.Allocator, sources: std.Io.Dir, out: std.Io.Dir) !void {
+ var walker = try sources.walk(ally);
+ defer walker.deinit();
+ while (try walker.next(io)) |entry| {
+ switch (entry.kind) {
+ .file, .sym_link => {
+ std.debug.print("Copying static file {s}...\n", .{entry.basename});
+ try entry.dir.copyFile(entry.basename, out, entry.basename, io, .{});
+ },
+
+ .directory => {
+ const new_out = try out.createDirPathOpen(io, entry.basename, .{ .open_options = .{ .iterate = true } });
+ defer new_out.close(io);
+ try copyStaticFiles(io, ally, sources, out);
+ },
+
+ else => {},
+ }
+ }
+}