| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | //! To get started, run this tool with no args and read the help message. |
| 2 | 2 | //! |
| 3 | | //! The build systems of glibc, musl, and FreeBSD require specifying a single target |
| 3 | //! The build systems of glibc, musl, FreeBSD, and NetBSD require specifying a single target |
| 4 | 4 | //! architecture. Meanwhile, Zig supports out-of-the-box cross compilation for |
| 5 | 5 | //! every target. So the process to create libc headers that Zig ships is to use |
| 6 | 6 | //! this tool. |
| 7 | 7 | //! |
| 8 | | //! First, use the glibc, musl, and FreeBSD build systems to create installations of all the |
| 9 | | //! targets in the `glibc_targets`, `musl_targets`, and `freebsd_targets` variables. |
| 10 | | //! Next, run this tool to create a new directory which puts .h files into |
| 8 | //! First, use the glibc, musl, FreeBSD, and NetBSD build systems to create installations of all the |
| 9 | //! targets in the `glibc_targets`, `musl_targets`, `freebsd_targets`, and `netbsd_targets` |
| 10 | //! variables. Next, run this tool to create a new directory which puts .h files into |
| 11 | 11 | //! <arch> subdirectories, with `generic` being files that apply to all architectures. |
| 12 | 12 | //! You'll then have to manually update Zig source repo with these new files. |
| 13 | 13 | |
| ... | ... | @@ -87,6 +87,21 @@ const freebsd_targets = [_]LibCTarget{ |
| 87 | 87 | .{ .arch = .x86_64, .abi = .none }, |
| 88 | 88 | }; |
| 89 | 89 | |
| 90 | const netbsd_targets = [_]LibCTarget{ |
| 91 | .{ .arch = .arm, .abi = .eabi }, |
| 92 | .{ .arch = .arm, .abi = .eabihf }, |
| 93 | .{ .arch = .aarch64, .abi = .none }, |
| 94 | .{ .arch = .m68k, .abi = .none }, |
| 95 | .{ .arch = .mips, .abi = .eabi }, |
| 96 | .{ .arch = .mips, .abi = .eabihf }, |
| 97 | .{ .arch = .powerpc, .abi = .eabi }, |
| 98 | .{ .arch = .powerpc, .abi = .eabihf }, |
| 99 | .{ .arch = .sparc, .abi = .none }, |
| 100 | .{ .arch = .sparc64, .abi = .none }, |
| 101 | .{ .arch = .x86, .abi = .none }, |
| 102 | .{ .arch = .x86_64, .abi = .none }, |
| 103 | }; |
| 104 | |
| 90 | 105 | const DestTarget = struct { |
| 91 | 106 | arch: Arch, |
| 92 | 107 | os: OsTag, |
| ... | ... | @@ -130,6 +145,7 @@ const LibCVendor = enum { |
| 130 | 145 | musl, |
| 131 | 146 | glibc, |
| 132 | 147 | freebsd, |
| 148 | netbsd, |
| 133 | 149 | }; |
| 134 | 150 | |
| 135 | 151 | pub fn main() !void { |
| ... | ... | @@ -177,6 +193,7 @@ pub fn main() !void { |
| 177 | 193 | .glibc => &glibc_targets, |
| 178 | 194 | .musl => &musl_targets, |
| 179 | 195 | .freebsd => &freebsd_targets, |
| 196 | .netbsd => &netbsd_targets, |
| 180 | 197 | }; |
| 181 | 198 | |
| 182 | 199 | var path_table = PathTable.init(allocator); |
| ... | ... | @@ -192,25 +209,49 @@ pub fn main() !void { |
| 192 | 209 | .musl => std.zig.target.muslArchName(libc_target.arch, libc_target.abi), |
| 193 | 210 | .freebsd => switch (libc_target.arch) { |
| 194 | 211 | .arm => "armv7", |
| 195 | | .aarch64 => "aarch64", |
| 196 | | .powerpc => "powerpc", |
| 197 | | .powerpc64 => "powerpc64", |
| 198 | | .powerpc64le => "powerpc64le", |
| 199 | | .riscv64 => "riscv64", |
| 200 | 212 | .x86 => "i386", |
| 201 | 213 | .x86_64 => "amd64", |
| 214 | |
| 215 | .aarch64, |
| 216 | .powerpc, |
| 217 | .powerpc64, |
| 218 | .riscv64, |
| 219 | => |a| @tagName(a), |
| 220 | |
| 221 | else => unreachable, |
| 222 | }, |
| 223 | .netbsd => switch (libc_target.arch) { |
| 224 | .arm => if (libc_target.abi == .eabihf) "evbarmv7hf" else "evbarmv7", |
| 225 | .aarch64 => "evbarm64", |
| 226 | .m68k => "mac68k", |
| 227 | .mips => if (libc_target.abi == .eabihf) "evbmips" else "evbmipssf", |
| 228 | .powerpc => if (libc_target.abi == .eabihf) "evbppc" else "evbppcsf", |
| 229 | .x86 => "i386", |
| 230 | .x86_64 => "amd64", |
| 231 | |
| 232 | .sparc, |
| 233 | .sparc64, |
| 234 | => |a| @tagName(a), |
| 235 | |
| 202 | 236 | else => unreachable, |
| 203 | 237 | }, |
| 204 | 238 | }; |
| 205 | 239 | const dest_target = DestTarget{ |
| 206 | 240 | .arch = libc_target.arch, |
| 207 | | .os = if (vendor == .freebsd) .freebsd else .linux, |
| 241 | .os = switch (vendor) { |
| 242 | .musl, .glibc => .linux, |
| 243 | .freebsd => .freebsd, |
| 244 | .netbsd => .netbsd, |
| 245 | }, |
| 208 | 246 | .abi = libc_target.abi, |
| 209 | 247 | }; |
| 210 | 248 | |
| 211 | 249 | search: for (search_paths.items) |search_path| { |
| 212 | 250 | const sub_path = switch (vendor) { |
| 213 | | .glibc, .freebsd => &[_][]const u8{ search_path, libc_dir, "usr", "include" }, |
| 251 | .glibc, |
| 252 | .freebsd, |
| 253 | .netbsd, |
| 254 | => &[_][]const u8{ search_path, libc_dir, "usr", "include" }, |
| 214 | 255 | .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" }, |
| 215 | 256 | }; |
| 216 | 257 | const target_include_dir = try std.fs.path.join(allocator, sub_path); |
| ... | ... | @@ -339,6 +380,6 @@ fn usageAndExit(arg0: []const u8) noreturn { |
| 339 | 380 | std.debug.print("--search-path can be used any number of times.\n", .{}); |
| 340 | 381 | std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{}); |
| 341 | 382 | std.debug.print("--out is a dir that will be created, and populated with the results\n", .{}); |
| 342 | | std.debug.print("--abi is either glibc, musl, or freebsd\n", .{}); |
| 383 | std.debug.print("--abi is either glibc, musl, freebsd, or netbsd\n", .{}); |
| 343 | 384 | std.process.exit(1); |
| 344 | 385 | } |