Skip to content

Commit 6f8ab46

Browse files
committed
git lfs stuff
1 parent 623c15d commit 6f8ab46

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
*.a filter=lfs diff=lfs merge=lfs -text
1313
bin/x64/dxc filter=lfs diff=lfs merge=lfs -text
1414
bin/x64/libdxcompiler.so.3.7 filter=lfs diff=lfs merge=lfs -text
15+
.lfs-content-token filter=lfs diff=lfs merge=lfs -text

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout repository
2222
uses: actions/checkout@v3
23+
with:
24+
lfs: true
2325
- name: Install Zig
2426
uses: mlugg/setup-zig@v2
2527
- name: Check format

.lfs-content-token

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:936686ef9b9485f027086ce1ed7b4f7461d0ceb7eeccb573e48582055ca1c00f
3+
size 87

build.zig

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ const std = @import("std");
22
const builtin = @import("builtin");
33

44
pub 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

Comments
 (0)