From 16fe33322010d868a2b15e3fe0ac05c37e22bbd6 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Fri, 11 Aug 2023 17:06:26 +0200 Subject: [PATCH 1/3] Fix building as subproject --- build.zig | 23 ++++++++++++++++++----- project_setup.sh | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 531e6ee..ec2927e 100755 --- a/build.zig +++ b/build.zig @@ -64,7 +64,15 @@ pub fn getArtifact(b: *std.Build, target: std.zig.CrossTarget, optimize: std.bui return raylib.artifact("raylib"); } -pub fn getModule(b: *std.Build) *std.Build.Module { +//TODO: make these not comptime +pub fn getModule(b: *std.Build, comptime rl_path: []const u8) *std.Build.Module { + if (b.modules.contains("raylib")) { + return b.modules.get("raylib").?; + } + return b.addModule("raylib", .{ .source_file = .{ .path = rl_path ++ "/lib/raylib-zig.zig" } }); +} + +pub fn getModuleInternal(b: *std.Build) *std.Build.Module { if (b.modules.contains("raylib")) { return b.modules.get("raylib").?; } @@ -72,8 +80,13 @@ pub fn getModule(b: *std.Build) *std.Build.Module { } pub const math = struct { - pub fn getModule(b: *std.Build) *std.Build.Module { - var raylib = rl.getModule(b); + pub fn getModule(b: *std.Build, comptime rl_path: []const u8) *std.Build.Module { + var raylib = rl.getModule(b, rl_path); + return b.addModule("raylib-math", .{ .source_file = .{ .path = rl_path ++ "/lib/raylib-zig-math.zig" }, .dependencies = &.{.{ .name = "raylib-zig", .module = raylib }} }); + } + + fn getModuleInternal(b: *std.Build) *std.Build.Module { + var raylib = rl.getModuleInternal(b); return b.addModule("raylib-math", .{ .source_file = .{ .path = "lib/raylib-zig-math.zig" }, .dependencies = &.{.{ .name = "raylib-zig", .module = raylib }} }); } }; @@ -149,8 +162,8 @@ pub fn build(b: *std.Build) void { const system_lib = b.option(bool, "system-raylib", "link to preinstalled raylib libraries") orelse false; _ = system_lib; - var raylib = rl.getModule(b); - var raylib_math = rl.math.getModule(b); + var raylib = rl.getModuleInternal(b); + var raylib_math = rl.math.getModuleInternal(b); for (examples) |ex| { const exe = b.addExecutable(.{ .name = ex.name, .root_source_file = .{ .path = ex.path }, .optimize = optimize, .target = target }); diff --git a/project_setup.sh b/project_setup.sh index 42c0a9e..fa3e250 100755 --- a/project_setup.sh +++ b/project_setup.sh @@ -16,8 +16,8 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - var raylib = rl.getModule(b); - var raylib_math = rl.math.getModule(b); + var raylib = rl.getModule(b, "raylib-zig"); + var raylib_math = rl.math.getModule(b, "raylib-zig"); const exe = b.addExecutable(.{ .name = "'$PROJECT_NAME'", .root_source_file = .{ .path = "src/main.zig" }, .optimize = optimize, .target = target }); From 42dab04fbf163ac918d8ad8eff50fb08273a82ac Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Mon, 14 Aug 2023 00:18:32 +0200 Subject: [PATCH 2/3] Correct @call --- lib/preludes/raylib-zig-prelude.zig | 2 +- lib/raylib-zig.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/preludes/raylib-zig-prelude.zig b/lib/preludes/raylib-zig-prelude.zig index 6722355..ebbe6f6 100755 --- a/lib/preludes/raylib-zig-prelude.zig +++ b/lib/preludes/raylib-zig-prelude.zig @@ -1296,7 +1296,7 @@ pub fn loadCodepoints(text: [:0]const u8) []i32 { } pub fn textFormat(text: [:0]const u8, args: anytype) [:0]const u8 { - return std.mem.span(@call(.{}, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args)); + return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args)); } pub fn textSplit(text: [:0]const u8, delimiter: u8) [][:0]const u8 { diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index dd8054c..009981f 100644 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -1296,7 +1296,7 @@ pub fn loadCodepoints(text: [:0]const u8) []i32 { } pub fn textFormat(text: [:0]const u8, args: anytype) [:0]const u8 { - return std.mem.span(@call(.{}, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args)); + return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args)); } pub fn textSplit(text: [:0]const u8, delimiter: u8) [][:0]const u8 { From 949f0816b652b276d70da7533c87eed26d880f15 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Thu, 17 Aug 2023 00:51:01 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3839149..4c06901 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Manually tweaked, auto-generated [raylib](https://github.com/raysan5/raylib) bindings for zig. -Bindings tested on raylib version 4.5.0-dev and Zig 0.10.1 +Bindings tested on raylib version 4.6.0-dev and Zig 0.11.0 Thanks to all the [contributors](https://github.com/Not-Nik/raylib-zig/graphs/contributors) for their help with this binding.