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