Skip to content

Commit

Permalink
Fix the type mismatch caused due to unsupported ?[]const u8 (raysan…
Browse files Browse the repository at this point in the history
…5#4383)

Co-authored-by: Yuval Herman <[email protected]>
  • Loading branch information
2 people authored and psxdev committed Nov 18, 2024
1 parent b838644 commit 60d29f0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn addRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
.shared = options.shared,
.linux_display_backend = options.linux_display_backend,
.opengl_version = options.opengl_version,
// TODO: Fix the type mismatch caused here due to unsupported `?[]const u8`.
.config = options.config,
});
const raylib = raylib_dep.artifact("raylib");
Expand Down Expand Up @@ -86,7 +85,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
});
if (options.config) |config| {
if (options.config.len > 0) {
const file = b.pathJoin(&.{ srcDir(b), "config.h" });
const content = try std.fs.cwd().readFileAlloc(b.allocator, file, std.math.maxInt(usize));
defer b.allocator.free(content);
Expand All @@ -104,14 +103,14 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
flag = try std.fmt.allocPrint(b.allocator, "-D{s}", .{flag}); // Prepend with -D

// If user specifies the flag skip it
if (std.mem.containsAtLeast(u8, config, 1, flag)) continue;
if (std.mem.containsAtLeast(u8, options.config, 1, flag)) continue;

// Append default value from config.h to compile flags
try raylib_flags_arr.append(b.allocator, flag);
}

// Append config flags supplied by user to compile flags
try raylib_flags_arr.append(b.allocator, config);
try raylib_flags_arr.append(b.allocator, options.config);

try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
}
Expand Down Expand Up @@ -321,7 +320,7 @@ pub const Options = struct {
linux_display_backend: LinuxDisplayBackend = .Both,
opengl_version: OpenglVersion = .auto,
/// config should be a list of cflags, eg, "-DSUPPORT_CUSTOM_FRAME_CONTROL"
config: ?[]const u8 = null,
config: []const u8 = &.{},

raygui_dependency_name: []const u8 = "raygui",
};
Expand Down Expand Up @@ -384,7 +383,7 @@ pub fn build(b: *std.Build) !void {
.shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h"),
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{},
};

const lib = try compileRaylib(b, target, optimize, options);
Expand Down

0 comments on commit 60d29f0

Please sign in to comment.