From e40513e97ff57960165b30a6b9fecfaad95bd1aa Mon Sep 17 00:00:00 2001 From: Benjamin Feng Date: Wed, 31 Jul 2019 21:26:39 -0500 Subject: [PATCH 1/3] Add builder.findProgram test and fix references --- std/build.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/std/build.zig b/std/build.zig index 3a0c34c8d1..acd3a1e33b 100644 --- a/std/build.zig +++ b/std/build.zig @@ -805,7 +805,7 @@ pub const Builder = struct { return name; } const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) }); - if (fs.path.real(self.allocator, full_path)) |real_path| { + if (fs.realpathAlloc(self.allocator, full_path)) |real_path| { return real_path; } else |_| { continue; @@ -817,10 +817,10 @@ pub const Builder = struct { if (fs.path.isAbsolute(name)) { return name; } - var it = mem.tokenize(PATH, []u8{fs.path.delimiter}); + var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter}); while (it.next()) |path| { const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); - if (fs.path.real(self.allocator, full_path)) |real_path| { + if (fs.realpathAlloc(self.allocator, full_path)) |real_path| { return real_path; } else |_| { continue; @@ -834,7 +834,7 @@ pub const Builder = struct { } for (paths) |path| { const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); - if (fs.path.real(self.allocator, full_path)) |real_path| { + if (fs.realpathAlloc(self.allocator, full_path)) |real_path| { return real_path; } else |_| { continue; @@ -904,6 +904,15 @@ pub const Builder = struct { } }; +test "builder.findProgram compiles" { + //allocator: *Allocator, + //zig_exe: []const u8, + //build_root: []const u8, + //cache_root: []const u8, + const builder = try Builder.create(std.heap.direct_allocator, "zig", "zig-cache", "zig-cache"); + _ = builder.findProgram([_][]const u8{}, [_][]const u8{}) catch null; +} + pub const Version = struct { major: u32, minor: u32, From 327abdba0b5de1f1eeef32e19b6a16ec4c7ec323 Mon Sep 17 00:00:00 2001 From: Benjamin Feng Date: Wed, 31 Jul 2019 21:28:25 -0500 Subject: [PATCH 2/3] More current style for error handling --- std/build.zig | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/std/build.zig b/std/build.zig index acd3a1e33b..997e2ab901 100644 --- a/std/build.zig +++ b/std/build.zig @@ -805,11 +805,7 @@ pub const Builder = struct { return name; } const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) }); - if (fs.realpathAlloc(self.allocator, full_path)) |real_path| { - return real_path; - } else |_| { - continue; - } + return fs.realpathAlloc(self.allocator, full_path) catch continue; } } if (self.env_map.get("PATH")) |PATH| { @@ -820,11 +816,7 @@ pub const Builder = struct { var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter}); while (it.next()) |path| { const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); - if (fs.realpathAlloc(self.allocator, full_path)) |real_path| { - return real_path; - } else |_| { - continue; - } + return fs.realpathAlloc(self.allocator, full_path) catch continue; } } } @@ -834,11 +826,7 @@ pub const Builder = struct { } for (paths) |path| { const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); - if (fs.realpathAlloc(self.allocator, full_path)) |real_path| { - return real_path; - } else |_| { - continue; - } + return fs.realpathAlloc(self.allocator, full_path) catch continue; } } return error.FileNotFound; From 723aea8369375d17d19bc1e6d02dbf6eb4d9ba49 Mon Sep 17 00:00:00 2001 From: Benjamin Feng Date: Wed, 31 Jul 2019 22:07:17 -0500 Subject: [PATCH 3/3] Default wasm-lib prefix to empty --- std/build.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/std/build.zig b/std/build.zig index 997e2ab901..d63e1ae899 100644 --- a/std/build.zig +++ b/std/build.zig @@ -1119,6 +1119,9 @@ pub const Target = union(enum) { } pub fn libPrefix(self: Target) []const u8 { + if (self.isWasm()) { + return ""; + } switch (self.getAbi()) { .msvc => return "", else => return "lib",