Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6696c12
WIP: Generate bindings from Sentry-Swift.h
jpnurmi Sep 2, 2025
28efafc
Fix Xcode 26
jpnurmi Oct 29, 2025
9a504f3
Support wildcards
jpnurmi Oct 29, 2025
d4be03c
Support negation
jpnurmi Oct 29, 2025
f8cf3a8
Process attributes
jpnurmi Oct 29, 2025
21a86be
Remove unneeded Constants
jpnurmi Oct 29, 2025
15a8b02
SentryOnAppStartMeasurementAvailable
jpnurmi Oct 29, 2025
830be9a
SentryStructuredLogAttribute
jpnurmi Oct 29, 2025
f69b682
ref: SyntaxNode/StringExtensions
jpnurmi Oct 29, 2025
74610f8
Insert namespace
jpnurmi Oct 30, 2025
79a385b
Rename SentryRRWebEvent
jpnurmi Oct 30, 2025
6cc4c84
Models
jpnurmi Oct 30, 2025
8a4057e
INSCopying
jpnurmi Oct 30, 2025
bb48bea
tabs to spaces
jpnurmi Oct 30, 2025
0bdee43
Interfaces
jpnurmi Oct 30, 2025
f6d9119
Argument names
jpnurmi Oct 30, 2025
db67798
partial SentryScope
jpnurmi Oct 30, 2025
e366852
MethodToProperty
jpnurmi Oct 30, 2025
eda4876
Format
jpnurmi Oct 30, 2025
85f6fa5
StronglyTypedNSArray
jpnurmi Oct 30, 2025
49c1000
DEPRECATED_MSG_ATTRIBUTE
jpnurmi Oct 30, 2025
5339c6b
StructsAndEnums
jpnurmi Oct 30, 2025
a46c385
Header
jpnurmi Oct 30, 2025
b6db1e3
Try .NET 10 run script
jpnurmi Oct 30, 2025
d38c428
Minor clean up...
jpnurmi Oct 30, 2025
59f6d78
Fix comment
jpnurmi Oct 30, 2025
63316c8
Fix rename
jpnurmi Oct 30, 2025
18aabbf
Remove SentrySession
jpnurmi Oct 30, 2025
b595c57
Clean up...
jpnurmi Oct 30, 2025
e02c641
Restore trailing line-break
jpnurmi Oct 30, 2025
d168d49
Fix interfaces
jpnurmi Oct 30, 2025
0efe682
Shorten switch-cases
jpnurmi Oct 30, 2025
c426d61
Refactor
jpnurmi Oct 31, 2025
a1d4b66
Prepare KeepMethod/Properties for V9
jpnurmi Oct 31, 2025
857f793
Fix WildcardExtensions.Matches
jpnurmi Oct 31, 2025
32714c0
$PSNativeCommandUseErrorActionPreference = $true
jpnurmi Oct 31, 2025
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
170 changes: 28 additions & 142 deletions scripts/generate-cocoa-bindings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true

$RootPath = (Get-Item $PSScriptRoot).Parent.FullName
$CocoaSdkPath = "$RootPath/modules/sentry-cocoa"
Expand Down Expand Up @@ -103,8 +104,11 @@ if (!(Test-Path '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/
}

# Get iPhone SDK version
$iPhoneSdkVersion = sharpie xcode -sdks | grep -o -m 1 'iphoneos\S*'
$XcodePath = (xcode-select -p) -replace '/Contents/Developer$', ''
$iPhoneSdkVersion = sharpie xcode -xcode $XcodePath -sdks | grep -o -m 1 'iphoneos\S*'
Write-Output "iPhoneSdkVersion: $iPhoneSdkVersion"
$iPhoneSdkPath = xcrun --show-sdk-path --sdk $iPhoneSdkVersion
Write-Output "iPhoneSdkPath: $iPhoneSdkPath"

## Imports in the various header files are provided in the "new" style of:
# `#import <Sentry/SomeHeader.h>`
Expand Down Expand Up @@ -141,173 +145,55 @@ else
{
Write-Host "File not found: $privateHeaderFile"
}
$swiftHeaderFile = "$HeadersPath/Sentry-Swift.h"
if (Test-Path $swiftHeaderFile)
{
$content = Get-Content -Path $swiftHeaderFile -Raw
# Replace module @imports with traditional #includes
$content = $content -replace '(?m)^#if\s+(__has_feature\(objc_modules\))', '#if 1 // $1'
$content = $content -replace '(?m)^@import\s+ObjectiveC;\s*\n', ''
$content = $content -replace '(?m)^@import\s+(\w+);', '#include <$1/$1.h>'
$content = $content -replace '(?m)^#import\s+"Sentry.h"\s*\n', ''

Set-Content -Path $swiftHeaderFile -Value $content
Write-Host "Patched includes: $swiftHeaderFile"
}
else
{
Write-Host "File not found: $swiftHeaderFile"
}

# Generate bindings
Write-Output 'Generating bindings with Objective Sharpie.'
sharpie bind -sdk $iPhoneSdkVersion `
-scope "$CocoaSdkPath" `
"$HeadersPath/Sentry.h" `
"$HeadersPath/Sentry-Swift.h" `
"$PrivateHeadersPath/PrivateSentrySDKOnly.h" `
-o $BindingsPath `
-c -Wno-objc-property-no-attribute
-c -Wno-objc-property-no-attribute `
-F"$iPhoneSdkPath/System/Library/SubFrameworks" # needed for UIUtilities.framework in Xcode 26+

# Ensure backup path exists
if (!(Test-Path $BackupPath))
{
New-Item -ItemType Directory -Path $BackupPath | Out-Null
}

# The following header will be added to patched files. The notice applies
# to those files, not this script which generates the files.
$Header = @"
// -----------------------------------------------------------------------------
// This file is auto-generated by Objective Sharpie and patched via the script
// at /scripts/generate-cocoa-bindings.ps1. Do not edit this file directly.
// If changes are required, update the script instead.
// -----------------------------------------------------------------------------
"@
Push-Location $PSScriptRoot

################################################################################
# Patch StructsAndEnums.cs
################################################################################
$File = 'StructsAndEnums.cs'
Write-Output "Patching $BindingsPath/$File"
Copy-Item "$BindingsPath/$File" -Destination "$BackupPath/$File"
$Text = Get-Content "$BindingsPath/$File" -Raw

# Tabs to spaces
$Text = $Text -replace '\t', ' '

# Trim extra newline at EOF
$Text = $Text -replace '\n$', ''

# Insert namespace
$Text = $Text -replace 'using .+;\n\n', "$&namespace Sentry.CocoaSdk;`n`n"

# Public to internal
$Text = $Text -replace '\bpublic\b', 'internal'

# Remove static CFunctions class
$Text = $Text -replace '(?ms)\nstatic class CFunctions.*?}\n', ''

# Add header and output file
$Text = "$Header`n`n$Text"
$Text | Out-File "$BindingsPath/$File"
& dotnet run "$PSScriptRoot/patch-cocoa-bindings.cs" "$BindingsPath/$File" | ForEach-Object { Write-Host $_ }

################################################################################
# Patch ApiDefinitions.cs
################################################################################
$File = 'ApiDefinitions.cs'
Write-Output "Patching $BindingsPath/$File"
Copy-Item "$BindingsPath/$File" -Destination "$BackupPath/$File"
$Text = Get-Content "$BindingsPath/$File" -Raw

# Tabs to spaces
$Text = $Text -replace '\t', ' '

# Trim extra newline at EOF
$Text = $Text -replace '\n$', ''

# Insert namespace
$Text = $Text -replace 'using .+;\n\n', "$&namespace Sentry.CocoaSdk;`n`n"

# Set Internal attributes on interfaces and delegates
$Text = $Text -replace '(?m)^(partial interface|interface|delegate)\b', "[Internal]`n$&"

# Fix ISentrySerializable usage
$Text = $Text -replace '\bISentrySerializable\b', 'SentrySerializable'

# Remove INSCopying due to https://github.com/xamarin/xamarin-macios/issues/17130
$Text = $Text -replace ': INSCopying,', ':' -replace '\s?[:,] INSCopying', ''

# Remove iOS attributes like [iOS (13, 0)]
$Text = $Text -replace '\[iOS \(13,\s?0\)\]\n?\s*', ''

# Remove Unavailable attributes like [Unavailable (PlatformName.iOSAppExtension)]
$Text = $Text -replace '\[Unavailable \(PlatformName\.\w+\)\]\n?\s*', ''

# Fix delegate argument names
$Text = $Text -replace '(NSError) arg\d', '$1 error'
$Text = $Text -replace '(NSHttpUrlResponse) arg\d', '$1 response'
$Text = $Text -replace '(SentryEvent) arg\d', '$1 @event'
$Text = $Text -replace '(SentrySamplingContext) arg\d', '$1 samplingContext'
$Text = $Text -replace '(SentryBreadcrumb) arg\d', '$1 breadcrumb'
$Text = $Text -replace '(SentrySpan) arg\d', '$1 span'
$Text = $Text -replace '(SentryAppStartMeasurement) arg\d', '$1 appStartMeasurement'
$Text = $Text -replace '(SentryLog) arg\d', '$1 log'

# Adjust nullable return delegates (though broken until this is fixed: https://github.com/xamarin/xamarin-macios/issues/17109)
$Text = $Text -replace 'delegate \w+ Sentry(BeforeBreadcrumb|BeforeSendEvent|TracesSampler)Callback', "[return: NullAllowed]`n$&"

# Adjust protocols (some are models)
$Text = $Text -replace '(?ms)(@protocol.+?)/\*.+?\*/', '$1'
$Text = $Text -replace '(?ms)@protocol (SentrySerializable|SentrySpan).+?\[Protocol\]', "`$&`n[Model]"

# Adjust SentrySpan base type
$Text = $Text -replace 'interface SentrySpan\b', "[BaseType (typeof(NSObject))]`n`$&"

# Fix string constants
$Text = $Text -replace '(?m)(.*\n){2}^\s{4}NSString k.+?\n\n?', ''
$Text = $Text -replace '(?m)(.*\n){4}^partial interface Constants\n{\n}\n', ''
$Text = $Text -replace '\[Verify \(ConstantsInterfaceAssociation\)\]\n', ''

# Remove SentryVersionNumber
$Text = $Text -replace '.*SentryVersionNumber.*\n?', ''

# Remove SentryVersionString
$Text = $Text -replace '.*SentryVersionString.*\n?', ''

# Remove duplicate attributes
$s = 'partial interface Constants'
$t = $Text -split $s, 2
$t[1] = $t[1] -replace "\[Static\]\n\[Internal\]\n$s", $s
$Text = $t -join $s

# Remove empty Constants block
$Text = $Text -replace '\[Static\]\s*\[Internal\]\s*partial\s+interface\s+Constants\s\{[\s\n]*\}\n\n', ''

# Update MethodToProperty translations
$Text = $Text -replace '(Export \("get\w+"\)\]\n)\s*\[Verify \(MethodToProperty\)\]\n(.+ \{ get; \})', '$1$2'
$Text = $Text -replace '\[Verify \(MethodToProperty\)\]\n\s*(.+ (?:Hash|Value|DefaultIntegrations|AppStartMeasurementWithSpans|BaggageHttpHeader) \{ get; \})', '$1'
$Text = $Text -replace '\[Verify \(MethodToProperty\)\]\n\s*(.+) \{ get; \}', '$1();'

# Allow weakly typed NSArray
# We have some that accept either NSString or NSRegularExpression, which have no common type so they use NSObject
$Text = $Text -replace '\s*\[Verify \(StronglyTypedNSArray\)\]\n', ''

# Fix broken multi-line comments
$Text = $Text -replace '(DEPRECATED_MSG_ATTRIBUTE\()\n\s*', '$1'
$Text = $Text -replace '(DEPRECATED_MSG_ATTRIBUTE\([^)]*?)"\s*\r?\n\s*"', '$1 '

# Remove default IsEqual implementation (already implemented by NSObject)
$Text = $Text -replace '(?ms)\n?^ *// [^\n]*isEqual:.*?$.*?;\n', ''

# Replace obsolete platform availability attributes
$Text = $Text -replace '([\[,] )MacCatalyst \(', '$1Introduced (PlatformName.MacCatalyst, '
$Text = $Text -replace '([\[,] )Mac \(', '$1Introduced (PlatformName.MacOSX, '
$Text = $Text -replace '([\[,] )iOS \(', '$1Introduced (PlatformName.iOS, '

# Make interface partial if we need to access private APIs. Other parts will be defined in PrivateApiDefinitions.cs
$Text = $Text -replace '(?m)^interface SentryScope', 'partial $&'

$Text = $Text -replace '.*SentryEnvelope .*?[\s\S]*?\n\n', ''
$Text = $Text -replace '.*typedef.*SentryOnAppStartMeasurementAvailable.*?[\s\S]*?\n\n', ''

$propertiesToRemove = @(
'SentryAppStartMeasurement',
'SentryOnAppStartMeasurementAvailable',
'SentryMetricsAPI',
'SentryExperimentalOptions',
'description',
'enableMetricKitRawPayload'
)

foreach ($property in $propertiesToRemove)
{
$Text = $Text -replace "\n.*property.*$property.*?[\s\S]*?\}\n", ''
}


# Add header and output file
$Text = "$Header`n`n$Text"
$Text | Out-File "$BindingsPath/$File"
& dotnet run "$PSScriptRoot/patch-cocoa-bindings.cs" "$BindingsPath/$File" | ForEach-Object { Write-Host $_ }
Loading
Loading