@@ -2,6 +2,13 @@ const std = @import("std");
22const builtin = @import ("builtin" );
33
44pub fn build (b : * std.Build ) ! void {
5+ checkGitLfsContent () catch {
6+ try ensureGit (b .allocator );
7+ try ensureGitLfs (b .allocator , "install" );
8+ try ensureGitLfs (b .allocator , "pull" );
9+ try checkGitLfsContent ();
10+ };
11+
512 const options = .{
613 .zxaudio2_debug_layer = b .option (
714 bool ,
@@ -266,3 +273,81 @@ pub fn addCompileShaders(
266273 .shader_ver = options .shader_ver ,
267274 };
268275}
276+
277+ fn ensureGit (allocator : std.mem.Allocator ) ! void {
278+ const printErrorMsg = (struct {
279+ fn impl () void {
280+ std .log .err ("\n " ++
281+ \\---------------------------------------------------------------------------
282+ \\
283+ \\'git version' failed. Is Git not installed?
284+ \\
285+ \\---------------------------------------------------------------------------
286+ \\
287+ , .{});
288+ }
289+ }).impl ;
290+ const argv = &[_ ][]const u8 { "git" , "version" };
291+ const result = std .process .Child .run (.{
292+ .allocator = allocator ,
293+ .argv = argv ,
294+ }) catch { // e.g. FileNotFound
295+ printErrorMsg ();
296+ return error .GitNotFound ;
297+ };
298+ defer {
299+ allocator .free (result .stderr );
300+ allocator .free (result .stdout );
301+ }
302+ if (result .term .Exited != 0 ) {
303+ printErrorMsg ();
304+ return error .GitNotFound ;
305+ }
306+ }
307+
308+ fn ensureGitLfs (allocator : std.mem.Allocator , cmd : []const u8 ) ! void {
309+ const printNoGitLfs = (struct {
310+ fn impl () void {
311+ std .log .err ("\n " ++
312+ \\---------------------------------------------------------------------------
313+ \\
314+ \\Please install Git LFS (Large File Support) extension and run 'zig build' again.
315+ \\
316+ \\For more info about Git LFS see: https://git-lfs.github.com/
317+ \\
318+ \\---------------------------------------------------------------------------
319+ \\
320+ , .{});
321+ }
322+ }).impl ;
323+ const argv = &[_ ][]const u8 { "git" , "lfs" , cmd };
324+ const result = std .process .Child .run (.{
325+ .allocator = allocator ,
326+ .argv = argv ,
327+ }) catch { // e.g. FileNotFound
328+ printNoGitLfs ();
329+ return error .GitLfsNotFound ;
330+ };
331+ defer {
332+ allocator .free (result .stderr );
333+ allocator .free (result .stdout );
334+ }
335+ if (result .term .Exited != 0 ) {
336+ printNoGitLfs ();
337+ return error .GitLfsNotFound ;
338+ }
339+ }
340+
341+ fn checkGitLfsContent () ! void {
342+ const expected_contents =
343+ \\DO NOT EDIT OR DELETE
344+ \\This file is used to check if Git LFS content has been downloaded
345+ ;
346+ var buf : [expected_contents .len ]u8 = undefined ;
347+ _ = std .fs .cwd ().readFile (".lfs-content-token" , & buf ) catch {
348+ return error .GitLfsContentTokenNotFound ;
349+ };
350+ if (! std .mem .eql (u8 , expected_contents , & buf )) {
351+ return error .GitLfsContentCheckFailed ;
352+ }
353+ }
0 commit comments