2020-03-21 14:12:28 +00:00
|
|
|
//! To get started, run this tool with no args and read the help message.
|
|
|
|
//!
|
|
|
|
//! The build systems of musl-libc and glibc require specifying a single target
|
|
|
|
//! architecture. Meanwhile, Zig supports out-of-the-box cross compilation for
|
|
|
|
//! every target. So the process to create libc headers that Zig ships is to use
|
|
|
|
//! this tool.
|
|
|
|
//! First, use the musl/glibc build systems to create installations of all the
|
|
|
|
//! targets in the `glibc_targets`/`musl_targets` variables.
|
|
|
|
//! Next, run this tool to create a new directory which puts .h files into
|
|
|
|
//! <arch> subdirectories, with `generic` being files that apply to all architectures.
|
|
|
|
//! You'll then have to manually update Zig source repo with these new files.
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
const std = @import("std");
|
2020-03-04 03:40:41 +00:00
|
|
|
const Arch = std.Target.Cpu.Arch;
|
|
|
|
const Abi = std.Target.Abi;
|
|
|
|
const OsTag = std.Target.Os.Tag;
|
2019-03-06 22:42:41 +00:00
|
|
|
const assert = std.debug.assert;
|
2020-08-31 05:21:22 +01:00
|
|
|
const Blake3 = std.crypto.hash.Blake3;
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
const LibCTarget = struct {
|
|
|
|
name: []const u8,
|
2024-10-16 02:38:15 +01:00
|
|
|
arch: Arch,
|
|
|
|
abi: Abi,
|
2019-09-07 19:46:59 +01:00
|
|
|
};
|
|
|
|
|
2019-07-17 00:02:51 +01:00
|
|
|
const glibc_targets = [_]LibCTarget{
|
2024-10-16 02:38:15 +01:00
|
|
|
.{ .name = "arc-linux-gnu", .arch = .arc, .abi = .gnu },
|
|
|
|
.{ .name = "arm-linux-gnueabi", .arch = .arm, .abi = .gnueabi },
|
|
|
|
.{ .name = "arm-linux-gnueabihf", .arch = .arm, .abi = .gnueabihf },
|
|
|
|
.{ .name = "armeb-linux-gnueabi", .arch = .armeb, .abi = .gnueabi },
|
|
|
|
.{ .name = "armeb-linux-gnueabihf", .arch = .armeb, .abi = .gnueabihf },
|
|
|
|
.{ .name = "aarch64-linux-gnu", .arch = .aarch64, .abi = .gnu },
|
|
|
|
.{ .name = "aarch64_be-linux-gnu", .arch = .aarch64_be, .abi = .gnu },
|
|
|
|
.{ .name = "csky-linux-gnuabiv2-soft", .arch = .csky, .abi = .gnueabi },
|
|
|
|
.{ .name = "csky-linux-gnuabiv2", .arch = .csky, .abi = .gnueabihf },
|
|
|
|
.{ .name = "loongarch64-linux-gnu-lp64d", .arch = .loongarch64, .abi = .gnu },
|
|
|
|
.{ .name = "loongarch64-linux-gnu-lp64s", .arch = .loongarch64, .abi = .gnusf },
|
|
|
|
.{ .name = "m68k-linux-gnu", .arch = .m68k, .abi = .gnu },
|
|
|
|
.{ .name = "mips-linux-gnu", .arch = .mips, .abi = .gnueabihf },
|
|
|
|
.{ .name = "mips-linux-gnu-soft", .arch = .mips, .abi = .gnueabi },
|
|
|
|
.{ .name = "mipsel-linux-gnu-soft", .arch = .mipsel, .abi = .gnueabi },
|
|
|
|
.{ .name = "mipsel-linux-gnu", .arch = .mipsel, .abi = .gnueabihf },
|
|
|
|
.{ .name = "mips64-linux-gnu-n64", .arch = .mips64, .abi = .gnuabi64 },
|
|
|
|
.{ .name = "mips64-linux-gnu-n32", .arch = .mips64, .abi = .gnuabin32 },
|
|
|
|
.{ .name = "mips64el-linux-gnu-n64", .arch = .mips64el, .abi = .gnuabi64 },
|
|
|
|
.{ .name = "mips64el-linux-gnu-n32", .arch = .mips64el, .abi = .gnuabin32 },
|
|
|
|
.{ .name = "powerpc-linux-gnu-soft", .arch = .powerpc, .abi = .gnueabi },
|
|
|
|
.{ .name = "powerpc-linux-gnu", .arch = .powerpc, .abi = .gnueabihf },
|
|
|
|
.{ .name = "powerpc64-linux-gnu", .arch = .powerpc64, .abi = .gnu },
|
|
|
|
.{ .name = "powerpc64le-linux-gnu", .arch = .powerpc64le, .abi = .gnu },
|
|
|
|
.{ .name = "riscv32-linux-gnu-rv32imafdc-ilp32d", .arch = .riscv32, .abi = .gnu },
|
|
|
|
.{ .name = "riscv64-linux-gnu-rv64imafdc-lp64d", .arch = .riscv64, .abi = .gnu },
|
|
|
|
.{ .name = "s390x-linux-gnu", .arch = .s390x, .abi = .gnu },
|
|
|
|
.{ .name = "sparcv9-linux-gnu", .arch = .sparc, .abi = .gnu },
|
|
|
|
.{ .name = "sparc64-linux-gnu", .arch = .sparc64, .abi = .gnu },
|
|
|
|
.{ .name = "i686-linux-gnu", .arch = .x86, .abi = .gnu },
|
|
|
|
.{ .name = "x86_64-linux-gnu", .arch = .x86_64, .abi = .gnu },
|
|
|
|
.{ .name = "x86_64-linux-gnu-x32", .arch = .x86_64, .abi = .gnux32 },
|
2019-03-06 22:42:41 +00:00
|
|
|
};
|
2019-07-17 00:02:51 +01:00
|
|
|
|
|
|
|
const musl_targets = [_]LibCTarget{
|
2024-10-16 02:38:15 +01:00
|
|
|
.{ .name = "arm", .arch = .arm, .abi = .musl },
|
|
|
|
.{ .name = "aarch64", .arch = .aarch64, .abi = .musl },
|
|
|
|
.{ .name = "loongarch64", .arch = .loongarch64, .abi = .musl },
|
|
|
|
.{ .name = "m68k", .arch = .m68k, .abi = .musl },
|
|
|
|
.{ .name = "mips", .arch = .mips, .abi = .musl },
|
|
|
|
.{ .name = "mips64", .arch = .mips64, .abi = .musl },
|
2024-10-16 03:41:52 +01:00
|
|
|
.{ .name = "mipsn32", .arch = .mips64, .abi = .muslabin32 },
|
2024-10-16 02:38:15 +01:00
|
|
|
.{ .name = "powerpc", .arch = .powerpc, .abi = .musl },
|
|
|
|
.{ .name = "powerpc64", .arch = .powerpc64, .abi = .musl },
|
|
|
|
.{ .name = "riscv32", .arch = .riscv32, .abi = .musl },
|
|
|
|
.{ .name = "riscv64", .arch = .riscv64, .abi = .musl },
|
|
|
|
.{ .name = "s390x", .arch = .s390x, .abi = .musl },
|
|
|
|
.{ .name = "i386", .arch = .x86, .abi = .musl },
|
|
|
|
.{ .name = "x86_64", .arch = .x86_64, .abi = .musl },
|
2024-10-16 03:41:52 +01:00
|
|
|
.{ .name = "x32", .arch = .x86_64, .abi = .muslx32 },
|
2019-03-12 14:28:05 +00:00
|
|
|
};
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
const DestTarget = struct {
|
2024-10-16 02:38:15 +01:00
|
|
|
arch: Arch,
|
2020-03-04 03:40:41 +00:00
|
|
|
os: OsTag,
|
2019-03-06 22:42:41 +00:00
|
|
|
abi: Abi,
|
|
|
|
|
2021-06-13 19:36:51 +01:00
|
|
|
const HashContext = struct {
|
|
|
|
pub fn hash(self: @This(), a: DestTarget) u32 {
|
2021-06-20 02:10:22 +01:00
|
|
|
_ = self;
|
2023-06-15 08:14:16 +01:00
|
|
|
return @intFromEnum(a.arch) +%
|
|
|
|
(@intFromEnum(a.os) *% @as(u32, 4202347608)) +%
|
|
|
|
(@intFromEnum(a.abi) *% @as(u32, 4082223418));
|
2021-06-13 19:36:51 +01:00
|
|
|
}
|
2019-03-06 22:42:41 +00:00
|
|
|
|
2022-05-29 09:37:16 +01:00
|
|
|
pub fn eql(self: @This(), a: DestTarget, b: DestTarget, b_index: usize) bool {
|
2021-06-20 02:10:22 +01:00
|
|
|
_ = self;
|
2022-05-29 09:37:16 +01:00
|
|
|
_ = b_index;
|
2024-10-16 02:38:15 +01:00
|
|
|
return a.arch == b.arch and
|
2021-06-13 19:36:51 +01:00
|
|
|
a.os == b.os and
|
|
|
|
a.abi == b.abi;
|
|
|
|
}
|
|
|
|
};
|
2019-03-06 22:42:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Contents = struct {
|
|
|
|
bytes: []const u8,
|
|
|
|
hit_count: usize,
|
|
|
|
hash: []const u8,
|
|
|
|
is_generic: bool,
|
|
|
|
|
2020-06-12 15:32:02 +01:00
|
|
|
fn hitCountLessThan(context: void, lhs: *const Contents, rhs: *const Contents) bool {
|
2021-06-20 02:10:22 +01:00
|
|
|
_ = context;
|
2019-03-06 22:42:41 +00:00
|
|
|
return lhs.hit_count < rhs.hit_count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-22 21:46:37 +01:00
|
|
|
const HashToContents = std.StringHashMap(Contents);
|
2021-06-13 19:36:51 +01:00
|
|
|
const TargetToHash = std.ArrayHashMap(DestTarget, []const u8, DestTarget.HashContext, true);
|
2019-08-22 21:46:37 +01:00
|
|
|
const PathTable = std.StringHashMap(*TargetToHash);
|
2019-03-06 22:42:41 +00:00
|
|
|
|
2019-07-17 00:02:51 +01:00
|
|
|
const LibCVendor = enum {
|
|
|
|
musl,
|
|
|
|
glibc,
|
|
|
|
};
|
|
|
|
|
2019-03-06 22:42:41 +00:00
|
|
|
pub fn main() !void {
|
2019-11-25 22:25:06 +00:00
|
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
2021-10-29 02:08:41 +01:00
|
|
|
const allocator = arena.allocator();
|
2019-07-17 00:02:51 +01:00
|
|
|
const args = try std.process.argsAlloc(allocator);
|
2019-03-06 22:42:41 +00:00
|
|
|
var search_paths = std.ArrayList([]const u8).init(allocator);
|
|
|
|
var opt_out_dir: ?[]const u8 = null;
|
2019-03-12 14:28:05 +00:00
|
|
|
var opt_abi: ?[]const u8 = null;
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
var arg_i: usize = 1;
|
|
|
|
while (arg_i < args.len) : (arg_i += 1) {
|
|
|
|
if (std.mem.eql(u8, args[arg_i], "--help"))
|
|
|
|
usageAndExit(args[0]);
|
|
|
|
if (arg_i + 1 >= args.len) {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("expected argument after '{s}'\n", .{args[arg_i]});
|
2019-03-06 22:42:41 +00:00
|
|
|
usageAndExit(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std.mem.eql(u8, args[arg_i], "--search-path")) {
|
|
|
|
try search_paths.append(args[arg_i + 1]);
|
|
|
|
} else if (std.mem.eql(u8, args[arg_i], "--out")) {
|
|
|
|
assert(opt_out_dir == null);
|
|
|
|
opt_out_dir = args[arg_i + 1];
|
2019-03-12 14:28:05 +00:00
|
|
|
} else if (std.mem.eql(u8, args[arg_i], "--abi")) {
|
|
|
|
assert(opt_abi == null);
|
|
|
|
opt_abi = args[arg_i + 1];
|
2019-03-06 22:42:41 +00:00
|
|
|
} else {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]});
|
2019-03-06 22:42:41 +00:00
|
|
|
usageAndExit(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
arg_i += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const out_dir = opt_out_dir orelse usageAndExit(args[0]);
|
2019-03-12 14:28:05 +00:00
|
|
|
const abi_name = opt_abi orelse usageAndExit(args[0]);
|
2024-10-16 02:38:15 +01:00
|
|
|
const vendor = std.meta.stringToEnum(LibCVendor, abi_name) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("unrecognized C ABI: {s}\n", .{abi_name});
|
2019-03-12 14:28:05 +00:00
|
|
|
usageAndExit(args[0]);
|
|
|
|
};
|
2019-07-17 00:02:51 +01:00
|
|
|
|
2024-10-16 02:38:15 +01:00
|
|
|
const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name});
|
|
|
|
const libc_targets = switch (vendor) {
|
|
|
|
.glibc => &glibc_targets,
|
|
|
|
.musl => &musl_targets,
|
|
|
|
};
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
var path_table = PathTable.init(allocator);
|
|
|
|
var hash_to_contents = HashToContents.init(allocator);
|
|
|
|
var max_bytes_saved: usize = 0;
|
|
|
|
var total_bytes: usize = 0;
|
|
|
|
|
2020-08-31 05:21:22 +01:00
|
|
|
var hasher = Blake3.init(.{});
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
for (libc_targets) |libc_target| {
|
|
|
|
const dest_target = DestTarget{
|
2019-07-17 00:02:51 +01:00
|
|
|
.arch = libc_target.arch,
|
|
|
|
.os = .linux,
|
2024-10-16 02:38:15 +01:00
|
|
|
.abi = libc_target.abi,
|
2019-03-06 22:42:41 +00:00
|
|
|
};
|
2024-10-16 02:38:15 +01:00
|
|
|
|
2020-11-06 18:54:08 +00:00
|
|
|
search: for (search_paths.items) |search_path| {
|
2024-10-16 02:38:15 +01:00
|
|
|
const sub_path = switch (vendor) {
|
|
|
|
.glibc => &[_][]const u8{ search_path, libc_target.name, "usr", "include" },
|
|
|
|
.musl => &[_][]const u8{ search_path, libc_target.name, "usr", "local", "musl", "include" },
|
|
|
|
};
|
2019-07-17 00:02:51 +01:00
|
|
|
const target_include_dir = try std.fs.path.join(allocator, sub_path);
|
2019-03-06 22:42:41 +00:00
|
|
|
var dir_stack = std.ArrayList([]const u8).init(allocator);
|
|
|
|
try dir_stack.append(target_include_dir);
|
|
|
|
|
|
|
|
while (dir_stack.popOrNull()) |full_dir_name| {
|
2023-11-22 19:35:33 +00:00
|
|
|
var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
|
2019-03-06 22:42:41 +00:00
|
|
|
error.FileNotFound => continue :search,
|
|
|
|
error.AccessDenied => continue :search,
|
|
|
|
else => return err,
|
|
|
|
};
|
2023-11-22 19:35:33 +00:00
|
|
|
defer dir.close();
|
2019-03-06 22:42:41 +00:00
|
|
|
|
2023-11-22 19:35:33 +00:00
|
|
|
var dir_it = dir.iterate();
|
2020-03-04 03:40:41 +00:00
|
|
|
|
|
|
|
while (try dir_it.next()) |entry| {
|
|
|
|
const full_path = try std.fs.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name });
|
2019-03-06 22:42:41 +00:00
|
|
|
switch (entry.kind) {
|
2023-05-20 23:06:42 +01:00
|
|
|
.directory => try dir_stack.append(full_path),
|
|
|
|
.file => {
|
2019-07-17 00:02:51 +01:00
|
|
|
const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path);
|
2020-08-09 13:57:49 +01:00
|
|
|
const max_size = 2 * 1024 * 1024 * 1024;
|
|
|
|
const raw_bytes = try std.fs.cwd().readFileAlloc(allocator, full_path, max_size);
|
2019-03-06 22:42:41 +00:00
|
|
|
const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
|
|
|
|
total_bytes += raw_bytes.len;
|
|
|
|
const hash = try allocator.alloc(u8, 32);
|
2020-08-31 05:21:22 +01:00
|
|
|
hasher = Blake3.init(.{});
|
2019-03-06 22:42:41 +00:00
|
|
|
hasher.update(rel_path);
|
|
|
|
hasher.update(trimmed);
|
|
|
|
hasher.final(hash);
|
|
|
|
const gop = try hash_to_contents.getOrPut(hash);
|
|
|
|
if (gop.found_existing) {
|
|
|
|
max_bytes_saved += raw_bytes.len;
|
2021-06-03 21:39:26 +01:00
|
|
|
gop.value_ptr.hit_count += 1;
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("duplicate: {s} {s} ({:2})\n", .{
|
2019-03-06 22:42:41 +00:00
|
|
|
libc_target.name,
|
|
|
|
rel_path,
|
2021-03-06 08:57:21 +00:00
|
|
|
std.fmt.fmtIntSizeDec(raw_bytes.len),
|
2020-01-09 09:56:38 +00:00
|
|
|
});
|
2019-03-06 22:42:41 +00:00
|
|
|
} else {
|
2021-06-03 21:39:26 +01:00
|
|
|
gop.value_ptr.* = Contents{
|
2019-03-06 22:42:41 +00:00
|
|
|
.bytes = trimmed,
|
|
|
|
.hit_count = 1,
|
|
|
|
.hash = hash,
|
|
|
|
.is_generic = false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const path_gop = try path_table.getOrPut(rel_path);
|
2021-06-03 21:39:26 +01:00
|
|
|
const target_to_hash = if (path_gop.found_existing) path_gop.value_ptr.* else blk: {
|
2019-03-06 22:42:41 +00:00
|
|
|
const ptr = try allocator.create(TargetToHash);
|
|
|
|
ptr.* = TargetToHash.init(allocator);
|
2021-06-03 21:39:26 +01:00
|
|
|
path_gop.value_ptr.* = ptr;
|
2019-03-06 22:42:41 +00:00
|
|
|
break :blk ptr;
|
|
|
|
};
|
2020-08-09 13:57:49 +01:00
|
|
|
try target_to_hash.putNoClobber(dest_target, hash);
|
2019-03-06 22:42:41 +00:00
|
|
|
},
|
2021-11-30 07:13:07 +00:00
|
|
|
else => std.debug.print("warning: weird file: {s}\n", .{full_path}),
|
2019-03-06 22:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("warning: libc target not found: {s}\n", .{libc_target.name});
|
2019-03-06 22:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("summary: {:2} could be reduced to {:2}\n", .{
|
2021-03-06 08:57:21 +00:00
|
|
|
std.fmt.fmtIntSizeDec(total_bytes),
|
|
|
|
std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),
|
|
|
|
});
|
2020-03-04 03:40:41 +00:00
|
|
|
try std.fs.cwd().makePath(out_dir);
|
2019-03-06 22:42:41 +00:00
|
|
|
|
|
|
|
var missed_opportunity_bytes: usize = 0;
|
|
|
|
// iterate path_table. for each path, put all the hashes into a list. sort by hit_count.
|
|
|
|
// the hash with the highest hit_count gets to be the "generic" one. everybody else
|
|
|
|
// gets their header in a separate arch directory.
|
|
|
|
var path_it = path_table.iterator();
|
|
|
|
while (path_it.next()) |path_kv| {
|
|
|
|
var contents_list = std.ArrayList(*Contents).init(allocator);
|
|
|
|
{
|
2021-06-13 19:36:51 +01:00
|
|
|
var hash_it = path_kv.value_ptr.*.iterator();
|
2019-03-06 22:42:41 +00:00
|
|
|
while (hash_it.next()) |hash_kv| {
|
2021-06-13 19:36:51 +01:00
|
|
|
const contents = hash_to_contents.getPtr(hash_kv.value_ptr.*).?;
|
2019-03-06 22:42:41 +00:00
|
|
|
try contents_list.append(contents);
|
|
|
|
}
|
|
|
|
}
|
2023-05-23 13:03:12 +01:00
|
|
|
std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan);
|
2020-08-31 05:21:22 +01:00
|
|
|
const best_contents = contents_list.popOrNull().?;
|
2019-03-06 22:42:41 +00:00
|
|
|
if (best_contents.hit_count > 1) {
|
|
|
|
// worth it to make it generic
|
2021-06-13 19:36:51 +01:00
|
|
|
const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
|
2020-03-04 03:40:41 +00:00
|
|
|
try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
|
2024-05-03 04:54:48 +01:00
|
|
|
try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
|
2019-03-06 22:42:41 +00:00
|
|
|
best_contents.is_generic = true;
|
|
|
|
while (contents_list.popOrNull()) |contender| {
|
|
|
|
if (contender.hit_count > 1) {
|
|
|
|
const this_missed_bytes = contender.hit_count * contender.bytes.len;
|
|
|
|
missed_opportunity_bytes += this_missed_bytes;
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Missed opportunity ({:2}): {s}\n", .{
|
2021-03-06 08:57:21 +00:00
|
|
|
std.fmt.fmtIntSizeDec(this_missed_bytes),
|
2021-06-13 19:36:51 +01:00
|
|
|
path_kv.key_ptr.*,
|
2021-03-06 08:57:21 +00:00
|
|
|
});
|
2019-03-06 22:42:41 +00:00
|
|
|
} else break;
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 19:36:51 +01:00
|
|
|
var hash_it = path_kv.value_ptr.*.iterator();
|
2019-03-06 22:42:41 +00:00
|
|
|
while (hash_it.next()) |hash_kv| {
|
2021-06-13 19:36:51 +01:00
|
|
|
const contents = hash_to_contents.get(hash_kv.value_ptr.*).?;
|
2019-03-06 22:42:41 +00:00
|
|
|
if (contents.is_generic) continue;
|
|
|
|
|
2021-06-13 19:36:51 +01:00
|
|
|
const dest_target = hash_kv.key_ptr.*;
|
2021-03-06 08:57:21 +00:00
|
|
|
const out_subpath = try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{
|
2024-10-16 02:38:15 +01:00
|
|
|
@tagName(dest_target.arch),
|
2019-03-06 22:42:41 +00:00
|
|
|
@tagName(dest_target.os),
|
|
|
|
@tagName(dest_target.abi),
|
2020-01-09 09:56:38 +00:00
|
|
|
});
|
2021-06-13 19:36:51 +01:00
|
|
|
const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* });
|
2020-03-04 03:40:41 +00:00
|
|
|
try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
|
2024-05-03 04:54:48 +01:00
|
|
|
try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });
|
2019-03-06 22:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usageAndExit(arg0: []const u8) noreturn {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0});
|
|
|
|
std.debug.print("--search-path can be used any number of times.\n", .{});
|
|
|
|
std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});
|
|
|
|
std.debug.print("--out is a dir that will be created, and populated with the results\n", .{});
|
|
|
|
std.debug.print("--abi is either musl or glibc\n", .{});
|
2019-07-17 00:02:51 +01:00
|
|
|
std.process.exit(1);
|
2019-03-06 22:42:41 +00:00
|
|
|
}
|