-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
140 lines (122 loc) · 4.96 KB
/
build.zig
File metadata and controls
140 lines (122 loc) · 4.96 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// ── Export for downstream consumers ──────────────────────────
// Pure Zig library — downstream users just call:
// const zigen = b.dependency("zigen", .{}).module("zigen");
// exe.root_module.addImport("zigen", zigen);
const zigen_mod = b.addModule("zigen", .{
.root_source_file = b.path("src/zigen.zig"),
});
// ── Export for downstream consumers ──────────────────────────
// Create inline src tests
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/zigen.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run all tests (src + unit + integration)");
test_step.dependOn(&run_tests.step);
// Unit test step
const unit_test_step = b.step("unit-test", "Run unit tests only");
// Unit test files
const unit_test_files = [_][]const u8{
"test/unit/core_test.zig",
"test/unit/dynamic_test.zig",
"test/unit/array_test.zig",
"test/unit/decomposition_test.zig",
"test/unit/geometry_test.zig",
"test/unit/sparse_test.zig",
"test/unit/utility_test.zig",
"test/unit/npy_test.zig",
};
inline for (unit_test_files) |test_file| {
const unit_test = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path(test_file),
.target = target,
.optimize = optimize,
}),
});
unit_test.root_module.addImport("zigen", zigen_mod);
const run_unit = b.addRunArtifact(unit_test);
unit_test_step.dependOn(&run_unit.step);
test_step.dependOn(&run_unit.step);
}
// Integration tests
const integration_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/integration/integration_test.zig"),
.target = target,
.optimize = optimize,
}),
});
integration_tests.root_module.addImport("zigen", zigen_mod);
const run_integration = b.addRunArtifact(integration_tests);
test_step.dependOn(&run_integration.step);
// Separate steps
const integration_step = b.step("integration-test", "Run integration tests only");
integration_step.dependOn(&run_integration.step);
// Create example programs
const examples = [_][]const u8{
"basic_matrix",
"matrix_operations",
"linear_algebra",
"geometry",
"sparse_systems",
"data_analysis",
"image_processing",
"iterative_solvers",
"dynamic_decompositions",
};
inline for (examples) |example_name| {
const example = b.addExecutable(.{
.name = example_name,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
.target = target,
.optimize = optimize,
}),
});
example.root_module.addImport("zigen", zigen_mod);
const install_example = b.addInstallArtifact(example, .{});
const example_step = b.step(
b.fmt("example-{s}", .{example_name}),
b.fmt("Build and install {s} example", .{example_name}),
);
example_step.dependOn(&install_example.step);
const run_example = b.addRunArtifact(example);
const run_example_step = b.step(
b.fmt("run-{s}", .{example_name}),
b.fmt("Run {s} example", .{example_name}),
);
run_example_step.dependOn(&run_example.step);
}
// Benchmark
const precision = b.option([]const u8, "precision", "Float precision: f32 or f64") orelse "f64";
const bench = b.addExecutable(.{
.name = "benchmark",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/benchmark_zigen.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
bench.root_module.addImport("zigen", zigen_mod);
// Add build options for precision configuration
const build_options = b.addOptions();
build_options.addOption([]const u8, "precision", precision);
bench.root_module.addImport("build_options", build_options.createModule());
// Install benchmark executable
const install_bench = b.addInstallArtifact(bench, .{});
const install_bench_step = b.step("install-bench", "Build and install benchmark");
install_bench_step.dependOn(&install_bench.step);
// Run benchmark
const run_bench = b.addRunArtifact(bench);
const bench_step = b.step("bench", "Run benchmark");
bench_step.dependOn(&run_bench.step);
}