Skip to content

Commit f21af55

Browse files
authored
chore: Create iOS-only xcframework in CI (#2264)
1 parent 3bd4aad commit f21af55

File tree

7 files changed

+194
-1306
lines changed

7 files changed

+194
-1306
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ jobs:
7373
path: package-dev/Plugins/Android
7474
wait-timeout: 3600
7575

76+
- name: Download Cocoa SDK
77+
uses: vaind/download-artifact@e7141b6a94ef28aa3d828b52830cfa1f406a1848 # v4-with-wait-timeout
78+
with:
79+
name: Cocoa-sdk
80+
path: package-dev/Plugins
81+
wait-timeout: 3600
82+
7683
- name: Download Linux SDK
7784
uses: vaind/download-artifact@e7141b6a94ef28aa3d828b52830cfa1f406a1848 # v4-with-wait-timeout
7885
with:
@@ -88,7 +95,7 @@ jobs:
8895
wait-timeout: 3600
8996

9097
- name: Build Sentry.Unity Solution
91-
run: docker exec unity dotnet build -c Release
98+
run: docker exec unity dotnet build -c Release -v:d
9299

93100
- name: Install assemblyalias
94101
run: docker exec unity dotnet tool install --global Alias --version 0.4.3 --allow-roll-forward

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
host: ubuntu-latest
4242
- target: Windows
4343
host: windows-latest
44+
- target: Cocoa
45+
host: macos-latest
4446
uses: ./.github/workflows/sdk.yml
4547
with:
4648
target: ${{ matrix.target }}

.github/workflows/sdk.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,27 @@ jobs:
4949
run: |
5050
if [[ "${TARGET}" == "Android" ]]; then
5151
submodules="modules/sentry-java"
52+
elif [[ "${TARGET}" == "Cocoa" ]]; then
53+
submodules=""
5254
else
5355
submodules="modules/sentry-native"
5456
fi
55-
5657
echo "submodulesPath=$submodules" >> $GITHUB_OUTPUT
57-
echo "submodules=src/sentry-dotnet $submodules" >> $GITHUB_OUTPUT
58-
58+
if [[ "$submodules" == "" ]]; then
59+
echo "submodules=src/sentry-dotnet" >> $GITHUB_OUTPUT
60+
else
61+
echo "submodules=src/sentry-dotnet $submodules" >> $GITHUB_OUTPUT
62+
fi
5963
- name: Get submodule status
6064
run: git submodule status --cached ${{ steps.env.outputs.submodules }} | tee submodules-status
6165

62-
- run: cp -r package-dev/Plugins/${{ env.TARGET }} sdk-static || echo "never mind, no files checked in..."
66+
- run: |
67+
if [[ "${{ env.TARGET }}" == "Cocoa" ]]; then
68+
cp -r package-dev/Plugins/iOS sdk-static/ || echo "never mind, no iOS files checked in..."
69+
cp -r package-dev/Plugins/macOS sdk-static/ || echo "never mind, no macOS files checked in..."
70+
else
71+
cp -r package-dev/Plugins/${{ env.TARGET }} sdk-static || echo "never mind, no files checked in..."
72+
fi
6373
shell: bash
6474
6575
- name: Restore from cache
@@ -92,14 +102,26 @@ jobs:
92102
dotnet msbuild /t:Build${{ env.TARGET }}SDK /p:Configuration=Release /p:OutDir=other src/Sentry.Unity
93103
94104
- name: Upload build logs on failure
95-
if: ${{ failure() }}
105+
# No build logs for Cocoa SDK as we assemble the xcframework from a downloaded release artifact
106+
if: ${{ failure() && env.TARGET != 'Cocoa' }}
96107
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
97108
with:
98109
path: ${{ steps.env.outputs.submodulesPath }}/build.log
99110
# Lower retention period - we only need this to retry CI.
100111
retention-days: 14
101112

102113
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
114+
if: ${{ env.TARGET == 'Cocoa' }}
115+
with:
116+
name: ${{ env.TARGET }}-sdk
117+
path: |
118+
package-dev/Plugins/iOS
119+
package-dev/Plugins/macOS
120+
# Lower retention period - we only need this to retry CI.
121+
retention-days: 14
122+
123+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
124+
if: ${{ env.TARGET != 'Cocoa' }}
103125
with:
104126
name: ${{ env.TARGET }}-sdk
105127
path: package-dev/Plugins/${{ env.TARGET }}

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- For targeting iOS, the Unity SDK now brings an iOS-only `.xcframework`, reducing package size. ([#2264](https://github.com/getsentry/sentry-unity/pull/2264))
8+
59
### Dependencies
610

711
- Bump Java SDK from v8.17.0 to v8.18.0 ([#2261](https://github.com/getsentry/sentry-unity/pull/2261))
812
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#8180)
913
- [diff](https://github.com/getsentry/sentry-java/compare/8.17.0...8.18.0)
10-
- Bump .NET SDK from v5.12.0-14-g25a894dd to v5.13.0 ([#2259](https://github.com/getsentry/sentry-unity/pull/2259))
14+
- Bump .NET SDK from v5.12.0 to v5.13.0 ([#2259](https://github.com/getsentry/sentry-unity/pull/2259))
1115
- [changelog](https://github.com/getsentry/sentry-dotnet/blob/main/CHANGELOG.md#5130)
1216
- [diff](https://github.com/getsentry/sentry-dotnet/compare/5.12.0-14-g25a894dd...5.13.0)
1317

Directory.Build.targets

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ Expected to exist:
185185
</Target>
186186

187187
<!-- Downloads and sets up the Cocoa SDK: dotnet msbuild /t:SetupCocoaSDK src/Sentry.Unity -->
188-
<Target Name="SetupCocoaSDK"
188+
<!-- Note: This target is now handled by CI for official builds, but kept for local development -->
189+
<Target Name="BuildCocoaSDK"
189190
Condition="!$([MSBuild]::IsOSPlatform('Windows')) AND '$(MSBuildProjectName)' == 'Sentry.Unity'
190191
And (!Exists('$(SentryiOSArtifactsDestination)') Or !Exists('$(SentrymacOSArtifactsDestination)Sentry.dylib'))"
191192
BeforeTargets="BeforeBuild">
@@ -197,34 +198,9 @@ Expected to exist:
197198

198199
<Message Importance="High" Text="Setting up the Cocoa SDK version '$(CocoaVersion)'." />
199200

200-
<!-- Clean cache if version does not exist to get rid of old versions -->
201-
<RemoveDir
202-
Condition="!Exists('$(SentryCocoaCache)Sentry-Dynamic-$(CocoaVersion).xcframework.zip')"
203-
Directories="$(SentryCocoaCache)" />
204-
205-
<!-- Create cache directory -->
206-
<MakeDir Condition="!Exists('$(SentryCocoaCache)')" Directories="$(SentryCocoaCache)" />
207-
208-
<!-- Download the Cocoa SDK as pre-built .xcframework -->
209-
<Exec
210-
Condition="!Exists('$(SentryCocoaCache)Sentry-Dynamic-$(CocoaVersion).xcframework.zip')"
211-
Command="curl -L https://github.com/getsentry/sentry-cocoa/releases/download/$(CocoaVersion)/Sentry-Dynamic.xcframework.zip -o $(SentryCocoaCache)Sentry-Dynamic-$(CocoaVersion).xcframework.zip" />
201+
<Exec Command="pwsh &quot;$(RepoRoot)scripts/setup-cocoa-sdk.ps1&quot; -RepoRoot &quot;$(RepoRoot)&quot; -CocoaVersion &quot;$(CocoaVersion)&quot; -CocoaCache &quot;$(SentryCocoaCache)&quot; -iOSDestination &quot;$(SentryiOSArtifactsDestination)&quot; -macOSDestination &quot;$(SentrymacOSArtifactsDestination)Sentry.dylib&quot;" />
212202

213-
<Exec
214-
Condition="!Exists('$(SentryCocoaCache)Sentry-Dynamic.xcframework')"
215-
Command="unzip -o $(SentryCocoaCache)Sentry-Dynamic-$(CocoaVersion).xcframework.zip -d $(SentryCocoaCache)" />
216-
217-
<!-- Set up the iOS support -->
218-
<ItemGroup>
219-
<!-- Itemgroup for the output Sentry.framework so we have access to '%(RecursiveDir)' when copying -->
220-
<xcframeworkdPath Include="$(SentryCocoaCache)/Sentry-Dynamic.xcframework/**/*" />
221-
</ItemGroup>
222-
<Copy SourceFiles="@(xcframeworkdPath)" DestinationFiles="@(xcframeworkdPath->'$(SentryiOSArtifactsDestination)%(RecursiveDir)%(Filename)%(Extension)')" />
223203
<Error Condition="(!Exists('$(SentryiOSArtifactsDestination)'))" Text="Failed to set up the iOS SDK." />
224-
225-
<!-- Set up the macOS support -->
226-
<Copy SourceFiles="$(SentryCocoaCache)Sentry-Dynamic.xcframework/macos-arm64_arm64e_x86_64/Sentry.framework/Sentry" DestinationFiles="$(SentrymacOSArtifactsDestination)Sentry.dylib" />
227-
<Copy SourceFiles="$(SentryCocoaCache)Sentry-Dynamic.xcframework/macos-arm64_arm64e_x86_64/dSYMs/Sentry.framework.dSYM/Contents/Resources/DWARF/Sentry" DestinationFiles="$(SentrymacOSArtifactsDestination)Sentry.dylib.dSYM" />
228204
<Error Condition="(!Exists('$(SentrymacOSArtifactsDestination)Sentry.dylib') Or !Exists('$(SentrymacOSArtifactsDestination)Sentry.dylib.dSYM'))" Text="Failed to set up the macOS SDK." />
229205
</Target>
230206

@@ -601,6 +577,7 @@ void PrintFailedTests(XElement element)
601577
<SDK Include="Windows"/>
602578
<SDK Include="Android"/>
603579
<SDK Include="Linux"/>
580+
<SDK Include="Cocoa"/>
604581
</ItemGroup>
605582
<Message Importance="High" Text="Replacing $(SentryArtifactsDestination)%(SDK.Identity)" />
606583
<RemoveDir Directories="$(SentryArtifactsDestination)%(SDK.Identity)" />
@@ -610,4 +587,4 @@ void PrintFailedTests(XElement element)
610587
<Message Importance="High" Text="Restoring package-dev/Plugins to the latest git commit" />
611588
<Exec WorkingDirectory="$(RepoRoot)" Command="git restore package-dev/Plugins" />
612589
</Target>
613-
</Project>
590+
</Project>

scripts/setup-cocoa-sdk.ps1

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env pwsh
2+
3+
param(
4+
[Parameter(Mandatory=$true)]
5+
[string]$RepoRoot,
6+
7+
[Parameter(Mandatory=$true)]
8+
[string]$CocoaVersion,
9+
10+
[Parameter(Mandatory=$true)]
11+
[string]$CocoaCache,
12+
13+
[Parameter(Mandatory=$true)]
14+
[string]$iOSDestination,
15+
16+
[Parameter(Mandatory=$true)]
17+
[string]$macOSDestination,
18+
19+
[switch]$iOSOnly
20+
)
21+
22+
Set-StrictMode -Version latest
23+
$ErrorActionPreference = 'Stop'
24+
$PSNativeCommandUseErrorActionPreference = $true
25+
26+
# Clean cache if version does not exist to get rid of old versions
27+
$zipFile = Join-Path $CocoaCache "Sentry-Dynamic-$CocoaVersion.xcframework.zip"
28+
if (-not (Test-Path $zipFile)) {
29+
Write-Host "Cleaning cache directory for new version..." -ForegroundColor Yellow
30+
if (Test-Path $CocoaCache) {
31+
Remove-Item -Path $CocoaCache -Recurse -Force
32+
}
33+
}
34+
35+
if (-not (Test-Path $CocoaCache)) {
36+
New-Item -ItemType Directory -Path $CocoaCache -Force | Out-Null
37+
}
38+
39+
if (-not (Test-Path $zipFile)) {
40+
Write-Host "Downloading Cocoa SDK version '$CocoaVersion'..." -ForegroundColor Yellow
41+
$downloadUrl = "https://github.com/getsentry/sentry-cocoa/releases/download/$CocoaVersion/Sentry-Dynamic.xcframework.zip"
42+
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipFile
43+
}
44+
45+
$xcframeworkPath = Join-Path $CocoaCache "Sentry-Dynamic.xcframework"
46+
if (-not (Test-Path $xcframeworkPath)) {
47+
Write-Host "Extracting xcframework..." -ForegroundColor Yellow
48+
Expand-Archive -Path $zipFile -DestinationPath $CocoaCache -Force
49+
}
50+
51+
################ Set up iOS support ################
52+
# We strip out the iOS frameworks and create a new xcframework out of those.
53+
54+
Write-Host "Setting up iOS frameworks..." -ForegroundColor Yellow
55+
56+
$iOSFrameworks = Get-ChildItem -Path $xcframeworkPath -Directory | Where-Object { $_.Name -like "ios-*" -and $_.Name -notlike "*maccatalyst*" }
57+
if ($iOSFrameworks.Count -eq 0) {
58+
Write-Error "No iOS frameworks found in xcframework at: $xcframeworkPath"
59+
exit 1
60+
}
61+
62+
Write-Host "Found $($iOSFrameworks.Count) iOS frameworks:" -ForegroundColor Green
63+
foreach ($framework in $iOSFrameworks) {
64+
Write-Host " - $($framework.Name)" -ForegroundColor Cyan
65+
}
66+
67+
$xcodebuildArgs = @("-create-xcframework")
68+
69+
foreach ($framework in $iOSFrameworks) {
70+
$frameworkPath = Join-Path $framework.FullName "Sentry.framework"
71+
if (Test-Path $frameworkPath) {
72+
$xcodebuildArgs += "-framework"
73+
$xcodebuildArgs += $frameworkPath
74+
Write-Host "Adding framework: $frameworkPath" -ForegroundColor Cyan
75+
} else {
76+
Write-Warning "Framework not found at: $frameworkPath"
77+
}
78+
}
79+
80+
# Remove the ~ suffix from destination. xcodebuild requires the output path to end with `.xcframework`
81+
$xcframeworkDestination = $iOSDestination.TrimEnd('~', '/')
82+
83+
$xcodebuildArgs += "-output"
84+
$xcodebuildArgs += $xcframeworkDestination
85+
86+
Write-Host "Creating iOS-only xcframework..." -ForegroundColor Yellow
87+
Write-Host "Command: xcodebuild $($xcodebuildArgs -join ' ')" -ForegroundColor Gray
88+
89+
try {
90+
& xcodebuild @xcodebuildArgs
91+
if ($LASTEXITCODE -ne 0) {
92+
Write-Error "xcodebuild failed with exit code: $LASTEXITCODE"
93+
exit 1
94+
}
95+
Write-Host "Successfully created iOS-only xcframework at: $xcframeworkDestination" -ForegroundColor Green
96+
} catch {
97+
Write-Error "Failed to run xcodebuild: $($_.Exception.Message)"
98+
exit 1
99+
}
100+
101+
Write-Host "Appending '~' for Unity to ignore the framework"
102+
Move-Item -Path $xcframeworkDestination -Destination $iOSDestination -Force
103+
104+
$iOSInfoPlist = Join-Path $iOSDestination "Info.plist"
105+
if (-not (Test-Path $iOSDestination) -or -not (Test-Path $iOSInfoPlist)) {
106+
Write-Error "Failed to set up the iOS SDK."
107+
exit 1
108+
}
109+
110+
################ Set up macOS support ################
111+
# We copy the .dylib and the .dSYM directly into the plugins folder
112+
113+
if (-not $iOSOnly) {
114+
Write-Host "Setting up macOS support..." -ForegroundColor Yellow
115+
116+
$macOSFrameworkPath = Join-Path $xcframeworkPath "macos-arm64_arm64e_x86_64/Sentry.framework/Sentry"
117+
$macOSdSYMPath = Join-Path $xcframeworkPath "macos-arm64_arm64e_x86_64/dSYMs/Sentry.framework.dSYM/Contents/Resources/DWARF/Sentry"
118+
119+
$macOSDestDir = Split-Path $macOSDestination -Parent
120+
if (-not (Test-Path $macOSDestDir)) {
121+
New-Item -ItemType Directory -Path $macOSDestDir -Force | Out-Null
122+
}
123+
124+
if (Test-Path $macOSFrameworkPath) {
125+
Copy-Item -Path $macOSFrameworkPath -Destination $macOSDestination -Force
126+
Write-Host "Copied macOS dylib to: $macOSDestination" -ForegroundColor Green
127+
} else {
128+
Write-Error "macOS framework not found at: $macOSFrameworkPath"
129+
exit 1
130+
}
131+
132+
$macOSdSYMDestination = "$macOSDestination.dSYM"
133+
if (Test-Path $macOSdSYMPath) {
134+
Copy-Item -Path $macOSdSYMPath -Destination $macOSdSYMDestination -Force
135+
Write-Host "Copied macOS dSYM to: $macOSdSYMDestination" -ForegroundColor Green
136+
} else {
137+
Write-Error "macOS dSYM not found at: $macOSdSYMPath"
138+
exit 1
139+
}
140+
141+
if (-not (Test-Path $macOSDestination) -or -not (Test-Path $macOSdSYMDestination)) {
142+
Write-Error "Failed to set up the macOS SDK."
143+
exit 1
144+
}
145+
}
146+
147+
Write-Host "Cocoa SDK setup completed successfully!" -ForegroundColor Green

0 commit comments

Comments
 (0)