From 131caa4cb7befc33d351f0f8c0e9e0b4fb4db4d7 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 11 Jun 2022 12:05:39 -0700 Subject: [PATCH] glfw: ensure upstream submodule is cloned Signed-off-by: Stephen Gutekanst --- glfw/build.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/glfw/build.zig b/glfw/build.zig index b296bfc4..d9b00574 100644 --- a/glfw/build.zig +++ b/glfw/build.zig @@ -53,6 +53,9 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void } fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *std.build.LibExeObjStep { + // TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939 + ensureDependencySubmodule(b.allocator, "upstream") catch unreachable; + const main_abs = std.fs.path.join(b.allocator, &.{ thisDir(), "src/main.zig" }) catch unreachable; const lib = b.addStaticLibrary("glfw", main_abs); lib.setBuildMode(step.build_mode); @@ -96,6 +99,18 @@ fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) * return lib; } +fn ensureDependencySubmodule(allocator: std.mem.Allocator, path: []const u8) !void { + if (std.process.getEnvVarOwned(allocator, "NO_ENSURE_SUBMODULES")) |no_ensure_submodules| { + if (std.mem.eql(u8, no_ensure_submodules, "true")) return; + } else |_| {} + var child = std.ChildProcess.init(&.{ "git", "submodule", "update", "--init", path }, allocator); + child.cwd = thisDir(); + child.stderr = std.io.getStdErr(); + child.stdout = std.io.getStdOut(); + + _ = try child.spawnAndWait(); +} + fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; }