Skip to content
Draft
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
17 changes: 8 additions & 9 deletions scripts/generate-cocoa-bindings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ foreach ($file in $filesToPatch)
if (Test-Path $file)
{
$content = Get-Content -Path $file -Raw
$content = $content -replace '<SentryObjC/([^>]+)>', '"$1"'
$content = $content -replace '<Sentry/([^>]+)>', '"$1"'
$content = $content -replace '#\s*import SENTRY_HEADER\(([^)]+)\)', '#import "$1.h"'
Set-Content -Path $file -Value $content
Expand Down Expand Up @@ -155,18 +156,16 @@ else
}

# Generate bindings
# The SentryObjC*.h headers expose the structured hybrid API (SentryObjCSDK.internal)
# We bind the SentryObjC umbrella header only. It exposes the full public surface
# (options, SDK entry point, event model, scope, enums) plus the structured hybrid API
# (SentryObjCSDK.internal, incl. debug images) via SentryObjC* classes. The classic
# Sentry.framework ObjC surface is no longer bound here; the few remaining classic
# holdouts (scope.applyToEvent enrichment + the SentrySerializable protocol) are declared
# by hand in PrivateApiDefinitions.cs. See getsentry/sentry-dotnet#5444.
Write-Output 'Generating bindings with Objective Sharpie.'
sharpie bind -sdk $iPhoneSdkVersion `
-scope "$CocoaSdkPath" `
"$HeadersPath/Sentry.h" `
"$HeadersPath/Sentry-Swift.h" `
"$HeadersPath/SentryObjCSDK.h" `
"$HeadersPath/SentryObjCInternalApi.h" `
"$HeadersPath/SentryObjCInternalSdkApi.h" `
"$HeadersPath/SentryObjCInternalProfilingApi.h" `
"$HeadersPath/SentryObjCId.h" `
"$HeadersPath/SentryObjCSpanId.h" `
"$HeadersPath/SentryObjC.h" `
-o $BindingsPath `
-c -Wno-objc-property-no-attribute `
-F"$iPhoneSdkPath/System/Library/SubFrameworks" # needed for UIUtilities.framework in Xcode 26+
Expand Down
164 changes: 48 additions & 116 deletions scripts/patch-cocoa-bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,60 +32,29 @@
var nodes = tree.GetCompilationUnitRoot()
.WithNamespace("Sentry.CocoaSdk")
.RemoveClass("CFunctions")
// Fold Swift-extension categories back into their base interface. Objective Sharpie emits
// members declared in a Swift `extension` (e.g. the entire `SentrySDK` API since sentry-cocoa
// 9.19.1 moved its class body into an extension) as a separate `[Category]` interface with an
// auto-generated name like `SentrySDK_Sentry_Swift_8248`. Left alone, KeepInterfaces would drop
// it because that generated name isn't in the keep-list, silently emptying the SentrySDK binding.
.MergeInterface("SentrySDK_*", "SentrySDK")
// Make enums, interfaces, and delegates internal
.AsInternal("Sentry*", "internal")
.WithAttribute("*Sentry*", "Internal")
// Adjust protocols (some are models)
.VerifyModel("SentryRedactOptions")
.VerifyModel("SentrySerializable")
.VerifyModel("SentrySpan")
.RemoveComment("SentryRRWebEvent", "[Model]")
.RemoveComment("SentryReplayBreadcrumbConverter", "[Model]")
.RemoveComment("SentryViewScreenshotProvider", "[Model]")
// Adjust base types
.WithAttribute("SentrySpan", "BaseType (typeof(NSObject))")
.WithAttribute("SentryRedactOptions", "BaseType (typeof(NSObject))")
// Remove INSCopying due to https://github.com/xamarin/xamarin-macios/issues/17130
.RemoveBaseType("INSCopying")
// Fix property-to-method conversions
.PropertyToMethod("Sentry*", "Serialize")
.PropertyToMethod("SentrySpan", "ToTraceHeader")
.PropertyToMethod("SentryTraceContext", "ToBaggage")
.PropertyToMethod("SentryObjCSpan", "ToTraceHeader")
.PropertyToMethod("SentryObjCTraceContext", "ToBaggage")
// Verify the rest
.VerifyProperty("*Sentry*", "*", "MethodToProperty") // TODO: replace broad patterns with one-by-one verification
.VerifyProperty("SentryOptions", "*Targets", "StronglyTypedNSArray")
.VerifyProperty("SentryObjCOptions", "*Targets", "StronglyTypedNSArray")
// Fix delegate argument names
.RenameParameter("NSError", "arg*", "error")
.RenameParameter("NSHttpUrlResponse", "arg*", "response")
.RenameParameter("SentryEvent", "arg*", "@event")
.RenameParameter("SentrySamplingContext", "arg*", "samplingContext")
.RenameParameter("SentryBreadcrumb", "arg*", "breadcrumb")
.RenameParameter("SentrySpan", "arg*", "span")
.RenameParameter("SentryLog", "arg*", "log")
.RenameParameter("SentryProfileOptions", "arg*", "options")
// Fix interface names
.RenameInterface("ISentrySerializable", "SentrySerializable")
.RenameInterface("ISentryRedactOptions", "SentryRedactOptions")
.RenameBaseType("ISentrySerializable", "SentrySerializable")
.RenameBaseType("ISentryRedactOptions", "SentryRedactOptions")
// Rename conflicting SentryRRWebEvent (protocol vs. interface)
.RenameProtocol("SentryRRWebEvent", "ISentryRRWebEvent")
// Adjust nullable return delegates (though broken until this is fixed: https://github.com/xamarin/xamarin-macios/issues/17109)
.WithAttribute("SentryBeforeBreadcrumbCallback", "return: NullAllowed")
.WithAttribute("SentryBeforeSendEventCallback", "return: NullAllowed")
.WithAttribute("SentryTracesSamplerCallback", "return: NullAllowed")
.RenameParameter("SentryObjCEvent", "arg*", "@event")
.RenameParameter("SentryObjCSamplingContext", "arg*", "samplingContext")
.RenameParameter("SentryObjCBreadcrumb", "arg*", "breadcrumb")
.RenameParameter("SentryObjCSpan", "arg*", "span")
// Fix nullable property attributes
.WithPropertyAttribute("SentryOptions", "OnCrashedLastRun", "NullAllowed")
.WithPropertyAttribute("SentryObjCOptions", "OnCrashedLastRun", "NullAllowed")
// Fix nullable generic type arguments
.ChangePropertyType("SentryOptions", "OnLastRunStatusDetermined", "Action<SentryLastRunStatus, SentryEvent?>")
// For PrivateApiDefinitions.cs
.WithModifier("SentryScope", "partial")
.ChangePropertyType("SentryObjCOptions", "OnLastRunStatusDetermined", "Action<SentryObjCLastRunStatus, SentryObjCEvent?>")
// error CS0246: The type or namespace name 'iOS' could not be found
.RemoveAttribute("iOS")
// error CS0246: The type or namespace name 'Mac' could not be found
Expand All @@ -96,92 +65,55 @@
.RemoveMethod("Sentry*", "IsEqual")
// error CS0246: The type or namespace name '_NSZone' could not be found
.RemoveMethod("Sentry*", "CopyWithZone")
// error CS0111: Type 'SentryAttribute' already defines a member called 'Constructor' with the same parameter types
.RemoveMethod("SentryLog", "SetAttribute")
// SentryLoggerDelegate and SentryCurrentDateProvider are not whitelisted
.RemoveMethod("SentryLogger", "Constructor")
// SentryAppStartMeasurement is not whitelisted
.RemoveDelegate("SentryOnAppStartMeasurementAvailable")
// unused
.RemoveDelegate("SentryUserFeedbackConfigurationBlock")
// error CS0114: 'SentryXxx.Description' hides inherited member 'NSObject.Description'.
.RemoveProperty("Sentry*", "Description")
// Minimize SentryDependencyContainer
.RemoveMethod("SentryDependencyContainer", "*")
.KeepProperties("SentryDependencyContainer", "SharedInstance", "DebugImageProvider")
// SentryUserFeedbackConfiguration is not whitelisted
.RemoveProperty("SentryOptions", "ConfigureUserFeedback")
.RemoveProperty("SentryOptions", "UserFeedbackConfiguration")
// SentryObjCSDK.internal is the entry point to the API for hybrid SDKs
// We only bind the `internal` accessor; every other SentryObjCSDK member references SentryObjC*
// types we don't whitelist.
.KeepProperties("SentryObjCSDK", "Internal")
.RemoveMethod("SentryObjCSDK", "*")
.KeepProperties("SentryObjCInternalApi", "Sdk", "Profiling")
// Option properties that reference SentryObjC* types the .NET SDK doesn't whitelist.
.RemoveProperty("SentryObjCOptions", "BeforeSendLog")
.RemoveProperty("SentryObjCOptions", "BeforeSendMetric")
.RemoveProperty("SentryObjCOptions", "ConfigureUserFeedback")
// SentryObjCSDK is both the public entry point and the hybrid-SDK gateway (via `internal`).
// Keep the public members the .NET SDK calls plus the `internal` accessor; drop the rest, whose
// signatures reference SentryObjC* types we don't whitelist.
.KeepMethods("SentryObjCSDK", "StartWithOptions", "ConfigureScope", "Crash")
.KeepProperties("SentryObjCSDK", "Internal", "CrashedLastRun")
// SentryObjCInternalApi: keep only the sub-APIs the .NET SDK uses (sdk, profiling, debug).
.KeepProperties("SentryObjCInternalApi", "Sdk", "Profiling", "Debug")
.KeepMethods("SentryObjCInternalApi", "SetTrace", "IgnoreNextSignal")
// Sharpie generates enums for types the SentryObjC headers reference, but the members that used
// them are trimmed above - drop the dead enums
.RemoveEnum("SentryObjC*")
.KeepInterfaces(
"ISentryRRWebEvent",
"SentryAttachment",
"SentryBaggage",
"SentryBreadcrumb",
"SentryClient",
"SentryDebugImageProvider",
"SentryDebugMeta",
"SentryDependencyContainer",
"SentryDsn",
"SentryEvent",
"SentryException",
"SentryExperimentalOptions",
"SentryFeedback",
"SentryFeedbackAPI",
"SentryFrame",
"SentryGeo",
"SentryHttpStatusCodeRange",
"SentryHub",
"SentryId",
"SentryLog",
"SentryLogger",
"SentryMeasurementUnit",
"SentryMeasurementUnitDuration",
"SentryMeasurementUnitFraction",
"SentryMeasurementUnitInformation",
"SentryMechanism",
"SentryMechanismContext",
"SentryMessage",
"SentryNSError",
"SentryObjCAttachment",
"SentryObjCBreadcrumb",
"SentryObjCDebugMeta",
"SentryObjCEvent",
"SentryObjCException",
"SentryObjCExperimentalOptions",
"SentryObjCFrame",
"SentryObjCGeo",
"SentryObjCHttpStatusCodeRange",
"SentryObjCId",
"SentryObjCInternalApi",
"SentryObjCInternalDebugApi",
"SentryObjCInternalProfilingApi",
"SentryObjCInternalSdkApi",
"SentryObjCMeasurementUnit",
"SentryObjCMechanism",
"SentryObjCMechanismContext",
"SentryObjCMessage",
"SentryObjCNSError",
"SentryObjCOptions",
"SentryObjCReplayOptions",
"SentryObjCRequest",
"SentryObjCSamplingContext",
"SentryObjCScope",
"SentryObjCSDK",
"SentryObjCSpan",
"SentryObjCSpanContext",
"SentryObjCSpanId",
"SentryOptions",
"SentryProfileOptions",
"SentryRedactOptions",
"SentryReplayApi",
"SentryReplayBreadcrumbConverter",
"SentryReplayOptions",
"SentryRequest",
"SentryRRWebEvent",
"SentrySamplingContext",
"SentryScope",
"SentryScreenFrames",
"SentrySDK",
"SentrySerializable",
"SentrySpan",
"SentrySpanContext",
"SentrySpanId",
"SentryStacktrace",
"SentryThread",
"SentryTraceContext",
"SentryTraceHeader",
"SentryTransactionContext",
"SentryUser",
"SentryViewScreenshotOptions",
"SentryViewScreenshotProvider"
"SentryObjCStacktrace",
"SentryObjCThread",
"SentryObjCTraceContext",
"SentryObjCTraceHeader",
"SentryObjCTransactionContext",
"SentryObjCUser"
)
// error CS0311: The type 'SentryXxx' cannot be used as type parameter 'TValue' in the generic type or method 'NSDictionary<TKey, TValue>'.
.ChangeGenericTypeArgument("NSDictionary", "Sentry*", "NSObject");
Expand Down
Loading
Loading