Skip to content

Commit 9da76c7

Browse files
[macOS] Add MetalToolchain component for Xcode 26+ (#13088)
--------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 75ec422 commit 9da76c7

File tree

2 files changed

+10
-49
lines changed

2 files changed

+10
-49
lines changed

images/macos/scripts/build/Install-Xcode.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1" -Disable
1010

1111
$arch = Get-Architecture
1212
[Array]$xcodeVersions = (Get-ToolsetContent).xcode.$arch.versions
13-
write-host $xcodeVersions
13+
Write-Host $xcodeVersions
1414
$defaultXcode = (Get-ToolsetContent).xcode.default
1515
[Array]::Reverse($xcodeVersions)
1616
$threadCount = "5"
@@ -33,7 +33,10 @@ Write-Host "Configuring Xcode versions..."
3333
$xcodeVersions | ForEach-Object {
3434
Write-Host "Configuring Xcode $($_.link) ..."
3535
Invoke-XcodeRunFirstLaunch -Version $_.link
36-
Install-AdditionalSimulatorRuntimes -Version $_.link -Arch $arch -Runtimes $_.install_runtimes
36+
Install-XcodeAdditionalSimulatorRuntimes -Version $_.link -Arch $arch -Runtimes $_.install_runtimes
37+
if ($_.link -match '\d{2}(?=[._])' -and [int]$matches[0] -ge 26) {
38+
Install-XcodeAdditionalComponents -Version $_.link
39+
}
3740
}
3841

3942
Invoke-XcodeRunFirstLaunch -Version $defaultXcode

images/macos/scripts/helpers/Xcode.Installer.psm1

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,46 +42,6 @@ function Invoke-DownloadXcodeArchive {
4242
return $tempXipDirectory
4343
}
4444

45-
function Resolve-ExactXcodeVersion {
46-
param (
47-
[Parameter(Mandatory)]
48-
[string] $Version
49-
)
50-
51-
# if toolset string contains spaces, consider it as a full name of Xcode
52-
if ($Version -match "\s") {
53-
return $Version
54-
}
55-
56-
$semverVersion = [SemVer]::Parse($Version)
57-
$availableVersions = Get-AvailableXcodeVersions
58-
$satisfiedVersions = $availableVersions | Where-Object { $semverVersion -eq $_.stableSemver }
59-
60-
return $satisfiedVersions | Select-Object -Last 1 -ExpandProperty rawVersion
61-
}
62-
63-
function Get-AvailableXcodeVersions {
64-
$rawVersionsList = Invoke-XCVersion -Arguments "list" | ForEach-Object { $_.Trim() } | Where-Object { $_ -match "^\d" }
65-
$availableVersions = $rawVersionsList | ForEach-Object {
66-
$partStable,$partMajor = $_.Split(" ", 2)
67-
$semver = $stableSemver = [SemVer]::Parse($partStable)
68-
69-
if ($partMajor) {
70-
# Convert 'beta 3' -> 'beta.3', 'Release Candidate' -> 'releasecandidate', 'GM Seed 2' -> 'gmseed.2'
71-
$normalizedLabel = $partMajor.toLower() -replace " (\d)", '.$1' -replace " ([a-z])", '$1'
72-
$semver = [SemVer]::new($stableSemver.Major, $stableSemver.Minor, $stableSemver.Patch, $normalizedLabel)
73-
}
74-
75-
return [PSCustomObject]@{
76-
semver = $semver
77-
rawVersion = $_
78-
stableSemver = $stableSemver
79-
}
80-
}
81-
82-
return $availableVersions | Sort-Object -Property semver
83-
}
84-
8545
function Expand-XcodeXipArchive {
8646
param (
8747
[Parameter(Mandatory)]
@@ -145,18 +105,16 @@ function Approve-XcodeLicense {
145105
}
146106
}
147107

148-
function Install-XcodeAdditionalPackages {
108+
function Install-XcodeAdditionalComponents {
149109
param (
150110
[Parameter(Mandatory)]
151111
[string] $Version
152112
)
153113

154-
Write-Host "Installing additional packages for Xcode $Version..."
114+
Write-Host "Installing additional MetalToolchain component for Xcode $Version..."
155115
$xcodeRootPath = Get-XcodeRootPath -Version $Version
156-
$packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -File
157-
$packages | ForEach-Object {
158-
Invoke-ValidateCommand "sudo installer -pkg $($_.FullName) -target / -allowUntrusted"
159-
}
116+
$xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $xcodeRootPath -ToolName "xcodebuild"
117+
Invoke-ValidateCommand "$xcodeBuildPath -downloadComponent MetalToolchain" | Out-Null
160118
}
161119

162120
function Invoke-XcodeRunFirstLaunch {
@@ -170,7 +128,7 @@ function Invoke-XcodeRunFirstLaunch {
170128
Invoke-ValidateCommand "sudo $xcodeRootPath -runFirstLaunch"
171129
}
172130

173-
function Install-AdditionalSimulatorRuntimes {
131+
function Install-XcodeAdditionalSimulatorRuntimes {
174132
param (
175133
[Parameter(Mandatory)]
176134
[string] $Version,

0 commit comments

Comments
 (0)