Fix crash on Windows (#286)

* Fix crash on Windows
This commit is contained in:
Tau 2021-04-03 11:14:52 +02:00 committed by GitHub
parent 4d052de925
commit 28f2431b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,7 +72,14 @@ pub fn wizard(allocator: *std.mem.Allocator) !void {
print("Found zig executable '{s}' in PATH.\n", .{path});
} else {
write("Could not find 'zig' in PATH\n");
zig_exe_path = try zinput.askString(allocator, "What is the path to the 'zig' executable you would like to use?", std.fs.MAX_PATH_BYTES);
zig_exe_path = try zinput.askString(allocator,
if (std.builtin.os.tag == .windows)
\\What is the path to the 'zig' executable you would like to use?
\\Note that due to a bug in zig (https://github.com/ziglang/zig/issues/6044),
\\your zig directory cannot contain the '/' character.
else
"What is the path to the 'zig' executable you would like to use?",
std.fs.MAX_PATH_BYTES);
}
const editor = try zinput.askSelectOne("Which code editor do you use?", enum { VSCode, Sublime, Kate, Neovim, Vim8, Emacs, Doom, Other });
@ -223,6 +230,9 @@ pub fn findZig(allocator: *std.mem.Allocator) !?[]const u8 {
var it = std.mem.tokenize(env_path, &[_]u8{std.fs.path.delimiter});
while (it.next()) |path| {
if (std.builtin.os.tag == .windows) {
if (std.mem.indexOfScalar(u8, path, '/')) |s| continue;
}
const full_path = try std.fs.path.join(allocator, &[_][]const u8{
path,
zig_exe,
@ -231,7 +241,6 @@ pub fn findZig(allocator: *std.mem.Allocator) !?[]const u8 {
if (!std.fs.path.isAbsolute(full_path)) continue;
// Skip folders named zig
const file = std.fs.openFileAbsolute(full_path, .{}) catch continue;
defer file.close();
const stat = file.stat() catch continue;