Skip to content

Commit

Permalink
gpu-dawn: error if curl is not installed, less verbose errors
Browse files Browse the repository at this point in the history
Some Linux distro's (e.g. Ubuntu) ship with wget but not curl by default. It's possible
to run into this if you don't use it a lot, e.g. in WSL under Windows - so produce an error
if `curl` is not installed.

Additionally, if the binary download fails, don't throw an entire stack trace to stdout.

Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
emidoots committed Mar 27, 2022
1 parent 34d7737 commit 853a9cd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ pub fn ensureBinaryDownloaded(
// A download failed, or extraction failed, so wipe out the directory to ensure we correctly
// try again next time.
std.fs.deleteTreeAbsolute(base_cache_dir) catch {};
@panic(@errorName(err));
std.log.err("mach/gpu-dawn: prebuilt binary download failed: {s}", .{@errorName(err)});
std.process.exit(1);
};
}

Expand All @@ -312,6 +313,8 @@ fn downloadBinary(
is_windows: bool,
version: []const u8,
) !void {
try ensureCanDownloadFiles(allocator);

const download_dir = try std.fs.path.join(allocator, &.{ target_cache_dir, "download" });
try std.fs.cwd().makePath(download_dir);

Expand Down Expand Up @@ -445,6 +448,23 @@ fn downloadFile(allocator: std.mem.Allocator, target_file: []const u8, url: []co
_ = try child.spawnAndWait();
}

fn ensureCanDownloadFiles(allocator: std.mem.Allocator) !void {
const argv = &[_][]const u8{ "curl", "--version" };
const result = try std.ChildProcess.exec(.{
.allocator = allocator,
.argv = argv,
.cwd = thisDir(),
});
defer {
allocator.free(result.stderr);
allocator.free(result.stdout);
}
if (result.term.Exited != 0) {
std.log.err("mach: error: 'curl --version' failed. Is curl not installed?", .{});
std.process.exit(1);
}
}

fn isLinuxDesktopLike(target: std.Target) bool {
const tag = target.os.tag;
return !tag.isDarwin() and tag != .windows and tag != .fuchsia and tag != .emscripten and !target.isAndroid();
Expand Down

0 comments on commit 853a9cd

Please sign in to comment.