Write documentation

This commit is contained in:
Dominic Grimm 2025-06-01 19:40:58 +02:00
parent c9c2b45b2a
commit 8967477f39
Signed by: dergrimm
SSH key fingerprint: SHA256:0uoWpcqOtkyvQ+ZqBjNYiDqIZY+9s8VeZkkJ/4ryB4E
11 changed files with 122 additions and 21 deletions

View file

@ -6,30 +6,48 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const material_max_len = b.option(
usize,
"material-max-len",
"Maximum length a material name can have",
) orelse material_max_len_default;
const lib_options = b.addOptions();
lib_options.addOption(usize, "material_max_len", material_max_len);
// comptime config options
const lib_options = blk: {
const material_max_len = b.option(
usize,
"material-max-len",
"Maximum length a material name can have",
) orelse material_max_len_default;
const options = b.addOptions();
options.addOption(usize, "material_max_len", material_max_len);
break :blk options;
};
const zap_dep = b.dependency("zap", .{ .openssl = false });
const clap_dep = b.dependency("clap", .{});
const lib_mod = b.addModule("craftflut", .{
.root_source_file = b.path("src/root.zig"),
});
lib_mod.addOptions("build_options", lib_options);
lib_mod.addImport("zap", zap_dep.module("zap"));
// craftflut library
const lib_mod = blk: {
const mod = b.addModule("craftflut", .{
.root_source_file = b.path("src/root.zig"),
});
mod.addOptions("build_options", lib_options);
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addImport("craftflut", lib_mod);
exe_mod.addImport("clap", clap_dep.module("clap"));
mod.addImport("zap", zap_dep.module("zap"));
break :blk mod;
};
// craftflut executable
const exe_mod = blk: {
const mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
mod.addImport("craftflut", lib_mod);
mod.addImport("clap", clap_dep.module("clap"));
break :blk mod;
};
const exe = b.addExecutable(.{
.name = "craftflut",
@ -37,12 +55,32 @@ pub fn build(b: *std.Build) void {
});
b.installArtifact(exe);
// run step
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);
// const lib_unit_tests = b.addTest(.{
// .root_module = lib_mod,
// });
// const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
// const exe_unit_tests = b.addTest(.{
// .root_module = exe_mod,
// });
// const run_exe_unit_tests = b.addRunArtifact(exe_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_lib_unit_tests.step);
// test_step.dependOn(&run_exe_unit_tests.step);
}