[examples] automatically rebuild raylib
Hooked up raylib as a library in the examples build so that if a change is made in raylib then running `zig build` in the examples directory will automatically rebuild raylib. The main pieces to this are the build.zig.zon file which allows the examples build to see the parent raylib directory. Then we can add raylib as a typical dependency and grab the "raylib" artifact to link to. We also no longer need to add include paths since raylib's build.zig installs them for us.
This commit is contained in:
parent
f5c96302d5
commit
d8d9d7e1c1
|
|
@ -2,13 +2,19 @@ const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
// This has been tested to work with zig 0.12.0
|
// 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 {
|
fn add_module(
|
||||||
|
comptime module: []const u8,
|
||||||
|
b: *std.Build,
|
||||||
|
target: std.Build.ResolvedTarget,
|
||||||
|
optimize: std.builtin.OptimizeMode,
|
||||||
|
raylib: *std.Build.Step.Compile,
|
||||||
|
) !*std.Build.Step {
|
||||||
if (target.result.os.tag == .emscripten) {
|
if (target.result.os.tag == .emscripten) {
|
||||||
@panic("Emscripten building via Zig unsupported");
|
@panic("Emscripten building via Zig unsupported");
|
||||||
}
|
}
|
||||||
|
|
||||||
const all = b.step(module, "All " ++ module ++ " examples");
|
const all = b.step(module, "All " ++ module ++ " examples");
|
||||||
var dir = try std.fs.cwd().openDir(module, .{ .iterate = true });
|
var dir = try std.fs.cwd().openDir(b.pathFromRoot(module), .{ .iterate = true });
|
||||||
defer if (comptime builtin.zig_version.minor >= 12) dir.close();
|
defer if (comptime builtin.zig_version.minor >= 12) dir.close();
|
||||||
|
|
||||||
var iter = dir.iterate();
|
var iter = dir.iterate();
|
||||||
|
|
@ -28,17 +34,7 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.Build.Reso
|
||||||
});
|
});
|
||||||
exe.addCSourceFile(.{ .file = b.path(path), .flags = &.{} });
|
exe.addCSourceFile(.{ .file = b.path(path), .flags = &.{} });
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
exe.addObjectFile(switch (target.result.os.tag) {
|
exe.linkLibrary(raylib);
|
||||||
.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(b.path("../src"));
|
|
||||||
exe.addIncludePath(b.path("../src/external"));
|
|
||||||
exe.addIncludePath(b.path("../src/external/glfw/include"));
|
|
||||||
|
|
||||||
switch (target.result.os.tag) {
|
switch (target.result.os.tag) {
|
||||||
.windows => {
|
.windows => {
|
||||||
|
|
@ -97,14 +93,20 @@ pub fn build(b: *std.Build) !void {
|
||||||
// set a preferred release mode, allowing the user to decide how to optimize.
|
// set a preferred release mode, allowing the user to decide how to optimize.
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const raylib_dep = b.dependency("raylib", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
const raylib = raylib_dep.artifact("raylib");
|
||||||
|
|
||||||
const all = b.getInstallStep();
|
const all = b.getInstallStep();
|
||||||
|
|
||||||
all.dependOn(try add_module("audio", b, target, optimize));
|
all.dependOn(try add_module("audio", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("core", b, target, optimize));
|
all.dependOn(try add_module("core", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("models", b, target, optimize));
|
all.dependOn(try add_module("models", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("others", b, target, optimize));
|
all.dependOn(try add_module("others", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("shaders", b, target, optimize));
|
all.dependOn(try add_module("shaders", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("shapes", b, target, optimize));
|
all.dependOn(try add_module("shapes", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("text", b, target, optimize));
|
all.dependOn(try add_module("text", b, target, optimize, raylib));
|
||||||
all.dependOn(try add_module("textures", b, target, optimize));
|
all.dependOn(try add_module("textures", b, target, optimize, raylib));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
examples/build.zig.zon
Normal file
10
examples/build.zig.zon
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
.{
|
||||||
|
.name = .raylib_examples,
|
||||||
|
.version = "0.0.0",
|
||||||
|
.fingerprint = 0x3570d11b06c2907a, // Changing this has security and trust implications.
|
||||||
|
.minimum_zig_version = "0.14.0",
|
||||||
|
.dependencies = .{
|
||||||
|
.raylib = .{ .path = ".." },
|
||||||
|
},
|
||||||
|
.paths = .{"."},
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user