@@ -26,7 +26,6 @@ pub fn build(b: *std.Build) !void {
2626 true
2727 else | err | switch (err ) {
2828 error .FileNotFound = > false ,
29- else = > return err ,
3029 };
3130
3231 const emit_bench = b .option (
@@ -41,25 +40,23 @@ pub fn build(b: *std.Build) !void {
4140 "Install the example binaries to zig-out" ,
4241 ) orelse false ;
4342
44- const c_api_module = b .createModule (.{
45- .root_source_file = b .path ("src/c_api.zig" ),
46- .target = target ,
47- .optimize = optimize ,
48- });
49-
5043 // Static C lib
5144 const static_lib : ? * Step.Compile = lib : {
5245 if (target .result .os .tag == .wasi ) break :lib null ;
5346
5447 const static_lib = b .addLibrary (.{
5548 .linkage = .static ,
5649 .name = "xev" ,
57- .root_module = c_api_module ,
50+ .root_module = b .createModule (.{
51+ .root_source_file = b .path ("src/c_api.zig" ),
52+ .target = target ,
53+ .optimize = optimize ,
54+ .link_libc = true ,
55+ }),
5856 });
59- static_lib .linkLibC ();
6057 if (target .result .os .tag == .windows ) {
61- static_lib .linkSystemLibrary ("ws2_32" );
62- static_lib .linkSystemLibrary ("mswsock" );
58+ static_lib .root_module . linkSystemLibrary ("ws2_32" , .{} );
59+ static_lib .root_module . linkSystemLibrary ("mswsock" , .{} );
6360 }
6461 break :lib static_lib ;
6562 };
@@ -72,7 +69,11 @@ pub fn build(b: *std.Build) !void {
7269 const dynamic_lib = b .addLibrary (.{
7370 .linkage = .dynamic ,
7471 .name = "xev" ,
75- .root_module = c_api_module ,
72+ .root_module = b .createModule (.{
73+ .root_source_file = b .path ("src/c_api.zig" ),
74+ .target = target ,
75+ .optimize = optimize ,
76+ }),
7677 });
7778 break :lib dynamic_lib ;
7879 };
@@ -119,20 +120,19 @@ pub fn build(b: *std.Build) !void {
119120 "test-filter" ,
120121 "Filter for test" ,
121122 );
122- const test_exe = b .addTest (.{
123+ break : test_exe b .addTest (.{
123124 .name = "xev-test" ,
124125 .filters = if (test_filter ) | filter | &.{filter } else &.{},
125126 .root_module = b .createModule (.{
126127 .root_source_file = b .path ("src/main.zig" ),
127128 .target = target ,
128129 .optimize = optimize ,
130+ .link_libc = switch (target .result .os .tag ) {
131+ .linux , .macos = > true ,
132+ else = > null ,
133+ },
129134 }),
130135 });
131- switch (target .result .os .tag ) {
132- .linux , .macos = > test_exe .linkLibC (),
133- else = > {},
134- }
135- break :test_exe test_exe ;
136136 };
137137
138138 // "test" Step
@@ -172,19 +172,24 @@ fn buildBenchmarks(
172172 b : * std.Build ,
173173 target : std.Build.ResolvedTarget ,
174174) ! []const * Step.Compile {
175+ const io = b .graph .io ;
175176 const alloc = b .allocator ;
176177 var steps : std .ArrayList (* Step .Compile ) = .empty ;
177178 defer steps .deinit (alloc );
178179
179- var dir = try std .fs .cwd ().openDir (try b .build_root .join (
180- b .allocator ,
181- &.{ "src" , "bench" },
182- ), .{ .iterate = true });
183- defer dir .close ();
180+ var dir = try std .Io .Dir .cwd ().openDir (
181+ io ,
182+ try b .build_root .join (
183+ b .allocator ,
184+ &.{ "src" , "bench" },
185+ ),
186+ .{ .iterate = true },
187+ );
188+ defer dir .close (io );
184189
185190 // Go through and add each as a step
186191 var it = dir .iterate ();
187- while (try it .next ()) | entry | {
192+ while (try it .next (io )) | entry | {
188193 // Get the index of the last '.' so we can strip the extension.
189194 const index = std .mem .lastIndexOfScalar (
190195 u8 ,
@@ -223,19 +228,24 @@ fn buildExamples(
223228 optimize : std.builtin.OptimizeMode ,
224229 c_lib_ : ? * Step.Compile ,
225230) ! []const * Step.Compile {
231+ const io = b .graph .io ;
226232 const alloc = b .allocator ;
227233 var steps : std .ArrayList (* Step .Compile ) = .empty ;
228234 defer steps .deinit (alloc );
229235
230- var dir = try std .fs .cwd ().openDir (try b .build_root .join (
231- b .allocator ,
232- &.{"examples" },
233- ), .{ .iterate = true });
234- defer dir .close ();
236+ var dir = try std .Io .Dir .cwd ().openDir (
237+ io ,
238+ try b .build_root .join (
239+ b .allocator ,
240+ &.{"examples" },
241+ ),
242+ .{ .iterate = true },
243+ );
244+ defer dir .close (io );
235245
236246 // Go through and add each as a step
237247 var it = dir .iterate ();
238- while (try it .next ()) | entry | {
248+ while (try it .next (io )) | entry | {
239249 // Get the index of the last '.' so we can strip the extension.
240250 const index = std .mem .lastIndexOfScalar (
241251 u8 ,
@@ -269,11 +279,11 @@ fn buildExamples(
269279 .root_module = b .createModule (.{
270280 .target = target ,
271281 .optimize = optimize ,
282+ .link_libc = true ,
272283 }),
273284 });
274- exe .linkLibC ();
275- exe .addIncludePath (b .path ("include" ));
276- exe .addCSourceFile (.{
285+ exe .root_module .addIncludePath (b .path ("include" ));
286+ exe .root_module .addCSourceFile (.{
277287 .file = b .path (b .fmt (
278288 "examples/{s}" ,
279289 .{entry .name },
@@ -286,7 +296,7 @@ fn buildExamples(
286296 "-D_POSIX_C_SOURCE=199309L" ,
287297 },
288298 });
289- exe .linkLibrary (c_lib );
299+ exe .root_module . linkLibrary (c_lib );
290300 break :exe exe ;
291301 };
292302
@@ -298,18 +308,20 @@ fn buildExamples(
298308}
299309
300310fn manPages (b : * std.Build ) ! []const * Step {
311+ const io = b .graph .io ;
301312 const alloc = b .allocator ;
302313 var steps : std .ArrayList (* Step ) = .empty ;
303314 defer steps .deinit (alloc );
304315
305- var dir = try std .fs .cwd ().openDir (try b .build_root .join (
306- b .allocator ,
307- &.{"docs" },
308- ), .{ .iterate = true });
309- defer dir .close ();
316+ var dir = try std .Io .Dir .cwd ().openDir (
317+ io ,
318+ try b .build_root .join (b .allocator , &.{"docs" }),
319+ .{ .iterate = true },
320+ );
321+ defer dir .close (io );
310322
311323 var it = dir .iterate ();
312- while (try it .next ()) | * entry | {
324+ while (try it .next (io )) | * entry | {
313325 // Filenames must end in "{section}.scd" and sections are
314326 // single numerals.
315327 const base = entry .name [0 .. entry .name .len - 4 ];
@@ -321,7 +333,7 @@ fn manPages(b: *std.Build) ![]const *Step {
321333 ) });
322334
323335 try steps .append (alloc , & b .addInstallFile (
324- cmd .captureStdOut (),
336+ cmd .captureStdOut (.{} ),
325337 b .fmt ("share/man/man{s}/{s}" , .{ section , base }),
326338 ).step );
327339 }
0 commit comments