11const std = @import ("std" );
22const builtin = @import ("builtin" );
33
4- // This has been tested to work with zig 0.11.0 (67709b6, Aug 4 2023)
4+ // This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
55fn add_module (comptime module : []const u8 , b : * std.Build , target : std.zig.CrossTarget , optimize : std.builtin.OptimizeMode ) ! * std.Build.Step {
66 if (target .getOsTag () == .emscripten ) {
77 @panic ("Emscripten building via Zig unsupported" );
@@ -11,7 +11,7 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
1111 const dir = try std .fs .cwd ().openIterableDir (module , .{});
1212 var iter = dir .iterate ();
1313 while (try iter .next ()) | entry | {
14- if (entry .kind != .file ) continue ;
14+ if (entry .kind != .File ) continue ;
1515 const extension_idx = std .mem .lastIndexOf (u8 , entry .name , ".c" ) orelse continue ;
1616 const name = entry .name [0.. extension_idx ];
1717 const path = try std .fs .path .join (b .allocator , &.{ module , entry .name });
@@ -24,26 +24,26 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
2424 .target = target ,
2525 .optimize = optimize ,
2626 });
27- exe .addCSourceFile (.{ . file = .{ . path = path }, . flags = &.{} });
27+ exe .addCSourceFile (path , &[ _ ][] const u8 { });
2828 exe .linkLibC ();
2929 exe .addObjectFile (switch (target .getOsTag ()) {
30- .windows = > .{ . path = "../src/zig-out/lib/raylib.lib" } ,
31- .linux = > .{ . path = "../src/zig-out/lib/libraylib.a" } ,
32- .macos = > .{ . path = "../src/zig-out/lib/libraylib.a" } ,
33- .emscripten = > .{ . path = "../src/zig-out/lib/libraylib.a" } ,
30+ .windows = > "../src/zig-out/lib/raylib.lib" ,
31+ .linux = > "../src/zig-out/lib/libraylib.a" ,
32+ .macos = > "../src/zig-out/lib/libraylib.a" ,
33+ .emscripten = > "../src/zig-out/lib/libraylib.a" ,
3434 else = > @panic ("Unsupported OS" ),
3535 });
3636
37- exe .addIncludePath (.{ . path = "../src" } );
38- exe .addIncludePath (.{ . path = "../src/external" } );
39- exe .addIncludePath (.{ . path = "../src/external/glfw/include" } );
37+ exe .addIncludePath ("../src" );
38+ exe .addIncludePath ("../src/external" );
39+ exe .addIncludePath ("../src/external/glfw/include" );
4040
4141 switch (target .getOsTag ()) {
4242 .windows = > {
4343 exe .linkSystemLibrary ("winmm" );
4444 exe .linkSystemLibrary ("gdi32" );
4545 exe .linkSystemLibrary ("opengl32" );
46- exe .addIncludePath (.{ . path = "external/glfw/deps/mingw" } );
46+ exe .addIncludePath ("external/glfw/deps/mingw" );
4747
4848 exe .defineCMacro ("PLATFORM_DESKTOP" , null );
4949 },
@@ -71,15 +71,11 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
7171 },
7272 }
7373
74- const install_cmd = b .addInstallArtifact (exe , .{});
75-
76- const run_cmd = b .addRunArtifact (exe );
77- run_cmd .step .dependOn (& install_cmd .step );
78-
79- const run_step = b .step (name , name );
80- run_step .dependOn (& run_cmd .step );
81-
82- all .dependOn (& install_cmd .step );
74+ b .installArtifact (exe );
75+ var run = b .addRunArtifact (exe );
76+ run .cwd = module ;
77+ b .step (name , name ).dependOn (& run .step );
78+ all .dependOn (& exe .step );
8379 }
8480 return all ;
8581}
0 commit comments