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