From a2f65d5a231eebf1be120ba7d904675f08e1464f Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 27 Mar 2022 12:52:19 -0700 Subject: [PATCH] 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 --- gpu-dawn/build.zig | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gpu-dawn/build.zig b/gpu-dawn/build.zig index 0a67f43f..5db2e794 100644 --- a/gpu-dawn/build.zig +++ b/gpu-dawn/build.zig @@ -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); }; } @@ -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); @@ -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();