[build.zig] Drop support for 0.11.0 and use more idiomatic build script code (#3927)
* Remove support for 0.11.0, and make build script more idiomatic + remove all 0.11.0 compatibility functions + remove most LazyPath .path variants + I didn't touch emscripten, I don't know if its relative or absolute + change all absolute paths to use .cwd_relative + only use the builder allocator + have local dependencies use the package manager + make adding raygui more flexible + use zig-cache for generated wayland files * Remove support for 0.11.0 in examples/build.zig * update examples further and add clarifying comment on addRaygui
This commit is contained in:
parent
3caa424ad4
commit
e0f6faa151
3 changed files with 131 additions and 196 deletions
|
@ -1,24 +1,14 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
// This has been tested to work with zig 0.11.0 (67709b6, Aug 4 2023) and zig 0.12.0-dev.2075+f5978181e (Jan 8 2024)
|
||||
//
|
||||
// anytype is used here to preserve compatibility, in 0.12.0dev the std.zig.CrossTarget type
|
||||
// was reworked into std.Target.Query and std.Build.ResolvedTarget. Using anytype allows
|
||||
// us to accept both CrossTarget and ResolvedTarget and act accordingly in getOsTagVersioned.
|
||||
fn add_module(comptime module: []const u8, b: *std.Build, target: anytype, optimize: std.builtin.OptimizeMode) !*std.Build.Step {
|
||||
if (comptime builtin.zig_version.minor >= 12 and @TypeOf(target) != std.Build.ResolvedTarget) {
|
||||
@compileError("Expected 'std.Build.ResolvedTarget' for argument 2 'target' in 'add_module', found '" ++ @typeName(@TypeOf(target)) ++ "'");
|
||||
} else if (comptime builtin.zig_version.minor == 11 and @TypeOf(target) != std.zig.CrossTarget) {
|
||||
@compileError("Expected 'std.zig.CrossTarget' for argument 2 'target' in 'add_module', found '" ++ @typeName(@TypeOf(target)) ++ "'");
|
||||
}
|
||||
|
||||
if (getOsTagVersioned(target) == .emscripten) {
|
||||
// This has been tested to work with zig 0.12.0
|
||||
fn add_module(comptime module: []const u8, b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step {
|
||||
if (target.result.os.tag == .emscripten) {
|
||||
@panic("Emscripten building via Zig unsupported");
|
||||
}
|
||||
|
||||
const all = b.step(module, "All " ++ module ++ " examples");
|
||||
var dir = try openIterableDirVersioned(std.fs.cwd(), module);
|
||||
var dir = try std.fs.cwd().openDir(module, .{ .iterate = true });
|
||||
defer if (comptime builtin.zig_version.minor >= 12) dir.close();
|
||||
|
||||
var iter = dir.iterate();
|
||||
|
@ -29,28 +19,28 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: anytype, optim
|
|||
const path = try std.fs.path.join(b.allocator, &.{ module, entry.name });
|
||||
|
||||
// zig's mingw headers do not include pthread.h
|
||||
if (std.mem.eql(u8, "core_loading_thread", name) and getOsTagVersioned(target) == .windows) continue;
|
||||
if (std.mem.eql(u8, "core_loading_thread", name) and target.result.os.tag == .windows) continue;
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = name,
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe.addCSourceFile(.{ .file = .{ .path = path }, .flags = &.{} });
|
||||
exe.addCSourceFile(.{ .file = b.path(path), .flags = &.{} });
|
||||
exe.linkLibC();
|
||||
exe.addObjectFile(switch (getOsTagVersioned(target)) {
|
||||
.windows => .{ .path = "../zig-out/lib/raylib.lib" },
|
||||
.linux => .{ .path = "../zig-out/lib/libraylib.a" },
|
||||
.macos => .{ .path = "../zig-out/lib/libraylib.a" },
|
||||
.emscripten => .{ .path = "../zig-out/lib/libraylib.a" },
|
||||
exe.addObjectFile(switch (target.result.os.tag) {
|
||||
.windows => b.path("../zig-out/lib/raylib.lib"),
|
||||
.linux => b.path("../zig-out/lib/libraylib.a"),
|
||||
.macos => b.path("../zig-out/lib/libraylib.a"),
|
||||
.emscripten => b.path("../zig-out/lib/libraylib.a"),
|
||||
else => @panic("Unsupported OS"),
|
||||
});
|
||||
|
||||
exe.addIncludePath(.{ .path = "../src" });
|
||||
exe.addIncludePath(.{ .path = "../src/external" });
|
||||
exe.addIncludePath(.{ .path = "../src/external/glfw/include" });
|
||||
exe.addIncludePath(b.path("../src"));
|
||||
exe.addIncludePath(b.path("../src/external"));
|
||||
exe.addIncludePath(b.path("../src/external/glfw/include"));
|
||||
|
||||
switch (getOsTagVersioned(target)) {
|
||||
switch (target.result.os.tag) {
|
||||
.windows => {
|
||||
exe.linkSystemLibrary("winmm");
|
||||
exe.linkSystemLibrary("gdi32");
|
||||
|
@ -117,19 +107,3 @@ pub fn build(b: *std.Build) !void {
|
|||
all.dependOn(try add_module("text", b, target, optimize));
|
||||
all.dependOn(try add_module("textures", b, target, optimize));
|
||||
}
|
||||
|
||||
fn getOsTagVersioned(target: anytype) std.Target.Os.Tag {
|
||||
if (comptime builtin.zig_version.minor >= 12) {
|
||||
return target.result.os.tag;
|
||||
} else {
|
||||
return target.getOsTag();
|
||||
}
|
||||
}
|
||||
|
||||
fn openIterableDirVersioned(dir: std.fs.Dir, path: []const u8) !(if (builtin.zig_version.minor >= 12) std.fs.Dir else std.fs.IterableDir) {
|
||||
if (comptime builtin.zig_version.minor >= 12) {
|
||||
return dir.openDir(path, .{ .iterate = true });
|
||||
} else {
|
||||
return dir.openIterableDir(path, .{});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue