From ff70a04bf5e2aea84fe9d71cede790e1a031f810 Mon Sep 17 00:00:00 2001 From: star-tek-mb Date: Sun, 5 Feb 2023 17:03:03 +0500 Subject: update zig build to latest master (#2910) also, adds package manager support --- examples/build.zig | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/build.zig b/examples/build.zig index eb040fd2..c0479910 100644 --- a/examples/build.zig +++ b/examples/build.zig @@ -1,15 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step { +fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*std.build.Step { if (target.getOsTag() == .emscripten) { @panic("Emscripten building via Zig unsupported"); } - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); - const all = b.step(module, "All " ++ module ++ " examples"); const dir = try std.fs.cwd().openIterableDir(module, .{}); var iter = dir.iterate(); @@ -22,10 +18,12 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi // zig's mingw headers do not include pthread.h if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue; - const exe = b.addExecutable(name, null); + const exe = b.addExecutable(.{ + .name = name, + .target = target, + .optimize = optimize, + }); exe.addCSourceFile(path, &[_][]const u8{}); - exe.setTarget(target); - exe.setBuildMode(mode); exe.linkLibC(); exe.addObjectFile(switch (target.getOsTag()) { .windows => "../src/raylib.lib", @@ -89,15 +87,19 @@ pub fn build(b: *std.build.Builder) !void { // means any target is allowed, and the default is native. Other options // for restricting supported target set are available. const target = b.standardTargetOptions(.{}); + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); const all = b.getInstallStep(); - all.dependOn(try add_module("audio", b, target)); - all.dependOn(try add_module("core", b, target)); - all.dependOn(try add_module("models", b, target)); - all.dependOn(try add_module("others", b, target)); - all.dependOn(try add_module("shaders", b, target)); - all.dependOn(try add_module("shapes", b, target)); - all.dependOn(try add_module("text", b, target)); - all.dependOn(try add_module("textures", b, target)); + all.dependOn(try add_module("audio", b, target, optimize)); + all.dependOn(try add_module("core", b, target, optimize)); + all.dependOn(try add_module("models", b, target, optimize)); + all.dependOn(try add_module("others", b, target, optimize)); + all.dependOn(try add_module("shaders", b, target, optimize)); + all.dependOn(try add_module("shapes", b, target, optimize)); + all.dependOn(try add_module("text", b, target, optimize)); + all.dependOn(try add_module("textures", b, target, optimize)); } -- cgit v1.2.3