forked from marler8997/zigup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
66 lines (61 loc) · 2.23 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! This build.zig file boostraps the real build in build2.zig
// NOTE: need to wait on https://github.com/ziglang/zig/pull/9989 before doing this
// to make build errors reasonable
const std = @import("std");
const Builder = std.build.Builder;
const GitRepoStep = @import("GitRepoStep.zig");
pub fn build(b: *Builder) !void {
buildNoreturn(b);
}
fn buildNoreturn(b: *Builder) noreturn {
const err = buildOrFail(b);
std.log.err("{s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
}
std.os.exit(0xff);
}
fn buildOrFail(b: *Builder) anyerror {
const ziget_repo = GitRepoStep.create(b, .{
.url = "https://github.com/marler8997/ziget",
.branch = null,
.sha = @embedFile("zigetsha"),
.fetch_enabled = true,
});
const build2 = addBuild(b, .{ .path = "build2.zig" }, .{});
build2.addArgs(try getBuildArgs(b));
var progress = std.Progress{};
{
var prog_node = progress.start("clone ziget", 1);
ziget_repo.step.make(prog_node) catch |e| return e;
prog_node.end();
}
{
var prog_node = progress.start("run build2.zig", 1);
build2.step.make(prog_node) catch |err| switch (err) {
error.MakeFailed => std.os.exit(0xff), // error already printed by subprocess, hopefully?
error.MakeSkipped => @panic("impossible?"),
};
prog_node.end();
}
std.os.exit(0);
}
// TODO: remove the following if https://github.com/ziglang/zig/pull/9987 is integrated
fn getBuildArgs(self: *Builder) ![]const [:0]const u8 {
const args = try std.process.argsAlloc(self.allocator);
return args[5..];
}
pub fn addBuild(self: *Builder, build_file: std.build.FileSource, _: struct {}) *std.build.RunStep {
const run_step = std.build.RunStep.create(
self,
self.fmt("zig build {s}", .{build_file.getDisplayName()}),
);
run_step.addArg(self.zig_exe);
run_step.addArg("build");
run_step.addArg("--build-file");
run_step.addFileSourceArg(build_file);
run_step.addArg("--cache-dir");
const cache_root_path = self.cache_root.path orelse @panic("todo");
run_step.addArg(self.pathFromRoot(cache_root_path));
return run_step;
}