Hey ,
I’m the creator of snek, the game designed to help you focus.
The game relies on Raylib which is currently vendored into the project using a git submodule. Since git clone
doesn’t automatically clone submodules () I frequently get reports from people trying to build the game that they get errors about Raylib missing. How can I clone Raylib as part of the build?
Currently, my project looks like
// build.zig.zon
.{
.name = .snek,
.version = "0.0.0",
.paths = .{
"snek.zig",
"build.zig",
"build.zig.zon",
},
.dependencies = .{
.raylib = .{ .path = "./raylib" },
},
.fingerprint = 0xd86d1176857ecf02,
}
// build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "snek",
.root_source_file = b.path("snek.zig"),
.target = target,
.optimize = optimize,
});
const check_step = b.step("check", "");
check_step.dependOn(&exe.step);
exe.linkLibC();
exe.linkSystemLibrary("m");
if (target.result.os.tag.isDarwin()) {
exe.linkFramework("IOKit");
exe.linkFramework("Cocoa");
} else if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("opengl32");
exe.linkSystemLibrary("gdi32");
exe.linkSystemLibrary("winmm");
}
const raylib = b.dependency("raylib", .{
.target = target,
.optimize = optimize,
});
exe.linkLibrary(raylib.artifact("raylib"));
b.installArtifact(exe);
const game_exe = b.addRunArtifact(exe);
const play_step = b.step("play", "");
play_step.dependOn(&game_exe.step);
}
I want to somehow detect if Raylib is cloned, and if not run git submodule update --init
.
I tried doing
diff --git a/build.zig b/build.zig
--- a/build.zig
+++ b/build.zig
@@ -11,6 +11,10 @@
});
const check_step = b.step("check", "");
check_step.dependOn(&exe.step);
+ const submodule_step = b.addSystemCommand(&.{ "git", "submodule", "update", "--init" });
+ submodule_step.addFileArg(std.Build.LazyPath{ .cwd_relative = "./raylib" });
+ check_step.dependOn(&submodule_step.step);
+ exe.step.dependOn(&submodule_step.step);
exe.linkLibC();
exe.linkSystemLibrary("m");
But it doesn’t seem to do anything.
Thanks for the help!