Something went wrong. Try again.
A Zig library for writing structured log messages directly to the systemd journal over its native datagram socket.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137// SPDX-FileCopyrightText: © 2024 Jeffrey C. Ollie <jeff@ocjtech.us>//// SPDX-License-Identifier: MIT
const std = @import("std");
pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{});
const module = b.addModule( "journalz", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, }, );
const unit_tests = b.addTest( .{ .root_module = module, }, );
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_unit_tests.step);
// Logs a known set of entries to the journal of whatever machine it runs // on. Nothing in `zig build test` runs it -- it needs a real journald -- // so it is the NixOS check in tests/nixos that gives it a machine. const e2e = b.addExecutable( .{ .name = "journalz-e2e", .root_module = b.createModule( .{ .root_source_file = b.path("tests/e2e.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "journalz", .module = module }, }, }, ), }, );
b.installArtifact(e2e);
// Points `std.log` at the journal. Built so that it cannot rot, installed // so that the NixOS check can run it against a real journald. const example = b.addExecutable( .{ .name = "journalz-example-std-log", .root_module = b.createModule( .{ .root_source_file = b.path("examples/std_log.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "journalz", .module = module }, }, }, ), }, );
b.installArtifact(example);
const check_step = b.step("check", "Check if journalz compiles"); check_step.dependOn(&unit_tests.step); check_step.dependOn(&e2e.step); check_step.dependOn(&example.step);
// Zig writes the documentation out as a side effect of compiling, so the // module is built as a library purely to get at it. What comes out is not // a page but a program: a WebAssembly viewer, its javascript, and a tar // of the sources it reads from. const library = b.addLibrary( .{ .name = "journalz", .root_module = module, }, );
const install_docs = b.addInstallDirectory( .{ .source_dir = library.getEmittedDocs(), .install_dir = .prefix, .install_subdir = "docs", }, );
const docs_step = b.step("docs", "Build the API documentation into zig-out/docs"); docs_step.dependOn(&install_docs.step);
// The viewer fetches sources.tar and main.wasm at runtime, which a // browser refuses to do from a `file://` page, so reading the docs // locally means serving them. const docs_port = b.option(u16, "docs-port", "Port for `zig build docs-serve` (default 8000)") orelse 8000;
const docs_server = b.addExecutable( .{ .name = "docs-server", .root_module = b.createModule( .{ .root_source_file = b.path("tools/docs_server.zig"), // Always the machine running the build, never whatever // -Dtarget the library is being built for. .target = b.graph.host, .optimize = .Debug, }, ), }, );
const run_docs_server = b.addRunArtifact(docs_server); run_docs_server.step.dependOn(&install_docs.step); run_docs_server.addDirectoryArg(library.getEmittedDocs()); run_docs_server.addArg(b.fmt("{d}", .{docs_port})); // It runs until interrupted, so its output has to reach the terminal // rather than being captured by the build runner. run_docs_server.stdio = .inherit;
const docs_serve_step = b.step("docs-serve", "Serve the API documentation over HTTP"); docs_serve_step.dependOn(&run_docs_server.step);
// The documentation server has a test of its own, and nothing else builds // it, so without these it could stop compiling and no test would notice. test_step.dependOn(&b.addRunArtifact( b.addTest(.{ .root_module = docs_server.root_module }), ).step); check_step.dependOn(&docs_server.step);}