Hey o, 👋 I'm pretty new to both Zig and raylib-zig, and I think I stumbled upon a bug while trying to build my project for different platforms. I've discussed this in the Zig Discord server, and they suggested I should report it.
What's Happening
I'm trying to build a simple project for multiple targets (like macOS and Windows), but it seems there's an issue with how artifacts are being cached. From what I understand after discussing it in Discord, the problem is that raylib-zig is using global variables to cache build artifacts, which doesn't play well with Zig's build system when trying to build for multiple targets.
How to Reproduce
I created a minimal test project to demonstrate the issue. Here's how you can try it yourself:
4. And a simple `src/main.zig`:
```zig
const rl = @import("raylib");
pub fn main() !void {
rl.initWindow(800, 450, "Test");
defer rl.closeWindow();
rl.setTargetFPS(60);
while (!rl.windowShouldClose()) {
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white);
}
}
The Error
When I run zig build, I get this error:
thread 31355508 panic: unable to find artifact 'raylib'
From what I learned in the Discord discussion, this happens because the caching system is reusing the first cached artifact instead of creating new ones for different targets.
What Should Happen
The build system should create separate artifacts for each target, allowing us to successfully build for multiple platforms.
Hey o, 👋 I'm pretty new to both Zig and
raylib-zig
, and I think I stumbled upon a bug while trying to build my project for different platforms. I've discussed this in the Zig Discord server, and they suggested I should report it.What's Happening
I'm trying to build a simple project for multiple targets (like macOS and Windows), but it seems there's an issue with how artifacts are being cached. From what I understand after discussing it in Discord, the problem is that
raylib-zig
is using global variables to cache build artifacts, which doesn't play well with Zig's build system when trying to build for multiple targets.How to Reproduce
I created a minimal test project to demonstrate the issue. Here's how you can try it yourself:
First, create a new project with this structure:
Here's my
build.zig.zon
:My
build.zig
:const Target = struct { query: std.Target.Query, name: []const u8, };
const targets = [_]Target{ .{ .query = .{ .cpu_arch = .aarch64, .os_tag = .macos }, .name = "aarch64-macos" }, .{ .query = .{ .cpu_arch = .x86_64, .os_tag = .windows }, .name = "x86_64-windows" }, };
pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{});
}
fn createExecutable( b: std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, ) !std.Build.Step.Compile { const exe = b.addExecutable(.{ .name = "raylib-test", .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); exe.linkLibCpp();
}
The Error
When I run
zig build
, I get this error:From what I learned in the Discord discussion, this happens because the caching system is reusing the first cached artifact instead of creating new ones for different targets.
What Should Happen
The build system should create separate artifacts for each target, allowing us to successfully build for multiple platforms.
Additional Context
The issue seems to be related to the global caching in
build.zig
here: https://github.com/Not-Nik/raylib-zig/blob/c191e12e7c50e5dc2b1addd1e5dbd16bd405d2b5/build.zig#L100I'm still learning Zig and raylib, so please let me know if you need any additional information or if I should test something else! 😊