authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-04 01:05:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-04 01:05:42-05:00
log447a89cd4db37b3d184bc05a46bf330066e677ab
treef8637e63113ae977ccd0336c22786dbe954c0962
parentb21d44f26a9f2ee9b4d4248692aa5cc5fc78ade3
signaturelock-open Commit is signed but in an unrecognized format.

update self-hosted `zig targets` to print correct glibc availability


3 files changed, 64 insertions(+), 53 deletions(-)

lib/std/fs.zig+8-5
......@@ -663,11 +663,14 @@ pub const Dir = struct {
663663 return self.openFileW(&path_w, flags);
664664 }
665665 const path_c = try os.toPosixPath(sub_path);
666 return self.openFileC(&path_c, flags);
666 return self.openFileZ(&path_c, flags);
667667 }
668668
669 /// Deprecated; use `openFileZ`.
670 pub const openFileC = openFileZ;
671
669672 /// 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 {
671674 if (builtin.os.tag == .windows) {
672675 const path_w = try os.windows.cStrToPrefixedFileW(sub_path);
673676 return self.openFileW(&path_w, flags);
......@@ -753,9 +756,9 @@ pub const Dir = struct {
753756 return self.openFile(sub_path, .{});
754757 }
755758
756 /// Deprecated; call `openFileC` directly.
759 /// Deprecated; call `openFileZ` directly.
757760 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, .{});
759762 }
760763
761764 /// Deprecated; call `openFileW` directly.
......@@ -1403,7 +1406,7 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O
14031406/// Same as `openFileAbsolute` but the path parameter is null-terminated.
14041407pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
14051408 assert(path.isAbsoluteC(absolute_path_c));
1406 return cwd().openFileC(absolute_path_c, flags);
1409 return cwd().openFileZ(absolute_path_c, flags);
14071410}
14081411
14091412/// 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;
88
99/// Caller must free result
1010pub 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" });
1231 errdefer allocator.free(test_zig_dir);
1332
1433 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });
1534 defer allocator.free(test_index_file);
1635
17 var file = try fs.cwd().openRead(test_index_file);
36 const file = try fs.cwd().openFile(test_index_file, .{});
1837 file.close();
1938
2039 return test_zig_dir;
src-self-hosted/print_targets.zig+35-46
......@@ -4,6 +4,9 @@ const io = std.io;
44const mem = std.mem;
55const Allocator = mem.Allocator;
66const Target = std.Target;
7const assert = std.debug.assert;
8
9const introspect = @import("introspect.zig");
710
811// TODO this is hard-coded until self-hosted gains this information canonically
912const available_libcs = [_][]const u8{
......@@ -55,57 +58,40 @@ const available_libcs = [_][]const u8{
5558 "x86_64-windows-gnu",
5659};
5760
58// TODO this is hard-coded until self-hosted gains this information canonically
59const 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
10361pub fn cmdTargets(
10462 allocator: *Allocator,
10563 args: []const []const u8,
10664 stdout: *io.OutStream(fs.File.WriteError),
10765 native_target: Target,
10866) !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
10995 const BOS = io.BufferedOutStream(fs.File.WriteError);
11096 var bos = BOS.init(stdout);
11197 var jws = std.json.WriteStream(BOS.Stream, 6).init(&bos.stream);
......@@ -150,7 +136,10 @@ pub fn cmdTargets(
150136 try jws.beginArray();
151137 for (available_glibcs) |glibc| {
152138 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);
154143 }
155144 try jws.endArray();
156145