Skip to content

Commit 540ad99

Browse files
authored
Update zig build system to zig version 0.11.0 (#3393)
* update build.zig for zig 0.11.0 * fix build.zig in examples to install executable correctly * discard build.zig, only use src/build.zig, to avoid annoying zig-out path problem * update zig version note
1 parent cfffa74 commit 540ad99

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

build.zig

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/build.zig

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33

4-
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
4+
// This has been tested to work with zig 0.11.0 (67709b6, Aug 4 2023)
55
fn 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(path, &[_][]const u8{});
27+
exe.addCSourceFile(.{ .file = .{ .path = path }, .flags = &.{} });
2828
exe.linkLibC();
2929
exe.addObjectFile(switch (target.getOsTag()) {
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",
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" },
3434
else => @panic("Unsupported OS"),
3535
});
3636

37-
exe.addIncludePath("../src");
38-
exe.addIncludePath("../src/external");
39-
exe.addIncludePath("../src/external/glfw/include");
37+
exe.addIncludePath(.{ .path = "../src" });
38+
exe.addIncludePath(.{ .path = "../src/external" });
39+
exe.addIncludePath(.{ .path = "../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("external/glfw/deps/mingw");
46+
exe.addIncludePath(.{ .path = "external/glfw/deps/mingw" });
4747

4848
exe.defineCMacro("PLATFORM_DESKTOP", null);
4949
},
@@ -71,11 +71,15 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
7171
},
7272
}
7373

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);
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);
7983
}
8084
return all;
8185
}

src/build.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22

3-
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
3+
// This has been tested to work with zig 0.11.0 (67709b6, Aug 4 2023)
44
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep {
55
const raylib_flags = &[_][]const u8{
66
"-std=gnu99",
@@ -192,12 +192,12 @@ pub fn build(b: *std.Build) void {
192192

193193
const lib = addRaylib(b, target, optimize, options);
194194

195-
lib.installHeader("src/raylib.h", "raylib.h");
196-
lib.installHeader("src/raymath.h", "raymath.h");
197-
lib.installHeader("src/rlgl.h", "rlgl.h");
195+
lib.installHeader("raylib.h", "raylib.h");
196+
lib.installHeader("raymath.h", "raymath.h");
197+
lib.installHeader("rlgl.h", "rlgl.h");
198198

199199
if (options.raygui) {
200-
lib.installHeader("../raygui/src/raygui.h", "raygui.h");
200+
lib.installHeader("../../raygui/src/raygui.h", "raygui.h");
201201
}
202202

203203
b.installArtifact(lib);

0 commit comments

Comments
 (0)