diff options
| author | freakmangd <[email protected]> | 2024-01-11 13:48:37 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-11 19:48:37 +0100 |
| commit | 482722d881e98d84773af97838b6604331ae5538 (patch) | |
| tree | f392228ca9b0aa5d82f3d2c4ee3bd8956a74ff05 /src/build.zig | |
| parent | a820c37ab284279230c51a57306e64ad70e7d344 (diff) | |
| download | raylib-482722d881e98d84773af97838b6604331ae5538.tar.gz raylib-482722d881e98d84773af97838b6604331ae5538.zip | |
Update to latest zig 0.12.0dev while keeping 0.11.0 compatibility (#3715)
* update build.zig for latest zig 0.12.0dev while still allowing 0.11.0
* update examples/build.zig and add nicer message for type mismatch
Diffstat (limited to 'src/build.zig')
| -rw-r--r-- | src/build.zig | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/build.zig b/src/build.zig index a574ad63..e0fc53fe 100644 --- a/src/build.zig +++ b/src/build.zig @@ -1,8 +1,18 @@ const std = @import("std"); const builtin = @import("builtin"); -// This has been tested to work with zig 0.11.0 and zig 0.12.0-dev.1390+94cee4fb2 -pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep { +// This has been tested to work with zig 0.11.0 and zig 0.12.0-dev.2075+f5978181e +// +// anytype is used here to preserve compatibility, in 0.12.0dev the std.zig.CrossTarget type +// was reworked into std.Target.Query and std.Build.ResolvedTarget. Using anytype allows +// us to accept both CrossTarget and ResolvedTarget and act accordingly in getOsTagVersioned. +pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.Step.Compile { + if (comptime builtin.zig_version.minor >= 12 and @TypeOf(target) != std.Build.ResolvedTarget) { + @compileError("Expected 'std.Build.ResolvedTarget' for argument 2 'target' in 'addRaylib', found '" ++ @typeName(@TypeOf(target)) ++ "'"); + } else if (comptime builtin.zig_version.minor == 11 and @TypeOf(target) != std.zig.CrossTarget) { + @compileError("Expected 'std.zig.CrossTarget' for argument 2 'target' in 'addRaylib', found '" ++ @typeName(@TypeOf(target)) ++ "'"); + } + const raylib_flags = &[_][]const u8{ "-std=gnu99", "-D_GNU_SOURCE", @@ -68,7 +78,7 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built raylib.addIncludePath(.{ .path = srcdir ++ "/../../raygui/src" }); } - switch (target.getOsTag()) { + switch (getOsTagVersioned(target)) { .windows => { addCSourceFilesVersioned(raylib, &.{ srcdir ++ "/rglfw.c", @@ -219,6 +229,14 @@ const srcdir = struct { } }.getSrcDir(); +fn getOsTagVersioned(target: anytype) std.Target.Os.Tag { + if (comptime builtin.zig_version.minor >= 12) { + return target.result.os.tag; + } else { + return target.getOsTag(); + } +} + fn addCSourceFilesVersioned(exe: *std.Build.Step.Compile, files: []const []const u8, flags: []const []const u8) void { if (comptime builtin.zig_version.minor >= 12) { exe.addCSourceFiles(.{ |
