gpu-dawn: error if curl is not installed, less verbose errors

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 <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-27 12:52:19 -07:00
parent 074721ece7
commit a2f65d5a23

View file

@ -299,7 +299,8 @@ pub fn ensureBinaryDownloaded(
// A download failed, or extraction failed, so wipe out the directory to ensure we correctly // A download failed, or extraction failed, so wipe out the directory to ensure we correctly
// try again next time. // try again next time.
std.fs.deleteTreeAbsolute(base_cache_dir) catch {}; 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);
}; };
} }
@ -312,6 +313,8 @@ fn downloadBinary(
is_windows: bool, is_windows: bool,
version: []const u8, version: []const u8,
) !void { ) !void {
try ensureCanDownloadFiles(allocator);
const download_dir = try std.fs.path.join(allocator, &.{ target_cache_dir, "download" }); const download_dir = try std.fs.path.join(allocator, &.{ target_cache_dir, "download" });
try std.fs.cwd().makePath(download_dir); try std.fs.cwd().makePath(download_dir);
@ -445,6 +448,23 @@ fn downloadFile(allocator: std.mem.Allocator, target_file: []const u8, url: []co
_ = try child.spawnAndWait(); _ = 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 { fn isLinuxDesktopLike(target: std.Target) bool {
const tag = target.os.tag; const tag = target.os.tag;
return !tag.isDarwin() and tag != .windows and tag != .fuchsia and tag != .emscripten and !target.isAndroid(); return !tag.isDarwin() and tag != .windows and tag != .fuchsia and tag != .emscripten and !target.isAndroid();