Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,26 @@ Once changes to Ben.Demystifier have been merged into the main branch then, the
should be updated from the main branch and the `modules/make-internal.sh` script run again (if necessary). This repo
should reference the most recent commit on the `internal` branch of Ben.Demystifier then (functionally identical to the
main branch - the only difference being the changes to member visibility).

## Local Sentry Cocoa SDK checkout

By default, `Sentry.Bindings.Cocoa` downloads a pre-built Sentry Cocoa SDK from
GitHub Releases. The version is specified in `modules/sentry-cocoa.properties`.

If you want to build an unreleased Sentry Cocoa SDK version from source instead,
replace the pre-built SDK with [getsentry/sentry-cocoa](https://github.com/getsentry/sentry-cocoa/)
by cloning it into the `modules/sentry-cocoa` directory:

```sh
$ rm -rf modules/sentry-cocoa
$ gh repo clone getsentry/sentry-cocoa modules/sentry-cocoa
$ dotnet build ... # uses modules/sentry-cocoa as is
```

To switch back to the pre-built SDK, delete the `modules/sentry-cocoa` directory
and let the next build download the pre-built SDK again:

```sh
$ rm -rf modules/sentry-cocoa
$ dotnet build ... # downloads pre-built Cocoa SDK into modules/sentry-cocoa
```
4 changes: 3 additions & 1 deletion scripts/build-sentry-cocoa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ xcodebuild archive -project Sentry.xcodeproj \
-archivePath ./Carthage/output-ios.xcarchive \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
./scripts/remove-architectures.sh ./Carthage/output-ios.xcarchive arm64e
xcodebuild archive -project Sentry.xcodeproj \
-scheme Sentry \
-configuration Release \
Expand All @@ -47,6 +48,7 @@ xcodebuild archive -project Sentry.xcodeproj \
-archivePath ./Carthage/output-maccatalyst.xcarchive \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
./scripts/remove-architectures.sh ./Carthage/output-maccatalyst.xcarchive arm64e
xcodebuild -create-xcframework \
-framework ./Carthage/output-maccatalyst.xcarchive/Products/Library/Frameworks/Sentry.framework \
-output ./Carthage/Build-maccatalyst/Sentry.xcframework
Expand All @@ -60,7 +62,7 @@ find Carthage/Build-ios/Sentry.xcframework/ios-arm64 -name '*.h' -exec cp {} Car
find Carthage/Build* \( -name Headers -o -name PrivateHeaders -o -name Modules \) -exec rm -rf {} +
rm -rf Carthage/output-*

cp ../../.git/modules/modules/sentry-cocoa/HEAD Carthage/.built-from-sha
cp .git/HEAD Carthage/.built-from-sha
echo ""

popd >/dev/null
22 changes: 17 additions & 5 deletions scripts/generate-cocoa-bindings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

$RootPath = (Get-Item $PSScriptRoot).Parent.FullName
$CocoaSdkPath = "$RootPath/modules/sentry-cocoa/Sentry.framework"
$CocoaSdkPath = "$RootPath/modules/sentry-cocoa"
if (Test-Path "$CocoaSdkPath/.git")
{
# Cocoa SDK cloned to modules/sentry-cocoa for local development
$HeadersPath = "$CocoaSdkPath/Carthage/Headers"
$PrivateHeadersPath = "$CocoaSdkPath/Carthage/Headers"
}
else
{
# Cocoa SDK downloaded from GitHub releases and extracted into modules/sentry-cocoa
$HeadersPath = "$CocoaSdkPath/Sentry.framework/Headers"
$PrivateHeadersPath = "$CocoaSdkPath/Sentry.framework/PrivateHeaders"
}
$BindingsPath = "$RootPath/src/Sentry.Bindings.Cocoa"
$BackupPath = "$BindingsPath/obj/_unpatched"

Expand Down Expand Up @@ -101,7 +113,7 @@ Write-Output "iPhoneSdkVersion: $iPhoneSdkVersion"
# ...instead of:
# `#import "SomeHeader.h"`
# This causes sharpie to fail resolve those headers
$filesToPatch = Get-ChildItem -Path "$CocoaSdkPath/Headers" -Filter *.h -Recurse | Select-Object -ExpandProperty FullName
$filesToPatch = Get-ChildItem -Path "$HeadersPath" -Filter *.h -Recurse | Select-Object -ExpandProperty FullName
foreach ($file in $filesToPatch)
{
if (Test-Path $file)
Expand All @@ -116,7 +128,7 @@ foreach ($file in $filesToPatch)
Write-Host "File not found: $file"
}
}
$privateHeaderFile = "$CocoaSdkPath/PrivateHeaders/PrivatesHeader.h"
$privateHeaderFile = "$PrivateHeadersPath/PrivatesHeader.h"
if (Test-Path $privateHeaderFile)
{
$content = Get-Content -Path $privateHeaderFile -Raw
Expand All @@ -134,8 +146,8 @@ else
Write-Output 'Generating bindings with Objective Sharpie.'
sharpie bind -sdk $iPhoneSdkVersion `
-scope "$CocoaSdkPath" `
"$CocoaSdkPath/Headers/Sentry.h" `
"$CocoaSdkPath/PrivateHeaders/PrivateSentrySDKOnly.h" `
"$HeadersPath/Sentry.h" `
"$PrivateHeadersPath/PrivateSentrySDKOnly.h" `
-o $BindingsPath `
-c -Wno-objc-property-no-attribute

Expand Down
33 changes: 27 additions & 6 deletions src/Sentry.Bindings.Cocoa/Sentry.Bindings.Cocoa.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
<SentryCocoaProperties>$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)../../modules/sentry-cocoa.properties"))</SentryCocoaProperties>
<SentryCocoaVersion>$([System.Text.RegularExpressions.Regex]::Match($(SentryCocoaProperties), 'version\s*=\s*([^\s]+)').Groups[1].Value)</SentryCocoaVersion>
<SentryCocoaFramework>$(SentryCocoaCache)Sentry-$(SentryCocoaVersion).xcframework</SentryCocoaFramework>
<SentryCocoaBindingInputs>../../modules/sentry-cocoa.properties;../../scripts/generate-cocoa-bindings.ps1</SentryCocoaBindingInputs>
<!-- SentrySpan.g.cs: error CS0108: 'ISentrySpan.Serialize()' hides inherited member 'ISentrySerializable.Serialize()'. Use the new keyword if hiding was intended -->
<NoWarn>$(NoWarn);CS0108</NoWarn>
</PropertyGroup>

<!-- Override values for local Cocoa SDK builds -->
<PropertyGroup Condition="Exists('$(SentryCocoaCache).git')">
<SentryCocoaFramework>$(SentryCocoaCache)Carthage\Build-$(TargetPlatformIdentifier)\Sentry.xcframework</SentryCocoaFramework>
<SentryCocoaBindingInputs>../../scripts/generate-cocoa-bindings.ps1;../../modules/sentry-cocoa/Carthage/.built-from-sha</SentryCocoaBindingInputs>
</PropertyGroup>

<!-- Build empty assemblies when not on macOS, to pass the solution build. -->
<ItemGroup Condition="!$([MSBuild]::IsOSPlatform('OSX'))">
<Compile Remove="*" />
Expand Down Expand Up @@ -52,8 +59,8 @@
</ItemGroup>

<!-- Downloads and sets up the Cocoa SDK: dotnet msbuild /t:setupCocoaSDK src/Sentry.Bindings.Cocoa/Sentry.Bindings.Cocoa.csproj -->
<Target Name="_SetupCocoaSDK"
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaFramework)')">
<Target Name="_DownloadCocoaSDK"
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaCache).git') And !Exists('$(SentryCocoaFramework)')">

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

Expand Down Expand Up @@ -84,14 +91,28 @@
SkipUnchangedFiles="true" />
</Target>

<!-- Build the Sentry Cocoa SDK from source -->
<Target Name="_BuildCocoaSDK"
Condition="$([MSBuild]::IsOSPlatform('OSX')) And Exists('$(SentryCocoaCache).git')"
Inputs="..\..\modules\sentry-cocoa\.git\HEAD;..\..\scripts\build-sentry-cocoa.sh" Outputs="..\..\modules\sentry-cocoa\Carthage\.built-from-sha">

<Message Importance="High" Text="Building the Cocoa SDK from source." />
<Exec Command="bash ../../scripts/build-sentry-cocoa.sh" IgnoreStandardErrorWarningFormat="true" />
</Target>

<!-- Choose between download and build -->
<Target Name="_SetupCocoaSDK"
DependsOnTargets="_DownloadCocoaSDK;_BuildCocoaSDK"
Condition="$([MSBuild]::IsOSPlatform('OSX'))" />

<!-- Setup exactly once: https://learn.microsoft.com/visualstudio/msbuild/run-target-exactly-once -->
<Target Name="SetupCocoaSDKBeforeOuterBuild" DependsOnTargets="_SetupCocoaSDK"
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaFramework)')"
Condition="$([MSBuild]::IsOSPlatform('OSX'))"
BeforeTargets="DispatchToInnerBuilds" />

<Target Name="SetupCocoaSDK"
BeforeTargets="BeforeBuild"
Condition="$([MSBuild]::IsOSPlatform('OSX')) And !Exists('$(SentryCocoaFramework)')">
Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<!-- Setup exactly once: https://learn.microsoft.com/visualstudio/msbuild/run-target-exactly-once -->
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="_SetupCocoaSDK" RemoveProperties="TargetFramework" />
</Target>
Expand All @@ -102,8 +123,8 @@

<!-- Generate bindings -->
<Target Name="_GenerateSentryCocoaBindings" AfterTargets="SetupCocoaSDK"
Condition="$([MSBuild]::IsOSPlatform('OSX')) and Exists('$(SentryCocoaFrameworkHeaders)')"
Inputs="../../modules/sentry-cocoa.properties;../../scripts/generate-cocoa-bindings.ps1"
Condition="$([MSBuild]::IsOSPlatform('OSX'))"
Inputs="$(SentryCocoaBindingInputs)"
Outputs="ApiDefinitions.cs;StructsAndEnums.cs">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="_InnerGenerateSentryCocoaBindings" Properties="TargetFramework=once" />
</Target>
Expand Down
Loading