build.zig: trip over the finish line for becoming a module

It's pretty easy. This is the first step to spinning zed off as a
separate project, which has been the plan for a while now.
This commit is contained in:
torque 2023-06-01 22:35:12 -07:00
parent 06a01dad6b
commit 18379cf86c
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -1,12 +1,14 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.build.Builder) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target: std.Build.CrossTarget = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize: std.builtin.Mode = b.standardOptimizeOption(.{});
demo(b, target, optimize); const noclip = b.addModule("noclip", .{
tokenator(b, target, optimize); .source_file = .{ .path = "source/noclip.zig" }
zed(b, target, optimize); });
demo(b, noclip, target, optimize);
const test_step = b.step("test", "Run unit tests"); const test_step = b.step("test", "Run unit tests");
const tests = b.addTest(.{ const tests = b.addTest(.{
@ -19,9 +21,8 @@ pub fn build(b: *std.build.Builder) void {
test_step.dependOn(&tests.step); test_step.dependOn(&tests.step);
} }
fn demo(b: *std.build.Builder, target: anytype, optimize: anytype) void { fn demo(b: *std.Build, noclip: *std.Build.Module, target: std.Build.CrossTarget, optimize: std.builtin.Mode) void {
const demo_step = b.step("demo", "Build and install CLI demo program"); const demo_step = b.step("demo", "Build and install CLI demo program");
const noclip = b.createModule(.{ .source_file = .{ .path = "source/noclip.zig" } });
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "noclip-demo", .name = "noclip-demo",
@ -34,46 +35,3 @@ fn demo(b: *std.build.Builder, target: anytype, optimize: anytype) void {
demo_step.dependOn(&install_demo.step); demo_step.dependOn(&install_demo.step);
} }
fn tokenator(b: *std.build.Builder, target: anytype, optimize: anytype) void {
const tok_step = b.step("tokenator", "Build documentation tokenizer");
const noclip = b.createModule(.{ .source_file = .{ .path = "source/noclip.zig" } });
const exe = b.addExecutable(.{
.name = "tokenator",
.root_source_file = .{ .path = "documentation/tokenator.zig" },
.target = target,
.optimize = optimize,
});
exe.addModule("noclip", noclip);
const install_tok = b.addInstallArtifact(exe);
tok_step.dependOn(&install_tok.step);
}
fn zed(b: *std.build.Builder, target: anytype, optimize: anytype) void {
const tok_step = b.step("zed", "Build documentation generator");
const noclip = b.createModule(.{ .source_file = .{ .path = "source/noclip.zig" } });
const exe = b.addExecutable(.{
.name = "zed",
.root_source_file = .{ .path = "documentation/zed.zig" },
.target = target,
.optimize = optimize,
});
exe.addModule("noclip", noclip);
const install_tok = b.addInstallArtifact(exe);
tok_step.dependOn(&install_tok.step);
const test_step = b.step("run-zed-tests", "Test documentation generator");
const tests = b.addTest(.{
.name = "test-zed",
.root_source_file = .{ .path = "documentation/zed.zig" },
.target = target,
.optimize = optimize,
});
const runcmd = b.addRunArtifact(tests);
test_step.dependOn(&runcmd.step);
}