build: fix script installation

This commit is contained in:
LordMZTE 2024-10-19 11:02:36 +02:00
parent 0699824fb2
commit 35737f9d04
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -12,7 +12,53 @@ pub fn addScript(b: *std.Build, opts: Options, src: []const u8, dest: []const u8
pub fn addZBuild(b: *std.Build, opts: Options, args: anytype, dep: []const u8) void {
if (opts.isBlacklisted(dep)) return;
for (b.dependency(dep, args).builder.install_tls.step.dependencies.items) |d| {
b.installArtifact((d.cast(std.Build.Step.InstallArtifact) orelse continue).artifact);
}
const dependency = b.dependency(dep, args);
b.getInstallStep().dependOn(&InstallDepStep.init(b, dependency).step);
}
pub const InstallDepStep = struct {
step: std.Build.Step,
dep: *std.Build.Dependency,
pub fn init(b: *std.Build, dep: *std.Build.Dependency) *InstallDepStep {
const self = b.allocator.create(InstallDepStep) catch @panic("OOM");
self.* = .{
.step = std.Build.Step.init(.{
.owner = b,
.id = .custom,
.name = "install-dep",
.makeFn = make,
}),
.dep = dep,
};
self.step.dependOn(&dep.builder.install_tls.step);
return self;
}
fn make(step: *std.Build.Step, prog_node: std.Progress.Node) anyerror!void {
_ = prog_node;
const self: *InstallDepStep = @fieldParentPtr("step", step);
var dir = try std.fs.cwd().openDir(self.dep.builder.install_prefix, .{
.iterate = true,
});
defer dir.close();
var iter = try dir.walk(step.owner.allocator);
while (try iter.next()) |ent| {
const outpath = step.owner.pathJoin(&.{ step.owner.install_prefix, ent.path });
switch (ent.kind) {
.directory => std.fs.cwd().makeDir(outpath) catch |e| switch (e) {
error.PathAlreadyExists => {},
else => return e,
},
else => {
const inpath = step.owner.pathJoin(&.{ self.dep.builder.install_prefix, ent.path });
try std.fs.cwd().copyFile(inpath, std.fs.cwd(), outpath, .{});
},
}
}
}
};