-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
105 lines (88 loc) · 3.46 KB
/
build.zig
File metadata and controls
105 lines (88 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const std = @import("std");
const fs = std.fs;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create a module for the core library.
const zigformer_mod = b.addModule("zigformer", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
// Create an options artifact for compile-time configuration.
const config_options = b.addOptions();
config_options.addOption(usize, "embedding_dim", 128);
config_options.addOption(usize, "hidden_dim", 256);
config_options.addOption(usize, "max_seq_len", 80);
config_options.addOption(usize, "num_heads", 4);
// Add the options to the library module under the name "config".
zigformer_mod.addOptions("config", config_options);
// Create the main command-line executable's module.
const cli_module = b.addModule("cli", .{
.root_source_file = b.path("src/cli.zig"),
.target = target,
.optimize = optimize,
});
cli_module.addImport("zigformer", zigformer_mod);
// Wire Chilli dependency into the CLI module
const chilli_dep = b.dependency("chilli", .{});
const chilli_module = chilli_dep.module("chilli");
cli_module.addImport("chilli", chilli_module);
// Create the executable artifact from the module.
const exe = b.addExecutable(.{
.name = "zigformer-cli",
.root_module = cli_module,
});
b.installArtifact(exe);
// Create the GUI executable
const gui_module = b.addModule("gui", .{
.root_source_file = b.path("src/gui.zig"),
.target = target,
.optimize = optimize,
});
gui_module.addImport("zigformer", zigformer_mod);
gui_module.addImport("chilli", chilli_module);
const gui_exe = b.addExecutable(.{
.name = "zigformer-gui",
.root_module = gui_module,
});
b.installArtifact(gui_exe);
// Create a "run-gui" step
const run_gui_cmd = b.addRunArtifact(gui_exe);
run_gui_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_gui_cmd.addArgs(args);
}
const run_gui_step = b.step("run-gui", "Run the GUI application");
run_gui_step.dependOn(&run_gui_cmd.step);
// Create a "run" step to execute the application.
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 application");
run_step.dependOn(&run_cmd.step);
// Create the test executable.
const test_exe = b.addExecutable(.{
.name = "zigformer-tests",
.root_module = zigformer_mod, // The tests are part of the library module.
});
test_exe.kind = .@"test";
// Create a "test" step to run the unit tests.
const test_run_cmd = b.addRunArtifact(test_exe);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&test_run_cmd.step);
// --- Docs Setup ---
const docs_step = b.step("docs", "Generate API documentation");
const doc_install_path = "zig-out/docs";
// Create docs directory if it doesn't exist (portable across all platforms)
fs.cwd().makePath(doc_install_path) catch {};
const gen_docs_cmd = b.addSystemCommand(&[_][]const u8{
b.graph.zig_exe,
"build-lib",
"src/lib.zig",
"-femit-docs=" ++ doc_install_path,
});
docs_step.dependOn(&gen_docs_cmd.step);
}