From e2ff98fda7a974714962e9d43100093eed640bf9 Mon Sep 17 00:00:00 2001 From: Erik Bershel <110455084+erik-bershel@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:06:17 +0200 Subject: [PATCH] [macOS] Rebuild dyld shared cache for latest stable Xcode (#13149) --- images/macos/scripts/build/Install-Xcode.ps1 | 5 +++++ .../scripts/helpers/Xcode.Installer.psm1 | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/images/macos/scripts/build/Install-Xcode.ps1 b/images/macos/scripts/build/Install-Xcode.ps1 index 7aa6c2c03..74a34642d 100644 --- a/images/macos/scripts/build/Install-Xcode.ps1 +++ b/images/macos/scripts/build/Install-Xcode.ps1 @@ -39,6 +39,11 @@ $xcodeVersions | ForEach-Object { } } +# Update dyld shared cache for the latest stable Xcode version +if ((-not $os.IsSonoma)) { + Update-DyldCache -XcodeVersions $xcodeVersions +} + Invoke-XcodeRunFirstLaunch -Version $defaultXcode Write-Host "Configuring Xcode symlinks..." diff --git a/images/macos/scripts/helpers/Xcode.Installer.psm1 b/images/macos/scripts/helpers/Xcode.Installer.psm1 index 1007f7343..132f54f68 100644 --- a/images/macos/scripts/helpers/Xcode.Installer.psm1 +++ b/images/macos/scripts/helpers/Xcode.Installer.psm1 @@ -316,3 +316,23 @@ function Invoke-ValidateCommand { Receive-Job -Job $job } } + +function Update-DyldCache { + param ( + [Parameter(Mandatory)] + [array] $XcodeVersions + ) + + # Find the latest stable Xcode version (excluding beta and RC versions) + $latestStableXcode = $XcodeVersions | Where-Object { + -not ($_.link.Contains("beta") -or $_.link.Contains("Release_Candidate") -or $_.link.Contains("_RC")) + } | Sort-Object { [version]($_.version -split '\+')[0] } -Descending | Select-Object -First 1 + + if ($latestStableXcode) { + Write-Host "Updating dyld shared cache for Xcode $($latestStableXcode.link)..." + Switch-Xcode -Version $latestStableXcode.link + Invoke-ValidateCommand "xcrun simctl runtime dyld_shared_cache update --all" + } else { + Write-Host "No stable Xcode version found for dyld cache update." + } +}