Skip to content

Commit

Permalink
Revert "Update zig build system to zig version 0.11.0 (#3393)"
Browse files Browse the repository at this point in the history
This reverts commit 540ad99.
  • Loading branch information
raysan5 committed Oct 10, 2023
1 parent 540ad99 commit 0d8a6cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
7 changes: 7 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const std = @import("std");
const raylib = @import("src/build.zig");

// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
pub fn build(b: *std.Build) void {
raylib.build(b);
}
36 changes: 16 additions & 20 deletions examples/build.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");

// This has been tested to work with zig 0.11.0 (67709b6, Aug 4 2023)
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step {
if (target.getOsTag() == .emscripten) {
@panic("Emscripten building via Zig unsupported");
Expand All @@ -11,7 +11,7 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
const dir = try std.fs.cwd().openIterableDir(module, .{});
var iter = dir.iterate();
while (try iter.next()) |entry| {
if (entry.kind != .file) continue;
if (entry.kind != .File) continue;
const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
const name = entry.name[0..extension_idx];
const path = try std.fs.path.join(b.allocator, &.{ module, entry.name });
Expand All @@ -24,26 +24,26 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
.target = target,
.optimize = optimize,
});
exe.addCSourceFile(.{ .file = .{ .path = path }, .flags = &.{} });
exe.addCSourceFile(path, &[_][]const u8{});
exe.linkLibC();
exe.addObjectFile(switch (target.getOsTag()) {
.windows => .{ .path = "../src/zig-out/lib/raylib.lib" },
.linux => .{ .path = "../src/zig-out/lib/libraylib.a" },
.macos => .{ .path = "../src/zig-out/lib/libraylib.a" },
.emscripten => .{ .path = "../src/zig-out/lib/libraylib.a" },
.windows => "../src/zig-out/lib/raylib.lib",
.linux => "../src/zig-out/lib/libraylib.a",
.macos => "../src/zig-out/lib/libraylib.a",
.emscripten => "../src/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("../src");
exe.addIncludePath("../src/external");
exe.addIncludePath("../src/external/glfw/include");

switch (target.getOsTag()) {
.windows => {
exe.linkSystemLibrary("winmm");
exe.linkSystemLibrary("gdi32");
exe.linkSystemLibrary("opengl32");
exe.addIncludePath(.{ .path = "external/glfw/deps/mingw" });
exe.addIncludePath("external/glfw/deps/mingw");

exe.defineCMacro("PLATFORM_DESKTOP", null);
},
Expand Down Expand Up @@ -71,15 +71,11 @@ fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossT
},
}

const install_cmd = b.addInstallArtifact(exe, .{});

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(&install_cmd.step);

const run_step = b.step(name, name);
run_step.dependOn(&run_cmd.step);

all.dependOn(&install_cmd.step);
b.installArtifact(exe);
var run = b.addRunArtifact(exe);
run.cwd = module;
b.step(name, name).dependOn(&run.step);
all.dependOn(&exe.step);
}
return all;
}
Expand Down
10 changes: 5 additions & 5 deletions src/build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

// This has been tested to work with zig 0.11.0 (67709b6, Aug 4 2023)
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep {
const raylib_flags = &[_][]const u8{
"-std=gnu99",
Expand Down Expand Up @@ -192,12 +192,12 @@ pub fn build(b: *std.Build) void {

const lib = addRaylib(b, target, optimize, options);

lib.installHeader("raylib.h", "raylib.h");
lib.installHeader("raymath.h", "raymath.h");
lib.installHeader("rlgl.h", "rlgl.h");
lib.installHeader("src/raylib.h", "raylib.h");
lib.installHeader("src/raymath.h", "raymath.h");
lib.installHeader("src/rlgl.h", "rlgl.h");

if (options.raygui) {
lib.installHeader("../../raygui/src/raygui.h", "raygui.h");
lib.installHeader("../raygui/src/raygui.h", "raygui.h");
}

b.installArtifact(lib);
Expand Down

1 comment on commit 0d8a6cf

@4m1rh4s4n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why revert? This doesn't work with zig 0.11.0

Please sign in to comment.