master
1const std = @import("std");
2const Step = std.Build.Step;
3const LazyPath = std.Build.LazyPath;
4const InstallDir = std.Build.InstallDir;
5const InstallFile = @This();
6const assert = std.debug.assert;
7
8pub const base_id: Step.Id = .install_file;
9
10step: Step,
11source: LazyPath,
12dir: InstallDir,
13dest_rel_path: []const u8,
14
15pub fn create(
16 owner: *std.Build,
17 source: LazyPath,
18 dir: InstallDir,
19 dest_rel_path: []const u8,
20) *InstallFile {
21 assert(dest_rel_path.len != 0);
22 const install_file = owner.allocator.create(InstallFile) catch @panic("OOM");
23 install_file.* = .{
24 .step = Step.init(.{
25 .id = base_id,
26 .name = owner.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }),
27 .owner = owner,
28 .makeFn = make,
29 }),
30 .source = source.dupe(owner),
31 .dir = dir.dupe(owner),
32 .dest_rel_path = owner.dupePath(dest_rel_path),
33 };
34 source.addStepDependencies(&install_file.step);
35 return install_file;
36}
37
38fn make(step: *Step, options: Step.MakeOptions) !void {
39 _ = options;
40 const b = step.owner;
41 const install_file: *InstallFile = @fieldParentPtr("step", step);
42 try step.singleUnchangingWatchInput(install_file.source);
43
44 const full_dest_path = b.getInstallPath(install_file.dir, install_file.dest_rel_path);
45 const p = try step.installFile(install_file.source, full_dest_path);
46 step.result_cached = p == .fresh;
47}