| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | | const builtin = @import("builtin"); |
| 3 | 2 | const fs = std.fs; |
| 4 | 3 | const fmt = std.fmt; |
| 5 | 4 | const assert = std.debug.assert; |
| ... | ... | @@ -11,8 +10,8 @@ const AbiList = struct { |
| 11 | 10 | path: []const u8, |
| 12 | 11 | }; |
| 13 | 12 | const ZigTarget = struct { |
| 14 | | arch: @TagType(builtin.Arch), |
| 15 | | abi: builtin.Abi, |
| 13 | arch: std.Target.Cpu.Arch, |
| 14 | abi: std.Target.Abi, |
| 16 | 15 | }; |
| 17 | 16 | |
| 18 | 17 | const lib_names = [_][]const u8{ |
| ... | ... | @@ -27,18 +26,18 @@ const lib_names = [_][]const u8{ |
| 27 | 26 | // n64/n32 are hardcoded elsewhere, based on .gnuabi64/.gnuabin32 |
| 28 | 27 | const abi_lists = [_]AbiList{ |
| 29 | 28 | AbiList{ |
| 30 | | .targets = [_]ZigTarget{ |
| 29 | .targets = &[_]ZigTarget{ |
| 31 | 30 | ZigTarget{ .arch = .aarch64, .abi = .gnu }, |
| 32 | 31 | ZigTarget{ .arch = .aarch64_be, .abi = .gnu }, |
| 33 | 32 | }, |
| 34 | 33 | .path = "aarch64", |
| 35 | 34 | }, |
| 36 | 35 | AbiList{ |
| 37 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .s390x, .abi = .gnu }}, |
| 36 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .s390x, .abi = .gnu }}, |
| 38 | 37 | .path = "s390/s390-64", |
| 39 | 38 | }, |
| 40 | 39 | AbiList{ |
| 41 | | .targets = [_]ZigTarget{ |
| 40 | .targets = &[_]ZigTarget{ |
| 42 | 41 | ZigTarget{ .arch = .arm, .abi = .gnueabi }, |
| 43 | 42 | ZigTarget{ .arch = .armeb, .abi = .gnueabi }, |
| 44 | 43 | ZigTarget{ .arch = .arm, .abi = .gnueabihf }, |
| ... | ... | @@ -47,66 +46,66 @@ const abi_lists = [_]AbiList{ |
| 47 | 46 | .path = "arm", |
| 48 | 47 | }, |
| 49 | 48 | AbiList{ |
| 50 | | .targets = [_]ZigTarget{ |
| 49 | .targets = &[_]ZigTarget{ |
| 51 | 50 | ZigTarget{ .arch = .sparc, .abi = .gnu }, |
| 52 | 51 | ZigTarget{ .arch = .sparcel, .abi = .gnu }, |
| 53 | 52 | }, |
| 54 | 53 | .path = "sparc/sparc32", |
| 55 | 54 | }, |
| 56 | 55 | AbiList{ |
| 57 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .sparcv9, .abi = .gnu }}, |
| 56 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .sparcv9, .abi = .gnu }}, |
| 58 | 57 | .path = "sparc/sparc64", |
| 59 | 58 | }, |
| 60 | 59 | AbiList{ |
| 61 | | .targets = [_]ZigTarget{ |
| 60 | .targets = &[_]ZigTarget{ |
| 62 | 61 | ZigTarget{ .arch = .mips64el, .abi = .gnuabi64 }, |
| 63 | 62 | ZigTarget{ .arch = .mips64, .abi = .gnuabi64 }, |
| 64 | 63 | }, |
| 65 | 64 | .path = "mips/mips64", |
| 66 | 65 | }, |
| 67 | 66 | AbiList{ |
| 68 | | .targets = [_]ZigTarget{ |
| 67 | .targets = &[_]ZigTarget{ |
| 69 | 68 | ZigTarget{ .arch = .mips64el, .abi = .gnuabin32 }, |
| 70 | 69 | ZigTarget{ .arch = .mips64, .abi = .gnuabin32 }, |
| 71 | 70 | }, |
| 72 | 71 | .path = "mips/mips64", |
| 73 | 72 | }, |
| 74 | 73 | AbiList{ |
| 75 | | .targets = [_]ZigTarget{ |
| 74 | .targets = &[_]ZigTarget{ |
| 76 | 75 | ZigTarget{ .arch = .mipsel, .abi = .gnueabihf }, |
| 77 | 76 | ZigTarget{ .arch = .mips, .abi = .gnueabihf }, |
| 78 | 77 | }, |
| 79 | 78 | .path = "mips/mips32", |
| 80 | 79 | }, |
| 81 | 80 | AbiList{ |
| 82 | | .targets = [_]ZigTarget{ |
| 81 | .targets = &[_]ZigTarget{ |
| 83 | 82 | ZigTarget{ .arch = .mipsel, .abi = .gnueabi }, |
| 84 | 83 | ZigTarget{ .arch = .mips, .abi = .gnueabi }, |
| 85 | 84 | }, |
| 86 | 85 | .path = "mips/mips32", |
| 87 | 86 | }, |
| 88 | 87 | AbiList{ |
| 89 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .x86_64, .abi = .gnu }}, |
| 88 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .x86_64, .abi = .gnu }}, |
| 90 | 89 | .path = "x86_64/64", |
| 91 | 90 | }, |
| 92 | 91 | AbiList{ |
| 93 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .x86_64, .abi = .gnux32 }}, |
| 92 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .x86_64, .abi = .gnux32 }}, |
| 94 | 93 | .path = "x86_64/x32", |
| 95 | 94 | }, |
| 96 | 95 | AbiList{ |
| 97 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .i386, .abi = .gnu }}, |
| 96 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .i386, .abi = .gnu }}, |
| 98 | 97 | .path = "i386", |
| 99 | 98 | }, |
| 100 | 99 | AbiList{ |
| 101 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .powerpc64le, .abi = .gnu }}, |
| 100 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .powerpc64le, .abi = .gnu }}, |
| 102 | 101 | .path = "powerpc/powerpc64/le", |
| 103 | 102 | }, |
| 104 | 103 | AbiList{ |
| 105 | | .targets = [_]ZigTarget{ZigTarget{ .arch = .powerpc64, .abi = .gnu }}, |
| 104 | .targets = &[_]ZigTarget{ZigTarget{ .arch = .powerpc64, .abi = .gnu }}, |
| 106 | 105 | .path = "powerpc/powerpc64/be", |
| 107 | 106 | }, |
| 108 | 107 | AbiList{ |
| 109 | | .targets = [_]ZigTarget{ |
| 108 | .targets = &[_]ZigTarget{ |
| 110 | 109 | ZigTarget{ .arch = .powerpc, .abi = .gnueabi }, |
| 111 | 110 | ZigTarget{ .arch = .powerpc, .abi = .gnueabihf }, |
| 112 | 111 | }, |
| ... | ... | @@ -137,8 +136,8 @@ pub fn main() !void { |
| 137 | 136 | const in_glibc_dir = args[1]; // path to the unzipped tarball of glibc, e.g. ~/downloads/glibc-2.25 |
| 138 | 137 | const zig_src_dir = args[2]; // path to the source checkout of zig, lib dir, e.g. ~/zig-src/lib |
| 139 | 138 | |
| 140 | | const prefix = try fs.path.join(allocator, [_][]const u8{ in_glibc_dir, "sysdeps", "unix", "sysv", "linux" }); |
| 141 | | const glibc_out_dir = try fs.path.join(allocator, [_][]const u8{ zig_src_dir, "libc", "glibc" }); |
| 139 | const prefix = try fs.path.join(allocator, &[_][]const u8{ in_glibc_dir, "sysdeps", "unix", "sysv", "linux" }); |
| 140 | const glibc_out_dir = try fs.path.join(allocator, &[_][]const u8{ zig_src_dir, "libc", "glibc" }); |
| 142 | 141 | |
| 143 | 142 | var global_fn_set = std.StringHashMap(Function).init(allocator); |
| 144 | 143 | var global_ver_set = std.StringHashMap(usize).init(allocator); |
| ... | ... | @@ -158,26 +157,26 @@ pub fn main() !void { |
| 158 | 157 | const basename = try fmt.allocPrint(allocator, "lib{}.abilist", .{lib_name}); |
| 159 | 158 | const abi_list_filename = blk: { |
| 160 | 159 | if (abi_list.targets[0].abi == .gnuabi64 and std.mem.eql(u8, lib_name, "c")) { |
| 161 | | break :blk try fs.path.join(allocator, [_][]const u8{ prefix, abi_list.path, "n64", basename }); |
| 160 | break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "n64", basename }); |
| 162 | 161 | } else if (abi_list.targets[0].abi == .gnuabin32 and std.mem.eql(u8, lib_name, "c")) { |
| 163 | | break :blk try fs.path.join(allocator, [_][]const u8{ prefix, abi_list.path, "n32", basename }); |
| 162 | break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "n32", basename }); |
| 164 | 163 | } else if (abi_list.targets[0].arch != .arm and |
| 165 | 164 | abi_list.targets[0].abi == .gnueabihf and |
| 166 | 165 | (std.mem.eql(u8, lib_name, "c") or |
| 167 | 166 | (std.mem.eql(u8, lib_name, "m") and abi_list.targets[0].arch == .powerpc))) |
| 168 | 167 | { |
| 169 | | break :blk try fs.path.join(allocator, [_][]const u8{ prefix, abi_list.path, "fpu", basename }); |
| 168 | break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "fpu", basename }); |
| 170 | 169 | } else if (abi_list.targets[0].arch != .arm and |
| 171 | 170 | abi_list.targets[0].abi == .gnueabi and |
| 172 | 171 | (std.mem.eql(u8, lib_name, "c") or |
| 173 | 172 | (std.mem.eql(u8, lib_name, "m") and abi_list.targets[0].arch == .powerpc))) |
| 174 | 173 | { |
| 175 | | break :blk try fs.path.join(allocator, [_][]const u8{ prefix, abi_list.path, "nofpu", basename }); |
| 174 | break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "nofpu", basename }); |
| 176 | 175 | } |
| 177 | | break :blk try fs.path.join(allocator, [_][]const u8{ prefix, abi_list.path, basename }); |
| 176 | break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, basename }); |
| 178 | 177 | }; |
| 179 | 178 | const contents = std.io.readFileAlloc(allocator, abi_list_filename) catch |err| { |
| 180 | | std.debug.warn("unable to open {}: {}\n", .{abi_list_filename, err}); |
| 179 | std.debug.warn("unable to open {}: {}\n", .{ abi_list_filename, err }); |
| 181 | 180 | std.process.exit(1); |
| 182 | 181 | }; |
| 183 | 182 | var lines_it = std.mem.tokenize(contents, "\n"); |
| ... | ... | @@ -228,8 +227,8 @@ pub fn main() !void { |
| 228 | 227 | break :blk list.toSliceConst(); |
| 229 | 228 | }; |
| 230 | 229 | { |
| 231 | | const vers_txt_path = try fs.path.join(allocator, [_][]const u8{ glibc_out_dir, "vers.txt" }); |
| 232 | | const vers_txt_file = try fs.File.openWrite(vers_txt_path); |
| 230 | const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); |
| 231 | const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{}); |
| 233 | 232 | defer vers_txt_file.close(); |
| 234 | 233 | var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&vers_txt_file.outStream().stream); |
| 235 | 234 | const vers_txt = &buffered.stream; |
| ... | ... | @@ -240,15 +239,15 @@ pub fn main() !void { |
| 240 | 239 | try buffered.flush(); |
| 241 | 240 | } |
| 242 | 241 | { |
| 243 | | const fns_txt_path = try fs.path.join(allocator, [_][]const u8{ glibc_out_dir, "fns.txt" }); |
| 244 | | const fns_txt_file = try fs.File.openWrite(fns_txt_path); |
| 242 | const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" }); |
| 243 | const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{}); |
| 245 | 244 | defer fns_txt_file.close(); |
| 246 | 245 | var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&fns_txt_file.outStream().stream); |
| 247 | 246 | const fns_txt = &buffered.stream; |
| 248 | 247 | for (global_fn_list) |name, i| { |
| 249 | 248 | const kv = global_fn_set.get(name).?; |
| 250 | 249 | kv.value.index = i; |
| 251 | | try fns_txt.print("{} {}\n", .{name, kv.value.lib}); |
| 250 | try fns_txt.print("{} {}\n", .{ name, kv.value.lib }); |
| 252 | 251 | } |
| 253 | 252 | try buffered.flush(); |
| 254 | 253 | } |
| ... | ... | @@ -271,8 +270,8 @@ pub fn main() !void { |
| 271 | 270 | } |
| 272 | 271 | |
| 273 | 272 | { |
| 274 | | const abilist_txt_path = try fs.path.join(allocator, [_][]const u8{ glibc_out_dir, "abi.txt" }); |
| 275 | | const abilist_txt_file = try fs.File.openWrite(abilist_txt_path); |
| 273 | const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" }); |
| 274 | const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{}); |
| 276 | 275 | defer abilist_txt_file.close(); |
| 277 | 276 | var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&abilist_txt_file.outStream().stream); |
| 278 | 277 | const abilist_txt = &buffered.stream; |
| ... | ... | @@ -282,7 +281,7 @@ pub fn main() !void { |
| 282 | 281 | const fn_vers_list = &target_functions.get(@ptrToInt(abi_list)).?.value.fn_vers_list; |
| 283 | 282 | for (abi_list.targets) |target, it_i| { |
| 284 | 283 | if (it_i != 0) try abilist_txt.writeByte(' '); |
| 285 | | try abilist_txt.print("{}-linux-{}", .{@tagName(target.arch), @tagName(target.abi)}); |
| 284 | try abilist_txt.print("{}-linux-{}", .{ @tagName(target.arch), @tagName(target.abi) }); |
| 286 | 285 | } |
| 287 | 286 | try abilist_txt.writeByte('\n'); |
| 288 | 287 | // next, each line implicitly corresponds to a function |
| ... | ... | @@ -304,7 +303,7 @@ pub fn main() !void { |
| 304 | 303 | } |
| 305 | 304 | |
| 306 | 305 | pub fn strCmpLessThan(a: []const u8, b: []const u8) bool { |
| 307 | | return std.mem.compare(u8, a, b) == .LessThan; |
| 306 | return std.mem.order(u8, a, b) == .lt; |
| 308 | 307 | } |
| 309 | 308 | |
| 310 | 309 | pub fn versionLessThan(a: []const u8, b: []const u8) bool { |