Recently, I have been interested in using Zig as a C build/test tool. With that in mind, I started a research project:
This might eventually evolve into a system management program and perhaps replace the Yoe Updater, which is written in shell.
The first step was to get it to build and link against a C library. We may or may not use D-Bus long-term, but this was a useful first step. Zig is still moving fast, so it took some work to create the build file. The last step (linking in libsystemd
) stumped me for a while, but the solution was simple once someone told me:
The resulting build file is:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const exe = b.addExecutable(.{
.name = "mgr",
.target = target,
});
exe.addCSourceFile(.{
.file = b.path("main.c"),
.flags = &[_][]const u8{},
});
exe.linkLibC();
exe.linkSystemLibrary("libsystemd");
b.installArtifact(exe);
}
Not bad ā¦
Thinking about the design of mgr
, some thoughts come to mind:
- use systemd as much as possible
systemd-repart
systemd-sysupdate
(although Iām not keen on A/B update systems)
- manage both factory init and updates
- integrate well with Simple IoT ā perhaps over D-Bus
- run as a daemon in a running system as well as PID0 in an initramfs.