mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 03:18:14 +00:00
Update build.zig
This commit is contained in:
78
build.zig
78
build.zig
@@ -2,7 +2,7 @@ const std = @import("std");
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
/// Minimum supported version of Zig
|
/// Minimum supported version of Zig
|
||||||
const min_ver = "0.13.0";
|
const min_ver = "0.15.1";
|
||||||
|
|
||||||
const emccOutputDir = "zig-out" ++ std.fs.path.sep_str ++ "htmlout" ++ std.fs.path.sep_str;
|
const emccOutputDir = "zig-out" ++ std.fs.path.sep_str ++ "htmlout" ++ std.fs.path.sep_str;
|
||||||
const emccOutputFile = "index.html";
|
const emccOutputFile = "index.html";
|
||||||
@@ -100,25 +100,31 @@ const config_h_flags = outer: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
|
fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
|
||||||
var raylib_flags_arr = std.ArrayList([]const u8).init(b.allocator);
|
var raylib_flags_arr: std.ArrayList([]const u8) = .empty;
|
||||||
defer raylib_flags_arr.deinit();
|
defer raylib_flags_arr.deinit(b.allocator);
|
||||||
|
|
||||||
try raylib_flags_arr.appendSlice(&[_][]const u8{
|
try raylib_flags_arr.appendSlice(
|
||||||
"-std=gnu99",
|
b.allocator,
|
||||||
"-D_GNU_SOURCE",
|
&[_][]const u8{
|
||||||
"-DGL_SILENCE_DEPRECATION=199309L",
|
"-std=gnu99",
|
||||||
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
|
"-D_GNU_SOURCE",
|
||||||
});
|
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||||
|
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (options.shared) {
|
if (options.shared) {
|
||||||
try raylib_flags_arr.appendSlice(&[_][]const u8{
|
try raylib_flags_arr.appendSlice(
|
||||||
"-fPIC",
|
b.allocator,
|
||||||
"-DBUILD_LIBTYPE_SHARED",
|
&[_][]const u8{
|
||||||
});
|
"-fPIC",
|
||||||
|
"-DBUILD_LIBTYPE_SHARED",
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a flag indiciating the use of a custom `config.h`
|
// Sets a flag indiciating the use of a custom `config.h`
|
||||||
try raylib_flags_arr.append("-DEXTERNAL_CONFIG_FLAGS");
|
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
|
||||||
if (options.config.len > 0) {
|
if (options.config.len > 0) {
|
||||||
// Splits a space-separated list of config flags into multiple flags
|
// Splits a space-separated list of config flags into multiple flags
|
||||||
//
|
//
|
||||||
@@ -128,7 +134,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
|
|
||||||
// Apply config flags supplied by the user
|
// Apply config flags supplied by the user
|
||||||
while (config_iter.next()) |config_flag|
|
while (config_iter.next()) |config_flag|
|
||||||
try raylib_flags_arr.append(config_flag);
|
try raylib_flags_arr.append(b.allocator, config_flag);
|
||||||
|
|
||||||
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
|
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
|
||||||
//
|
//
|
||||||
@@ -146,11 +152,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, append default value from config.h to compile flags
|
// Otherwise, append default value from config.h to compile flags
|
||||||
try raylib_flags_arr.append(flag);
|
try raylib_flags_arr.append(b.allocator, flag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Set default config if no custome config got set
|
// Set default config if no custome config got set
|
||||||
try raylib_flags_arr.appendSlice(&config_h_flags);
|
try raylib_flags_arr.appendSlice(b.allocator, &config_h_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
const raylib = b.addLibrary(.{
|
const raylib = b.addLibrary(.{
|
||||||
@@ -168,28 +174,28 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
raylib.addIncludePath(b.path("src/external/glfw/include"));
|
raylib.addIncludePath(b.path("src/external/glfw/include"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var c_source_files = try std.ArrayList([]const u8).initCapacity(b.allocator, 2);
|
var c_source_files: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 2);
|
||||||
c_source_files.appendSliceAssumeCapacity(&.{ "src/rcore.c", "src/utils.c" });
|
c_source_files.appendSliceAssumeCapacity(&.{ "src/rcore.c", "src/utils.c" });
|
||||||
|
|
||||||
if (options.rshapes) {
|
if (options.rshapes) {
|
||||||
try c_source_files.append("src/rshapes.c");
|
try c_source_files.append(b.allocator, "src/rshapes.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RSHAPES");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RSHAPES");
|
||||||
}
|
}
|
||||||
if (options.rtextures) {
|
if (options.rtextures) {
|
||||||
try c_source_files.append("src/rtextures.c");
|
try c_source_files.append(b.allocator, "src/rtextures.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RTEXTURES");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RTEXTURES");
|
||||||
}
|
}
|
||||||
if (options.rtext) {
|
if (options.rtext) {
|
||||||
try c_source_files.append("src/rtext.c");
|
try c_source_files.append(b.allocator, "src/rtext.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RTEXT");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RTEXT");
|
||||||
}
|
}
|
||||||
if (options.rmodels) {
|
if (options.rmodels) {
|
||||||
try c_source_files.append("src/rmodels.c");
|
try c_source_files.append(b.allocator, "src/rmodels.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RMODELS");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RMODELS");
|
||||||
}
|
}
|
||||||
if (options.raudio) {
|
if (options.raudio) {
|
||||||
try c_source_files.append("src/raudio.c");
|
try c_source_files.append(b.allocator, "src/raudio.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RAUDIO");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RAUDIO");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.opengl_version != .auto) {
|
if (options.opengl_version != .auto) {
|
||||||
@@ -200,7 +206,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
switch (target.result.os.tag) {
|
switch (target.result.os.tag) {
|
||||||
.windows => {
|
.windows => {
|
||||||
switch (options.platform) {
|
switch (options.platform) {
|
||||||
.glfw => try c_source_files.append("src/rglfw.c"),
|
.glfw => try c_source_files.append(b.allocator, "src/rglfw.c"),
|
||||||
.rgfw, .sdl, .drm, .android => {},
|
.rgfw, .sdl, .drm, .android => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,14 +267,14 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
raylib.addSystemIncludePath(.{ .cwd_relative = androidAsmPath });
|
raylib.addSystemIncludePath(.{ .cwd_relative = androidAsmPath });
|
||||||
raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath });
|
raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath });
|
||||||
|
|
||||||
var libcData = std.ArrayList(u8).init(b.allocator);
|
var libcData: std.ArrayList(u8) = .empty;
|
||||||
const writer = libcData.writer();
|
var aw: std.Io.Writer.Allocating = .fromArrayList(b.allocator, &libcData);
|
||||||
try (std.zig.LibCInstallation{
|
try (std.zig.LibCInstallation{
|
||||||
.include_dir = androidIncludePath,
|
.include_dir = androidIncludePath,
|
||||||
.sys_include_dir = androidIncludePath,
|
.sys_include_dir = androidIncludePath,
|
||||||
.crt_dir = androidApiSpecificPath,
|
.crt_dir = androidApiSpecificPath,
|
||||||
}).render(writer);
|
}).render(&aw.writer);
|
||||||
const libcFile = b.addWriteFiles().add("android-libc.txt", try libcData.toOwnedSlice());
|
const libcFile = b.addWriteFiles().add("android-libc.txt", try libcData.toOwnedSlice(b.allocator));
|
||||||
raylib.setLibCFile(libcFile);
|
raylib.setLibCFile(libcFile);
|
||||||
|
|
||||||
if (options.opengl_version == .auto) {
|
if (options.opengl_version == .auto) {
|
||||||
@@ -279,7 +285,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
|
|
||||||
setDesktopPlatform(raylib, .android);
|
setDesktopPlatform(raylib, .android);
|
||||||
} else {
|
} else {
|
||||||
try c_source_files.append("src/rglfw.c");
|
try c_source_files.append(b.allocator, "src/rglfw.c");
|
||||||
|
|
||||||
if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) {
|
if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) {
|
||||||
raylib.root_module.addCMacro("_GLFW_X11", "");
|
raylib.root_module.addCMacro("_GLFW_X11", "");
|
||||||
@@ -320,7 +326,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
||||||
try c_source_files.append("rglfw.c");
|
try c_source_files.append(b.allocator, "rglfw.c");
|
||||||
raylib.linkSystemLibrary("GL");
|
raylib.linkSystemLibrary("GL");
|
||||||
raylib.linkSystemLibrary("rt");
|
raylib.linkSystemLibrary("rt");
|
||||||
raylib.linkSystemLibrary("dl");
|
raylib.linkSystemLibrary("dl");
|
||||||
@@ -343,7 +349,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// On macos rglfw.c include Objective-C files.
|
// On macos rglfw.c include Objective-C files.
|
||||||
try raylib_flags_arr.append("-ObjC");
|
try raylib_flags_arr.append(b.allocator, "-ObjC");
|
||||||
raylib.root_module.addCSourceFile(.{
|
raylib.root_module.addCSourceFile(.{
|
||||||
.file = b.path("src/rglfw.c"),
|
.file = b.path("src/rglfw.c"),
|
||||||
.flags = raylib_flags_arr.items,
|
.flags = raylib_flags_arr.items,
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
.{
|
.{
|
||||||
.name = .raylib,
|
.name = .raylib,
|
||||||
.version = "5.5.0",
|
.version = "5.5.0",
|
||||||
.minimum_zig_version = "0.14.0",
|
.minimum_zig_version = "0.15.1",
|
||||||
|
|
||||||
.fingerprint = 0x13035e5cb8bc1ac2, // Changing this has security and trust implications.
|
.fingerprint = 0x13035e5cb8bc1ac2, // Changing this has security and trust implications.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user