zellzig/build.zig

53 lines
1.5 KiB
Zig

const std = @import("std");
const pkgs = @import("deps.zig").pkgs;
pub fn build(b: *std.build.Builder) !void {
const docs = b.option(bool, "docs", "emit docs") orelse false;
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("zellzig", "src/main.zig");
lib.setBuildMode(mode);
lib.target.cpu_arch = .wasm32;
lib.target.os_tag = .wasi;
pkgs.addAllTo(lib);
if (docs) {
lib.emit_docs = .{ .emit_to = "zig-out/docs" };
const create_out_step = try b.allocator.create(std.build.Step);
create_out_step.* = CreateZigOutStep.step(b.allocator);
lib.step.dependOn(create_out_step);
}
lib.install();
const main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
pkgs.addAllTo(main_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
}
/// A step to create the zig-out directory for documentation.
const CreateZigOutStep = struct {
pub fn step(ally: std.mem.Allocator) std.build.Step {
return std.build.Step.init(
.custom,
"Create zig-out",
ally,
&make,
);
}
fn make(_: *std.build.Step) anyerror!void {
// TODO: don't hardcode zig-out
std.fs.cwd().makeDir("zig-out") catch |e| {
if (e != error.PathAlreadyExists)
return e;
};
}
};