| author | |
| committer | |
| log | 447a89cd4db37b3d184bc05a46bf330066e677ab |
| tree | f8637e63113ae977ccd0336c22786dbe954c0962 |
| parent | b21d44f26a9f2ee9b4d4248692aa5cc5fc78ade3 |
| signature |
3 files changed, 64 insertions(+), 53 deletions(-)
lib/std/fs.zig+8-5| ... | ... | @@ -663,11 +663,14 @@ pub const Dir = struct { |
| 663 | 663 | return self.openFileW(&path_w, flags); |
| 664 | 664 | } |
| 665 | 665 | const path_c = try os.toPosixPath(sub_path); |
| 666 | return self.openFileC(&path_c, flags); | |
| 666 | return self.openFileZ(&path_c, flags); | |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | /// Deprecated; use `openFileZ`. | |
| 670 | pub const openFileC = openFileZ; | |
| 671 | ||
| 669 | 672 | /// Same as `openFile` but the path parameter is null-terminated. |
| 670 | pub fn openFileC(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { | |
| 673 | pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { | |
| 671 | 674 | if (builtin.os.tag == .windows) { |
| 672 | 675 | const path_w = try os.windows.cStrToPrefixedFileW(sub_path); |
| 673 | 676 | return self.openFileW(&path_w, flags); |
| ... | ... | @@ -753,9 +756,9 @@ pub const Dir = struct { |
| 753 | 756 | return self.openFile(sub_path, .{}); |
| 754 | 757 | } |
| 755 | 758 | |
| 756 | /// Deprecated; call `openFileC` directly. | |
| 759 | /// Deprecated; call `openFileZ` directly. | |
| 757 | 760 | pub fn openReadC(self: Dir, sub_path: [*:0]const u8) File.OpenError!File { |
| 758 | return self.openFileC(sub_path, .{}); | |
| 761 | return self.openFileZ(sub_path, .{}); | |
| 759 | 762 | } |
| 760 | 763 | |
| 761 | 764 | /// Deprecated; call `openFileW` directly. |
| ... | ... | @@ -1403,7 +1406,7 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O |
| 1403 | 1406 | /// Same as `openFileAbsolute` but the path parameter is null-terminated. |
| 1404 | 1407 | pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { |
| 1405 | 1408 | assert(path.isAbsoluteC(absolute_path_c)); |
| 1406 | return cwd().openFileC(absolute_path_c, flags); | |
| 1409 | return cwd().openFileZ(absolute_path_c, flags); | |
| 1407 | 1410 | } |
| 1408 | 1411 | |
| 1409 | 1412 | /// Same as `openFileAbsolute` but the path parameter is WTF-16 encoded. |
src-self-hosted/introspect.zig+21-2| ... | ... | @@ -8,13 +8,32 @@ const warn = std.debug.warn; |
| 8 | 8 | |
| 9 | 9 | /// Caller must free result |
| 10 | 10 | pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 { |
| 11 | const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib", "zig" }); | |
| 11 | { | |
| 12 | const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib", "zig" }); | |
| 13 | errdefer allocator.free(test_zig_dir); | |
| 14 | ||
| 15 | const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" }); | |
| 16 | defer allocator.free(test_index_file); | |
| 17 | ||
| 18 | if (fs.cwd().openFile(test_index_file, .{})) |file| { | |
| 19 | file.close(); | |
| 20 | return test_zig_dir; | |
| 21 | } else |err| switch (err) { | |
| 22 | error.FileNotFound => { | |
| 23 | allocator.free(test_zig_dir); | |
| 24 | }, | |
| 25 | else => |e| return e, | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | // Also try without "zig" | |
| 30 | const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib" }); | |
| 12 | 31 | errdefer allocator.free(test_zig_dir); |
| 13 | 32 | |
| 14 | 33 | const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" }); |
| 15 | 34 | defer allocator.free(test_index_file); |
| 16 | 35 | |
| 17 | var file = try fs.cwd().openRead(test_index_file); | |
| 36 | const file = try fs.cwd().openFile(test_index_file, .{}); | |
| 18 | 37 | file.close(); |
| 19 | 38 | |
| 20 | 39 | return test_zig_dir; |
src-self-hosted/print_targets.zig+35-46| ... | ... | @@ -4,6 +4,9 @@ const io = std.io; |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const Allocator = mem.Allocator; |
| 6 | 6 | const Target = std.Target; |
| 7 | const assert = std.debug.assert; | |
| 8 | ||
| 9 | const introspect = @import("introspect.zig"); | |
| 7 | 10 | |
| 8 | 11 | // TODO this is hard-coded until self-hosted gains this information canonically |
| 9 | 12 | const available_libcs = [_][]const u8{ |
| ... | ... | @@ -55,57 +58,40 @@ const available_libcs = [_][]const u8{ |
| 55 | 58 | "x86_64-windows-gnu", |
| 56 | 59 | }; |
| 57 | 60 | |
| 58 | // TODO this is hard-coded until self-hosted gains this information canonically | |
| 59 | const available_glibcs = [_][]const u8{ | |
| 60 | "2.0", | |
| 61 | "2.1", | |
| 62 | "2.1.1", | |
| 63 | "2.1.2", | |
| 64 | "2.1.3", | |
| 65 | "2.2", | |
| 66 | "2.2.1", | |
| 67 | "2.2.2", | |
| 68 | "2.2.3", | |
| 69 | "2.2.4", | |
| 70 | "2.2.5", | |
| 71 | "2.2.6", | |
| 72 | "2.3", | |
| 73 | "2.3.2", | |
| 74 | "2.3.3", | |
| 75 | "2.3.4", | |
| 76 | "2.4", | |
| 77 | "2.5", | |
| 78 | "2.6", | |
| 79 | "2.7", | |
| 80 | "2.8", | |
| 81 | "2.9", | |
| 82 | "2.10", | |
| 83 | "2.11", | |
| 84 | "2.12", | |
| 85 | "2.13", | |
| 86 | "2.14", | |
| 87 | "2.15", | |
| 88 | "2.16", | |
| 89 | "2.17", | |
| 90 | "2.18", | |
| 91 | "2.19", | |
| 92 | "2.22", | |
| 93 | "2.23", | |
| 94 | "2.24", | |
| 95 | "2.25", | |
| 96 | "2.26", | |
| 97 | "2.27", | |
| 98 | "2.28", | |
| 99 | "2.29", | |
| 100 | "2.30", | |
| 101 | }; | |
| 102 | ||
| 103 | 61 | pub fn cmdTargets( |
| 104 | 62 | allocator: *Allocator, |
| 105 | 63 | args: []const []const u8, |
| 106 | 64 | stdout: *io.OutStream(fs.File.WriteError), |
| 107 | 65 | native_target: Target, |
| 108 | 66 | ) !void { |
| 67 | const available_glibcs = blk: { | |
| 68 | const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch |err| { | |
| 69 | std.debug.warn("unable to find zig installation directory: {}\n", .{@errorName(err)}); | |
| 70 | std.process.exit(1); | |
| 71 | }; | |
| 72 | defer allocator.free(zig_lib_dir); | |
| 73 | ||
| 74 | var dir = try std.fs.cwd().openDirList(zig_lib_dir); | |
| 75 | defer dir.close(); | |
| 76 | ||
| 77 | const vers_txt = try dir.readFileAlloc(allocator, "libc/glibc/vers.txt", 10 * 1024); | |
| 78 | defer allocator.free(vers_txt); | |
| 79 | ||
| 80 | var list = std.ArrayList(std.builtin.Version).init(allocator); | |
| 81 | defer list.deinit(); | |
| 82 | ||
| 83 | var it = mem.tokenize(vers_txt, "\r\n"); | |
| 84 | while (it.next()) |line| { | |
| 85 | const prefix = "GLIBC_"; | |
| 86 | assert(mem.startsWith(u8, line, prefix)); | |
| 87 | const adjusted_line = line[prefix.len..]; | |
| 88 | const ver = try std.builtin.Version.parse(adjusted_line); | |
| 89 | try list.append(ver); | |
| 90 | } | |
| 91 | break :blk list.toOwnedSlice(); | |
| 92 | }; | |
| 93 | defer allocator.free(available_glibcs); | |
| 94 | ||
| 109 | 95 | const BOS = io.BufferedOutStream(fs.File.WriteError); |
| 110 | 96 | var bos = BOS.init(stdout); |
| 111 | 97 | var jws = std.json.WriteStream(BOS.Stream, 6).init(&bos.stream); |
| ... | ... | @@ -150,7 +136,10 @@ pub fn cmdTargets( |
| 150 | 136 | try jws.beginArray(); |
| 151 | 137 | for (available_glibcs) |glibc| { |
| 152 | 138 | try jws.arrayElem(); |
| 153 | try jws.emitString(glibc); | |
| 139 | ||
| 140 | const tmp = try std.fmt.allocPrint(allocator, "{}", .{glibc}); | |
| 141 | defer allocator.free(tmp); | |
| 142 | try jws.emitString(tmp); | |
| 154 | 143 | } |
| 155 | 144 | try jws.endArray(); |
| 156 | 145 |