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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
//! Compiles a blueprint file using `blueprint-compiler`. This performs
//! additional checks to ensure that various minimum versions are met.
//!
//! Usage: blueprint.zig <major> <minor> <output> <input>
//!
//! Example: blueprint.zig 1 5 output.ui input.blp
const std = @import("std");
const adw_c = @import("adw_c");
pub const blueprint_compiler_help =
\\
\\When building from a Git checkout, Ghostty requires
\\version {f} or newer of `blueprint-compiler` as a
\\build-time dependency. Please install it, ensure that it
\\is available on your PATH, and then retry building Ghostty.
\\See `HACKING.md` for more details.
\\
\\This message should *not* appear for normal users, who
\\should build Ghostty from official release tarballs instead.
\\Please consult https://ghostty.org/docs/install/build for
\\more information on the recommended build instructions.
;
const adwaita_version = std.SemanticVersion{
.major = adw_c.ADW_MAJOR_VERSION,
.minor = adw_c.ADW_MINOR_VERSION,
.patch = adw_c.ADW_MICRO_VERSION,
};
const required_blueprint_version = std.SemanticVersion{
.major = 0,
.minor = 16,
.patch = 0,
};
pub fn main(init: std.process.Init) !void {
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
defer _ = debug_allocator.deinit();
const alloc = debug_allocator.allocator();
// Get our args
var it = try init.minimal.args.iterateAllocator(alloc);
defer it.deinit();
_ = it.next(); // Skip argv0
const arg_major = it.next() orelse return error.NoMajorVersion;
const arg_minor = it.next() orelse return error.NoMinorVersion;
const output = it.next() orelse return error.NoOutput;
const input = it.next() orelse return error.NoInput;
const required_adwaita_version = std.SemanticVersion{
.major = try std.fmt.parseUnsigned(u8, arg_major, 10),
.minor = try std.fmt.parseUnsigned(u8, arg_minor, 10),
.patch = 0,
};
if (adwaita_version.order(required_adwaita_version) == .lt) {
std.debug.print(
\\`libadwaita` is too old.
\\
\\Ghostty requires a version {f} or newer of `libadwaita` to
\\compile this blueprint. Please install it, ensure that it is
\\available on your PATH, and then retry building Ghostty.
, .{required_adwaita_version});
std.process.exit(1);
}
// Version checks
{
const blueprint_compiler = std.process.run(alloc, init.io, .{
.argv = &.{ "blueprint-compiler", "--version" },
}) catch |err| switch (err) {
error.FileNotFound => {
std.debug.print(
\\`blueprint-compiler` not found.
++ blueprint_compiler_help,
.{required_blueprint_version},
);
std.process.exit(1);
},
else => return err,
};
defer {
alloc.free(blueprint_compiler.stdout);
alloc.free(blueprint_compiler.stderr);
}
switch (blueprint_compiler.term) {
.exited => |rc| if (rc != 0) std.process.exit(1),
else => std.process.exit(1),
}
const version = try std.SemanticVersion.parse(std.mem.trim(
u8,
blueprint_compiler.stdout,
&std.ascii.whitespace,
));
if (version.order(required_blueprint_version) == .lt) {
std.debug.print(
\\`blueprint-compiler` is the wrong version.
++ blueprint_compiler_help,
.{required_blueprint_version},
);
std.process.exit(1);
}
}
// Compilation
{
const blueprint_compiler = std.process.run(alloc, init.io, .{
.argv = &.{
"blueprint-compiler",
"compile",
"--output",
output,
input,
},
}) catch |err| switch (err) {
error.FileNotFound => {
std.debug.print(
\\`blueprint-compiler` not found.
++ blueprint_compiler_help,
.{required_blueprint_version},
);
std.process.exit(1);
},
else => return err,
};
defer {
alloc.free(blueprint_compiler.stdout);
alloc.free(blueprint_compiler.stderr);
}
switch (blueprint_compiler.term) {
.exited => |rc| {
if (rc != 0) {
std.debug.print("{s}", .{blueprint_compiler.stderr});
std.process.exit(1);
}
},
else => {
std.debug.print("{s}", .{blueprint_compiler.stderr});
std.process.exit(1);
},
}
}
}
|