Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
141 lines (130 loc) · 4.77 KB
/
Copy pathbuild.zig
File metadata and controls
141 lines (130 loc) · 4.77 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
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
const std = @import("std");
const Build = std.Build;
const version = "31.0.4-preview";
pub fn build(b: *Build) !void {
const metadata_nupkg_file = blk: {
const download_winmd_nupkg = b.addSystemCommand(&.{
"curl",
"https://www.nuget.org/api/v2/package/Microsoft.Windows.SDK.Win32Metadata/" ++ version,
"--location",
"--output",
});
break :blk download_winmd_nupkg.addOutputFileArg("win32metadata.nupkg");
};
const metadata_nupkg_out = blk: {
const zipcmdline = b.dependency("zipcmdline", .{
.target = b.graph.host,
});
const unzip_exe = zipcmdline.artifact("unzip");
const unzip_metadata = b.addRunArtifact(unzip_exe);
unzip_metadata.addFileArg(metadata_nupkg_file);
unzip_metadata.addArg("-d");
break :blk unzip_metadata.addOutputDirectoryArg("nupkg");
};
const winmd = metadata_nupkg_out.path(b, "Windows.Win32.winmd");
b.step(
"show-winmd",
"Print the winmd file path in the cache",
).dependOn(
&PrintLazyPath.create(b, winmd).step,
);
const gen_step = b.step("gen", "Generate JSON files (in .zig-cache)");
const winmd_dep = b.dependency("winmd", .{});
const gen_out_dir = blk: {
const exe = b.addExecutable(.{
.name = "genjson",
.root_module = b.createModule(.{
.root_source_file = b.path("src/genjson.zig"),
.target = b.graph.host,
}),
});
exe.root_module.addImport("winmd", winmd_dep.module("winmd"));
{
const genjson = b.addRunArtifact(exe);
if (b.args) |a| genjson.addArgs(a);
b.step("genjson", "").dependOn(&genjson.step);
}
const run = b.addRunArtifact(exe);
run.addFileArg(winmd);
const out_dir = run.addOutputDirectoryArg(".");
gen_step.dependOn(&run.step);
break :blk out_dir;
};
const win32json = b.option(
[]const u8,
"win32json",
"Path to the win32json repository to install the output to.",
) orelse b.pathResolve(&.{ b.build_root.path.?, "win32json" });
{
// we can't use b.installDirectory because we need to make sure we delete
// all existing files before installing the new ones in case JSON files are removed
// b.installDirectory(.{
// .source_dir = gen_out_dir,
// .install_dir = .prefix,
// .install_subdir = ".",
// });
const install_exe = b.addExecutable(.{
.name = "install",
.root_module = b.createModule(.{
.root_source_file = b.path("src/install.zig"),
.target = b.graph.host,
}),
});
install_exe.rc_includes = .none;
install_exe.addWin32ResourceFile(.{ .file = b.path("src/win32/install.rc") });
const install = b.addRunArtifact(install_exe);
install.addArg(version);
install.addDirectoryArg(gen_out_dir);
install.addFileArg(b.path("src/static/README.md"));
install.addFileArg(b.path("src/static/LICENSE"));
install.addArg(win32json);
b.getInstallStep().dependOn(&install.step);
}
const test_step = b.step("test", "Run all the tests");
{
const validate_exe = b.addExecutable(.{
.name = "validate",
.root_module = b.createModule(.{
.root_source_file = b.path("src/validate.zig"),
.target = b.graph.host,
.optimize = .Debug,
}),
});
const validate = b.addRunArtifact(validate_exe);
validate.addDirectoryArg(gen_out_dir);
validate.expectExitCode(0);
test_step.dependOn(&validate.step);
}
}
const PrintLazyPath = struct {
step: std.Build.Step,
lazy_path: Build.LazyPath,
pub fn create(
b: *Build,
lazy_path: Build.LazyPath,
) *PrintLazyPath {
const print = b.allocator.create(PrintLazyPath) catch unreachable;
print.* = .{
.step = std.Build.Step.init(.{
.id = .custom,
.name = "print the given lazy path",
.owner = b,
.makeFn = make,
}),
.lazy_path = lazy_path,
};
lazy_path.addStepDependencies(&print.step);
return print;
}
fn make(step: *std.Build.Step, opt: std.Build.Step.MakeOptions) !void {
_ = opt;
const print: *PrintLazyPath = @fieldParentPtr("step", step);
var write_buf: [1024]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print(
"{s}\n",
.{print.lazy_path.getPath(step.owner)},
);
try stdout.interface.flush();
}
};