Skip to content

Commit

Permalink
build.zig: Use std.Build.Module.addCMacro for config flags
Browse files Browse the repository at this point in the history
  • Loading branch information
sagehane committed Nov 10, 2024
1 parent 6ddaaa7 commit 3559a92
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ 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.shared) {
try raylib_flags_arr.appendSlice(b.allocator, shared_flags);
}

const raylib = if (options.shared)
b.addSharedLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
})
else
b.addStaticLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
});
raylib.linkLibC();

if (options.config.len > 0) {
// Sets a flag indiciating the use of a custom `config.h`
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
Expand Down Expand Up @@ -169,32 +188,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
if (config_flag.len == flag.len or config_flag[flag.len] == '=') continue :outer;
}

// Otherwise, append default value from config.h to compile flags
try raylib_flags_arr.append(
b.allocator,
b.fmt("-D{s}={s}", .{ flag_val[0], flag_val[1] }),
);
// Otherwise, apply the default values from config.h
raylib.root_module.addCMacro(flag_val[0], flag_val[1]);
}
}

if (options.shared) {
try raylib_flags_arr.appendSlice(b.allocator, shared_flags);
}

const raylib = if (options.shared)
b.addSharedLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
})
else
b.addStaticLibrary(.{
.name = "raylib",
.target = target,
.optimize = optimize,
});
raylib.linkLibC();

// No GLFW required on PLATFORM_DRM
if (options.platform != .drm) {
raylib.addIncludePath(b.path("src/external/glfw/include"));
Expand Down

0 comments on commit 3559a92

Please sign in to comment.