update examples/build.zig and add nicer message for type mismatch

This commit is contained in:
freakmangd 2024-01-08 23:16:37 -05:00
commit 1184469026

View file

@ -3,10 +3,16 @@ const builtin = @import("builtin");
// This has been tested to work with zig 0.11.0 and zig 0.12.0-dev.2075+f5978181e
//
// anytype is used here for target because in 0.12.0dev the std.zig.CrossTarget type
// 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 types and act accordingly in getOsTagVersioned
// 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",