Skip to content

Commit 1d1b398

Browse files
committed
build.zig: Use std.Build.Module.addCMacro for config flags
1 parent e16d5eb commit 1d1b398

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

build.zig

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
134134
"-DGL_SILENCE_DEPRECATION=199309L",
135135
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
136136
});
137+
138+
if (options.shared) {
139+
try raylib_flags_arr.appendSlice(b.allocator, shared_flags);
140+
}
141+
142+
const raylib = if (options.shared)
143+
b.addSharedLibrary(.{
144+
.name = "raylib",
145+
.target = target,
146+
.optimize = optimize,
147+
})
148+
else
149+
b.addStaticLibrary(.{
150+
.name = "raylib",
151+
.target = target,
152+
.optimize = optimize,
153+
});
154+
raylib.linkLibC();
155+
137156
if (options.config.len > 0) {
138157
// Sets a flag indiciating the use of a custom `config.h`
139158
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
@@ -171,32 +190,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
171190
if (u_flag_stripped.len == flag.len or u_flag_stripped[flag.len] == '=') continue :outer;
172191
}
173192

174-
// Otherwise, append default value from config.h to compile flags
175-
try raylib_flags_arr.append(
176-
b.allocator,
177-
b.fmt("-D{s}={s}", .{ flag, value }),
178-
);
193+
// Otherwise, apply the default values from config.h
194+
raylib.root_module.addCMacro(flag, value);
179195
}
180196
}
181197

182-
if (options.shared) {
183-
try raylib_flags_arr.appendSlice(b.allocator, shared_flags);
184-
}
185-
186-
const raylib = if (options.shared)
187-
b.addSharedLibrary(.{
188-
.name = "raylib",
189-
.target = target,
190-
.optimize = optimize,
191-
})
192-
else
193-
b.addStaticLibrary(.{
194-
.name = "raylib",
195-
.target = target,
196-
.optimize = optimize,
197-
});
198-
raylib.linkLibC();
199-
200198
// No GLFW required on PLATFORM_DRM
201199
if (options.platform != .drm) {
202200
raylib.addIncludePath(b.path("src/external/glfw/include"));

0 commit comments

Comments
 (0)