From 35737f9d04ec770ef1e17ecdf94cb6f381771bfe Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sat, 19 Oct 2024 11:02:36 +0200 Subject: [PATCH] build: fix script installation --- setup/installers.zig | 52 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/setup/installers.zig b/setup/installers.zig index 6a6f30a..10fc102 100644 --- a/setup/installers.zig +++ b/setup/installers.zig @@ -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, .{}); + }, + } + } + } +};