Commit 4a2b23c2be

Alex Rønne Petersen <alex@alexrp.com>
2024-08-13 23:38:02
build: Use the new b.addFail() for the update-mingw step.
This is precisely the kind of use case it was added for.
1 parent 019c0fc
Changed files (1)
build.zig
@@ -537,21 +537,20 @@ pub fn build(b: *std.Build) !void {
 
     const update_mingw_step = b.step("update-mingw", "Update zig's bundled mingw");
     const opt_mingw_src_path = b.option([]const u8, "mingw-src", "path to mingw-w64 source directory");
-    const update_mingw_exe = b.addExecutable(.{
-        .name = "update_mingw",
-        .target = b.graph.host,
-        .root_source_file = b.path("tools/update_mingw.zig"),
-    });
-    const update_mingw_run = b.addRunArtifact(update_mingw_exe);
-    update_mingw_run.addDirectoryArg(b.path("lib"));
     if (opt_mingw_src_path) |mingw_src_path| {
+        const update_mingw_exe = b.addExecutable(.{
+            .name = "update_mingw",
+            .target = b.graph.host,
+            .root_source_file = b.path("tools/update_mingw.zig"),
+        });
+        const update_mingw_run = b.addRunArtifact(update_mingw_exe);
+        update_mingw_run.addDirectoryArg(b.path("lib"));
         update_mingw_run.addDirectoryArg(.{ .cwd_relative = mingw_src_path });
+
+        update_mingw_step.dependOn(&update_mingw_run.step);
     } else {
-        // Intentionally cause an error if this build step is requested.
-        update_mingw_run.addArg("--missing-mingw-source-directory");
+        update_mingw_step.dependOn(&b.addFail("The -Dmingw-src=... option is required for this step").step);
     }
-
-    update_mingw_step.dependOn(&update_mingw_run.step);
 }
 
 fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {