Hash :
2f564f1c
Author :
Date :
2025-09-16T16:46:36
mac: handle Metal toolchain being unbundled from Xcode 26 The Metal toolchain was formerly part of Xcode, but in Xcode 26, it has been unbundled and is now a separate install. Attempting to use the Metal toolchain without installing it results in a build error, such as: error: error: cannot execute tool 'metal' due to missing Metal Toolchain; use: xcodebuild -downloadComponent MetalToolchain By running the suggested command, the Metal toolchain can be installed, but the existing angle build does not know how to find it correctly. For system Xcode installations, tools from the Metal toolchain (`metal` and `metallib`) can be run via `xcrun`. This construct should work equally well for older Xcode versions, for situations where it’s still in use. For the hermetic toolchain, we’ll continue splicing the Metal toolchain into the location it had previously been avialable (see https://chromium-review.googlesource.com/c/6950738), although this is subject to change in the future. Bug: chromium:423933062, chromium:445400016 Change-Id: I139eca51938f7cecfec9b90fd488947160ef4ec9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6955000 Auto-Submit: Mark Mentovai <mark@chromium.org> Commit-Queue: Mark Mentovai <mark@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This file houses the build configuration for the ANGLE Metal back-end.
import("../../../../gni/angle.gni")
import("metal_backend.gni")
if (metal_internal_shader_compilation_supported) {
import("//build/config/mac/mac_sdk.gni")
}
assert(is_mac || is_ios)
assert(angle_enable_metal)
config("angle_metal_backend_config") {
defines = [ "ANGLE_ENABLE_METAL" ]
ldflags = [
"-weak_framework",
"Metal",
]
include_dirs = [ "$root_gen_dir/angle" ]
}
if (metal_internal_shader_compilation_supported) {
template("run_metal_tool") {
action(target_name) {
forward_variables_from(invoker,
[
"deps",
"sources",
"outputs",
"metal_tool",
])
script = "shaders/metal_wrapper.py"
if (use_system_xcode) {
# System Xcode: run metal and metallib via xcrun. Since Xcode 26.0, the
# Metal toolchain has been unbundled from Xcode, and must be installed
# separately by running `xcodebuild -downloadComponent MetalToolchain`.
# There is a vestigial metal executable in mac_bin_path, but it’s
# incapable of running successfuly without the
# rest of the Metal toolchain surrounding it. `xcrun` is able to find
# and run the correct Metal toolchain when properly installed.
#
# If you’re using system Xcode and your build fails with this message:
# error: error: cannot execute tool 'metal' due to missing Metal Toolchain; use: xcodebuild -downloadComponent MetalToolchain
# then do what the error message suggests, and then retry your build.
args = [
"xcrun",
metal_tool,
]
} else {
# Hermetic Xcode: at least for now, the Metal toolchain is
# “spliced” into the location in the hermetic toolchain where it lived
# before Xcode 26.0, so it can be run directly from there.
args = [ mac_bin_path + metal_tool ]
}
args += invoker.args
}
}
_metal_internal_shaders_air_file =
"$root_gen_dir/angle/mtl_internal_shaders_autogen.air"
run_metal_tool("angle_metal_internal_shaders_to_air") {
_metal_internal_shaders_metal_source =
"shaders/mtl_internal_shaders_autogen.metal"
sources = [ _metal_internal_shaders_metal_source ]
outputs = [ _metal_internal_shaders_air_file ]
metal_tool = "metal"
args = [
"-c",
rebase_path(_metal_internal_shaders_metal_source, root_build_dir),
"-o",
rebase_path(_metal_internal_shaders_air_file, root_build_dir),
]
if (is_mac) {
args += [
"--std=macos-metal2.1",
"-mmacosx-version-min=10.14",
]
} else if (is_ios) {
args += [
"--std=ios-metal2.1",
"-mios-version-min=12",
]
}
}
_metal_internal_shaders_metallib_file =
"$root_gen_dir/angle/mtl_internal_shaders_autogen.metallib"
run_metal_tool("angle_metal_internal_shaders_to_mtllib") {
deps = [ ":angle_metal_internal_shaders_to_air" ]
sources = [ _metal_internal_shaders_air_file ]
outputs = [ _metal_internal_shaders_metallib_file ]
metal_tool = "metallib"
args = [
rebase_path(_metal_internal_shaders_air_file, root_build_dir),
"-o",
rebase_path(_metal_internal_shaders_metallib_file, root_build_dir),
]
}
config("angle_metal_internal_shaders_config") {
include_dirs = [ "$root_gen_dir/angle" ]
}
action("angle_metal_internal_shaders") {
script = "shaders/embed_in_header.py"
outputs = [ metal_internal_shaders_header ]
sources = [ _metal_internal_shaders_metallib_file ]
deps = [ ":angle_metal_internal_shaders_to_mtllib" ]
args = [
"--source",
rebase_path(_metal_internal_shaders_metallib_file, root_build_dir),
"--variable-name",
"gDefaultMetallib",
"--header",
rebase_path(metal_internal_shaders_header, root_build_dir),
]
public_configs = [ ":angle_metal_internal_shaders_config" ]
}
}
angle_source_set("angle_metal_backend") {
public_configs = [ ":angle_metal_backend_config" ]
sources = metal_backend_sources
cflags = []
cflags_cc = []
cflags_objc = []
cflags_objcc = []
ldflags = []
libs = []
defines = []
public_deps = [
"${angle_root}:angle_common",
"${angle_root}:angle_gpu_info_util",
"${angle_root}:angle_image_util",
"${angle_root}:libANGLE_headers",
"${angle_root}:translator",
]
if (metal_internal_shader_compilation_supported) {
public_deps += [ ":angle_metal_internal_shaders" ]
defines += [ "ANGLE_METAL_HAS_PREBUILT_INTERNAL_SHADERS" ]
}
objc_flags = [
"-Wno-nullability-completeness",
"-Wno-unguarded-availability",
"-fno-objc-arc",
]
cflags_objc += objc_flags
cflags_objcc += objc_flags
if (is_apple) {
frameworks = [
"IOSurface.framework",
"QuartzCore.framework",
]
if (is_mac) {
frameworks += [ "Cocoa.framework" ]
}
}
}