-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
94 lines (76 loc) · 2.93 KB
/
build.zig
File metadata and controls
94 lines (76 loc) · 2.93 KB
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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const version = getVersion(b);
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const options = b.addOptions();
options.addOption([]const u8, "version", version);
exe_mod.addOptions("build_options", options);
const exe = b.addExecutable(.{
.name = "zvelte-check",
.root_module = exe_mod,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the application");
run_step.dependOn(&run_cmd.step);
const test_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
test_mod.addOptions("build_options", options);
const test_step = b.step("test", "Run unit tests");
const exe_tests = b.addTest(.{
.root_module = test_mod,
});
test_step.dependOn(&b.addRunArtifact(exe_tests).step);
const fmt_check = b.addFmt(.{ .paths = &.{ "src", "build.zig", "build.zig.zon" } });
test_step.dependOn(&fmt_check.step);
// dump-transform: outputs generated TypeScript for debugging
const dump_mod = b.createModule(.{
.root_source_file = b.path("src/dump_transform.zig"),
.target = target,
.optimize = optimize,
});
const dump_exe = b.addExecutable(.{
.name = "dump-transform",
.root_module = dump_mod,
});
b.installArtifact(dump_exe);
const dump_cmd = b.addRunArtifact(dump_exe);
dump_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
dump_cmd.addArgs(args);
}
const dump_step = b.step("dump", "Dump transformer output for a .svelte file");
dump_step.dependOn(&dump_cmd.step);
}
fn getVersion(b: *std.Build) []const u8 {
var code: u8 = undefined;
const git_describe = b.runAllowFail(&.{ "git", "describe", "--match", "v*.*.*", "--tags" }, &code, .Ignore) catch {
return "unknown";
};
const trimmed = std.mem.trim(u8, git_describe, " \n\r");
const without_v = if (trimmed.len > 0 and trimmed[0] == 'v') trimmed[1..] else trimmed;
if (std.mem.indexOfScalar(u8, without_v, '-')) |dash_idx| {
const tag_part = without_v[0..dash_idx];
const rest = without_v[dash_idx + 1 ..];
if (std.mem.indexOfScalar(u8, rest, '-')) |second_dash| {
const count = rest[0..second_dash];
const hash = rest[second_dash + 1 ..];
const hash_without_g = if (hash.len > 0 and hash[0] == 'g') hash[1..] else hash;
return b.fmt("{s}-{s}+{s}", .{ tag_part, count, hash_without_g });
}
}
return without_v;
}