From 559fd922959905e12dabfdecf8b2a78db8ecda22 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Jun 2025 16:23:15 -0700 Subject: [PATCH] build: use `xcrun --sdk metal` for metal paths This wasn't working before but it just requires a restart of the machine for the changes to take effect. The namespace runners have this prebuilt so this should work now. The other workaround was flaky for unknown reasons so I'd prefer to go back to this. --- src/build/MetallibStep.zig | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/build/MetallibStep.zig b/src/build/MetallibStep.zig index bac3a72c5..b7405c496 100644 --- a/src/build/MetallibStep.zig +++ b/src/build/MetallibStep.zig @@ -22,10 +22,11 @@ step: *Step, output: LazyPath, pub fn create(b: *std.Build, opts: Options) ?*MetallibStep { - switch (opts.target.result.os.tag) { - .macos, .ios => {}, - else => return null, // Only macOS and iOS are supported. - } + const sdk = switch (opts.target.result.os.tag) { + .macos => "macosx", + .ios => "iphoneos", + else => return null, + }; const self = b.allocator.create(MetallibStep) catch @panic("OOM"); @@ -37,31 +38,11 @@ pub fn create(b: *std.Build, opts: Options) ?*MetallibStep { else => unreachable, }; - // Find the metal and metallib executables. The Apple docs - // at the time of writing (June 2025) say to use - // `xcrun --sdk metal` but this doesn't work with Xcode 26. - // - // I don't know if this is a bug but the xcodebuild approach also - // works with Xcode 15 so it seems safe to use this instead. - // - // Reported bug: FB17874042. - var code: u8 = undefined; - const metal_exe = std.mem.trim(u8, b.runAllowFail( - &.{ "xcodebuild", "-find-executable", "metal" }, - &code, - .Ignore, - ) catch return null, "\r\n "); - const metallib_exe = std.mem.trim(u8, b.runAllowFail( - &.{ "xcodebuild", "-find-executable", "metallib" }, - &code, - .Ignore, - ) catch return null, "\r\n "); - const run_ir = RunStep.create( b, b.fmt("metal {s}", .{opts.name}), ); - run_ir.addArgs(&.{ metal_exe, "-o" }); + run_ir.addArgs(&.{ "/usr/bin/xcrun", "-sdk", sdk, "metal", "-o" }); const output_ir = run_ir.addOutputFileArg(b.fmt("{s}.ir", .{opts.name})); run_ir.addArgs(&.{"-c"}); for (opts.sources) |source| run_ir.addFileArg(source); @@ -81,7 +62,7 @@ pub fn create(b: *std.Build, opts: Options) ?*MetallibStep { b, b.fmt("metallib {s}", .{opts.name}), ); - run_lib.addArgs(&.{ metallib_exe, "-o" }); + run_lib.addArgs(&.{ "/usr/bin/xcrun", "-sdk", sdk, "metallib", "-o" }); const output_lib = run_lib.addOutputFileArg(b.fmt("{s}.metallib", .{opts.name})); run_lib.addFileArg(output_ir); run_lib.step.dependOn(&run_ir.step);