-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
230 lines (185 loc) · 7.9 KB
/
build.zig
File metadata and controls
230 lines (185 loc) · 7.9 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Dependencies - manually add zig-config from local path
const zig_config_path = "../zig-config/src/zig-config.zig";
const zig_config_mod = b.addModule("zig_config", .{
.root_source_file = b.path(zig_config_path),
.target = target,
.optimize = optimize,
});
// Library module
const crosswind_lib = b.addModule("crosswind", .{
.root_source_file = b.path("src/crosswind.zig"),
});
// Add zig-config as a dependency
crosswind_lib.addImport("zig_config", zig_config_mod);
// Executable (CLI)
const exe = b.addExecutable(.{
.name = "crosswind",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("crosswind", crosswind_lib);
exe.root_module.addImport("zig_config", zig_config_mod);
b.installArtifact(exe);
// Run command
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 CLI");
run_step.dependOn(&run_cmd.step);
// Tests
const lib_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/crosswind.zig"),
.target = target,
.optimize = optimize,
}),
});
lib_tests.root_module.addImport("zig_config", zig_config_mod);
const run_lib_tests = b.addRunArtifact(lib_tests);
// Comprehensive test suite
const comprehensive_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/test_runner.zig"),
.target = target,
.optimize = optimize,
}),
});
comprehensive_tests.root_module.addImport("zig_config", zig_config_mod);
comprehensive_tests.root_module.addImport("crosswind", crosswind_lib);
const run_comprehensive_tests = b.addRunArtifact(comprehensive_tests);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(&run_lib_tests.step);
test_step.dependOn(&run_comprehensive_tests.step);
// Benchmarks
const bench = b.addExecutable(.{
.name = "benchmark",
.root_module = b.createModule(.{
.root_source_file = b.path("test/benchmark.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
bench.root_module.addImport("crosswind", crosswind_lib);
const run_bench = b.addRunArtifact(bench);
const bench_step = b.step("bench", "Run benchmarks");
bench_step.dependOn(&run_bench.step);
// Format check
const fmt_check = b.addFmt(.{
.paths = &.{ "src", "test" },
.check = true,
});
const fmt_step = b.step("fmt", "Check formatting");
fmt_step.dependOn(&fmt_check.step);
// Cross-compilation build system
// Define all target platforms with proper naming
const CrossTarget = struct {
query: std.Target.Query,
name: []const u8,
extension: []const u8,
};
const cross_targets = [_]CrossTarget{
.{ .query = .{ .cpu_arch = .x86_64, .os_tag = .linux }, .name = "linux-x86_64", .extension = "" },
.{ .query = .{ .cpu_arch = .aarch64, .os_tag = .linux }, .name = "linux-aarch64", .extension = "" },
.{ .query = .{ .cpu_arch = .x86_64, .os_tag = .macos }, .name = "macos-x86_64", .extension = "" },
.{ .query = .{ .cpu_arch = .aarch64, .os_tag = .macos }, .name = "macos-arm64", .extension = "" },
.{ .query = .{ .cpu_arch = .x86_64, .os_tag = .windows }, .name = "windows-x86_64", .extension = ".exe" },
};
// Create individual build steps for each platform
inline for (cross_targets) |cross_target| {
const platform_step = b.step("build-" ++ cross_target.name, "Build for " ++ cross_target.name);
const cross_exe = b.addExecutable(.{
.name = "crosswind",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(cross_target.query),
.optimize = .ReleaseFast,
}),
});
cross_exe.root_module.addImport("crosswind", crosswind_lib);
cross_exe.root_module.addImport("zig_config", zig_config_mod);
// Static linking only for Linux and Windows (macOS doesn't support static libc)
if (cross_target.query.os_tag == .linux or cross_target.query.os_tag == .windows) {
cross_exe.linkage = .static;
}
// Strip debug symbols in release builds
cross_exe.root_module.strip = true;
// Install to platform-specific directory
const install_cross = b.addInstallArtifact(cross_exe, .{
.dest_dir = .{
.override = .{
.custom = "dist/" ++ cross_target.name,
},
},
});
platform_step.dependOn(&install_cross.step);
}
// Build all platforms
const build_all_step = b.step("build-all", "Build for all platforms (Linux x86_64/aarch64, macOS x86_64/arm64, Windows x86_64)");
inline for (cross_targets) |cross_target| {
const cross_exe = b.addExecutable(.{
.name = "crosswind",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(cross_target.query),
.optimize = .ReleaseFast,
}),
});
cross_exe.root_module.addImport("crosswind", crosswind_lib);
cross_exe.root_module.addImport("zig_config", zig_config_mod);
// Static linking only for Linux and Windows
if (cross_target.query.os_tag == .linux or cross_target.query.os_tag == .windows) {
cross_exe.linkage = .static;
}
cross_exe.root_module.strip = true;
const install_cross = b.addInstallArtifact(cross_exe, .{
.dest_dir = .{
.override = .{
.custom = "dist/" ++ cross_target.name,
},
},
});
build_all_step.dependOn(&install_cross.step);
}
// Legacy cross-compilation step (for compatibility)
const cross_step = b.step("cross", "Build for all platforms (alias for build-all)");
cross_step.dependOn(build_all_step);
// Release build with all optimizations
const release_step = b.step("release", "Build optimized release binary for current platform");
const release_exe = b.addExecutable(.{
.name = "crosswind",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
release_exe.root_module.addImport("crosswind", crosswind_lib);
release_exe.root_module.addImport("zig_config", zig_config_mod);
release_exe.root_module.strip = true;
const install_release = b.addInstallArtifact(release_exe, .{});
release_step.dependOn(&install_release.step);
// Small size optimized build
const release_small_step = b.step("release-small", "Build size-optimized release binary");
const release_small_exe = b.addExecutable(.{
.name = "crosswind",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .ReleaseSmall,
}),
});
release_small_exe.root_module.addImport("crosswind", crosswind_lib);
release_small_exe.root_module.addImport("zig_config", zig_config_mod);
release_small_exe.root_module.strip = true;
const install_release_small = b.addInstallArtifact(release_small_exe, .{});
release_small_step.dependOn(&install_release_small.step);
}