Skip to content

Commit a7ea481

Browse files
committed
Fix build for Zig 0.18.0-dev.252+86dc5ce25
Zig 0.18.0-dev changed `standardOptimizeOption` to return an optional. `optimize` will now be optional for older versions of Zig as well. See: https://codeberg.org/ziglang/zig/pulls/36108
1 parent 783a1c7 commit a7ea481

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎build.zig‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ pub fn build(b: *std.Build) !void {
3333
// Get the upstream source and build options
3434
const upstream = b.dependency("sdl", .{});
3535
const target = b.standardTargetOptions(.{});
36-
const optimize = b.standardOptimizeOption(.{});
36+
// Coercing to an optional makes the value consistent across multiple versions of Zig.
37+
// TODO: Remove explicit type annotation when Zig 0.18.0 is the minimum supported version.
38+
const optimize: ?std.builtin.OptimizeMode = b.standardOptimizeOption(.{});
3739

3840
const default_target_config = b.option(
3941
bool,
@@ -119,7 +121,7 @@ pub fn build(b: *std.Build) !void {
119121
// safe added.
120122
// https://wiki.libsdl.org/SDL3/SDL_ASSERT_LEVEL
121123
.SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED = true,
122-
.SDL_DEFAULT_ASSERT_LEVEL = @as(u2, switch (optimize) {
124+
.SDL_DEFAULT_ASSERT_LEVEL = @as(u2, switch (optimize orelse std.builtin.OptimizeMode.Debug) {
123125
.Debug, .ReleaseSafe => 2,
124126
.ReleaseSmall, .ReleaseFast => 1,
125127
}),
@@ -146,7 +148,7 @@ pub fn build(b: *std.Build) !void {
146148
const translate_c = b.addTranslateC(.{
147149
.root_source_file = b.path("src/sdl.h"),
148150
.target = target,
149-
.optimize = optimize,
151+
.optimize = optimize orelse std.builtin.OptimizeMode.Debug,
150152
});
151153
translate_c.defineCMacro("USING_GENERATED_CONFIG_H", "1");
152154
translate_c.addIncludePath(upstream.path("include"));

0 commit comments

Comments
 (0)