|
| 1 | +From 2f564f1ca07b1d2668d8639d98ea5ad51cc9cd35 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mark Mentovai < [email protected]> |
| 3 | +Date: Tue, 16 Sep 2025 16:46:36 -0400 |
| 4 | +Subject: [PATCH] mac: handle Metal toolchain being unbundled from Xcode 26 |
| 5 | + |
| 6 | +The Metal toolchain was formerly part of Xcode, but in Xcode 26, it has |
| 7 | +been unbundled and is now a separate install. Attempting to use the |
| 8 | +Metal toolchain without installing it results in a build error, such as: |
| 9 | + |
| 10 | +error: error: cannot execute tool 'metal' due to missing Metal |
| 11 | +Toolchain; use: xcodebuild -downloadComponent MetalToolchain |
| 12 | + |
| 13 | +By running the suggested command, the Metal toolchain can be installed, |
| 14 | +but the existing angle build does not know how to find it correctly. |
| 15 | + |
| 16 | +For system Xcode installations, tools from the Metal toolchain (`metal` |
| 17 | +and `metallib`) can be run via `xcrun`. This construct should work |
| 18 | +equally well for older Xcode versions, for situations where it’s still |
| 19 | +in use. |
| 20 | + |
| 21 | +For the hermetic toolchain, we’ll continue splicing the Metal toolchain |
| 22 | +into the location it had previously been avialable (see |
| 23 | +https://chromium-review.googlesource.com/c/6950738), although this is |
| 24 | +subject to change in the future. |
| 25 | + |
| 26 | +Bug: chromium:423933062, chromium:445400016 |
| 27 | +Change-Id: I139eca51938f7cecfec9b90fd488947160ef4ec9 |
| 28 | +Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6955000 |
| 29 | +Auto-Submit: Mark Mentovai < [email protected]> |
| 30 | +Commit-Queue: Mark Mentovai < [email protected]> |
| 31 | +Reviewed-by: Geoff Lang < [email protected]> |
| 32 | +--- |
| 33 | + |
| 34 | +diff --git a/src/libANGLE/renderer/metal/BUILD.gn b/src/libANGLE/renderer/metal/BUILD.gn |
| 35 | +index 96e9ee8..50ac42a 100644 |
| 36 | +--- a/src/libANGLE/renderer/metal/BUILD.gn |
| 37 | ++++ b/src/libANGLE/renderer/metal/BUILD.gn |
| 38 | +@@ -24,20 +24,56 @@ |
| 39 | + } |
| 40 | + |
| 41 | + if (metal_internal_shader_compilation_supported) { |
| 42 | ++ template("run_metal_tool") { |
| 43 | ++ action(target_name) { |
| 44 | ++ forward_variables_from(invoker, |
| 45 | ++ [ |
| 46 | ++ "deps", |
| 47 | ++ "sources", |
| 48 | ++ "outputs", |
| 49 | ++ "metal_tool", |
| 50 | ++ ]) |
| 51 | ++ script = "shaders/metal_wrapper.py" |
| 52 | ++ if (use_system_xcode) { |
| 53 | ++ # System Xcode: run metal and metallib via xcrun. Since Xcode 26.0, the |
| 54 | ++ # Metal toolchain has been unbundled from Xcode, and must be installed |
| 55 | ++ # separately by running `xcodebuild -downloadComponent MetalToolchain`. |
| 56 | ++ # There is a vestigial metal executable in mac_bin_path, but it’s |
| 57 | ++ # incapable of running successfuly without the |
| 58 | ++ # rest of the Metal toolchain surrounding it. `xcrun` is able to find |
| 59 | ++ # and run the correct Metal toolchain when properly installed. |
| 60 | ++ # |
| 61 | ++ # If you’re using system Xcode and your build fails with this message: |
| 62 | ++ # error: error: cannot execute tool 'metal' due to missing Metal Toolchain; use: xcodebuild -downloadComponent MetalToolchain |
| 63 | ++ # then do what the error message suggests, and then retry your build. |
| 64 | ++ args = [ |
| 65 | ++ "xcrun", |
| 66 | ++ metal_tool, |
| 67 | ++ ] |
| 68 | ++ } else { |
| 69 | ++ # Hermetic Xcode: at least for now, the Metal toolchain is |
| 70 | ++ # “spliced” into the location in the hermetic toolchain where it lived |
| 71 | ++ # before Xcode 26.0, so it can be run directly from there. |
| 72 | ++ args = [ mac_bin_path + metal_tool ] |
| 73 | ++ } |
| 74 | ++ |
| 75 | ++ args += invoker.args |
| 76 | ++ } |
| 77 | ++ } |
| 78 | ++ |
| 79 | + _metal_internal_shaders_air_file = |
| 80 | + "$root_gen_dir/angle/mtl_internal_shaders_autogen.air" |
| 81 | + |
| 82 | +- action("angle_metal_internal_shaders_to_air") { |
| 83 | +- script = "shaders/metal_wrapper.py" |
| 84 | +- |
| 85 | +- outputs = [ _metal_internal_shaders_air_file ] |
| 86 | +- |
| 87 | ++ run_metal_tool("angle_metal_internal_shaders_to_air") { |
| 88 | + _metal_internal_shaders_metal_source = |
| 89 | + "shaders/mtl_internal_shaders_autogen.metal" |
| 90 | + sources = [ _metal_internal_shaders_metal_source ] |
| 91 | + |
| 92 | ++ outputs = [ _metal_internal_shaders_air_file ] |
| 93 | ++ |
| 94 | ++ metal_tool = "metal" |
| 95 | ++ |
| 96 | + args = [ |
| 97 | +- mac_bin_path + "metal", |
| 98 | + "-c", |
| 99 | + rebase_path(_metal_internal_shaders_metal_source, root_build_dir), |
| 100 | + "-o", |
| 101 | +@@ -60,17 +96,16 @@ |
| 102 | + _metal_internal_shaders_metallib_file = |
| 103 | + "$root_gen_dir/angle/mtl_internal_shaders_autogen.metallib" |
| 104 | + |
| 105 | +- action("angle_metal_internal_shaders_to_mtllib") { |
| 106 | +- script = "shaders/metal_wrapper.py" |
| 107 | +- |
| 108 | +- outputs = [ _metal_internal_shaders_metallib_file ] |
| 109 | ++ run_metal_tool("angle_metal_internal_shaders_to_mtllib") { |
| 110 | ++ deps = [ ":angle_metal_internal_shaders_to_air" ] |
| 111 | + |
| 112 | + sources = [ _metal_internal_shaders_air_file ] |
| 113 | + |
| 114 | +- deps = [ ":angle_metal_internal_shaders_to_air" ] |
| 115 | ++ outputs = [ _metal_internal_shaders_metallib_file ] |
| 116 | ++ |
| 117 | ++ metal_tool = "metallib" |
| 118 | + |
| 119 | + args = [ |
| 120 | +- mac_bin_path + "metallib", |
| 121 | + rebase_path(_metal_internal_shaders_air_file, root_build_dir), |
| 122 | + "-o", |
| 123 | + rebase_path(_metal_internal_shaders_metallib_file, root_build_dir), |
0 commit comments