Hey all, I'm new to zig and I'm trying to set up a build.zig that links to raylib, builds with zig build, and runs with zig build run. I'm able to link to raylib, build, and run my main.exe manually but if I try run zig build run it fails. See the bottom of this post for the failure.
Context
I'm using version 0.12.0-dev.
My folder structure is:
external/
├─ include/
│ ├─ some raylib headers
├─ libraries/
│ ├─ librarylib.a
│ ├─ libraylibdll.a
│ ├─ raylib.dll
src/
├─ main.zig
build.zig
The bulk of my build script:
const exe = b.addExecutable(.{ .name = "main", .root_source_file = .{ .path = "src/main.zig" }});
exe.addLibraryPath(.{ .path = "./external/libraries"});
exe.linkSystemLibrary2("raylibdll", .{});
exe.addIncludePath(.{ .path = "./external/include" });
const installArtifact = b.addInstallArtifact(exe, .{});
// Make build step depend on installing the exe
b.getInstallStep().dependOn(&installArtifact.step);
// Copy the .dll from the external folder into the build/bin folder so that main.exe can find it
const rayCopyStep = b.addInstallFile(.{.path = "./external/libraries/raylib.dll"}, "./bin/raylib.dll");
// Make it so build step depends on the copy
b.getInstallStep().dependOn(&rayCopyStep.step);
// Create the "zig build run" step
const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run app");
run_step.dependOn(&run_exe.step);
zig build works as expected and I can run the produced main.exe.
Problem
When I run zig build run I get
run main: error: the following command exited with error code 53:
D:\...\zig-cache\o\0a5c467306bba98e6cccb426256ec040\main.exe
If I run that main.exe from zig-cache it fails because it can't find the raylib dll which makes sense because it's not copied into that folder. So I know the issue is that raylib isn't copied into zig-cache so main.exe can't run. How can I fix that? Can I force zig build run to run the exe in zig-out/bin?