Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Managed layer initializes native SDK on iOS #1915

Merged
merged 45 commits into from
Dec 4, 2024

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Nov 22, 2024

iOS: Cocoa SDK Initialization

Overview

Implements the late initialization of the Cocoa SDK. This allows users to apply code changes to the options and for those options to apply to the native layer. Related issue: sentry-unity#1907

Implementation Details

The SDK now always includes the Cocoa SDK in the generated Xcode project with the following changes:

  1. New Native Support Option
  • Added an enum IosNativeInitializationType to the SentryOptions. This allows users to switch between Runtime and BuildTime initialization and defaults to Runtime.
  • The IosNativeSupportEnabled controls whether the SDK should add native support. This helps i.e. in the case of UaaL where users want to completely disabled the SDK from modifying the Xcode project. We still need to add the NoOpBridge due to the built-in P/Invoke declarations in SentryCocoaBridgeProxy.
  1. Native Bridge Updates

    • The iOS bridge now matches the macOS bridge (except Load() as )
    • Cocoa options now get generated at runtime
    • The Unity SDK can now initialize the Cocoa SDK through the bridge
  2. Build Process Changes

    • SentryOptions.mm generation is now controlled by IosNativeInitializationType enum
    • main.mm Init generation is now controlled by IosNativeInitializationType enum
    • Note: We still add the framework as before: Linking it with the binary and embedding it in the surrounding app. In case of late init, we could embed it in the UnityFramework but looking at supporting UaaL where the Cocoa SDK would be present outside the framework as well, this would cause conflicts.
  3. Runtime Behavior

    • SentryNativeCocoa.Configure checks whether the native SDK was already initialized
    • Both early and late initialization are going through the same code paths

Pending Tasks

  • RuntimeInitialization is default. This means we're missing testing BuildTime in CI right now.
    • "Init Native First" flow
    • "Init Native Late" flow
    • Note: Requires duplicate mobile smoke testing (2x build, compile, test)

Copy link
Contributor

github-actions bot commented Nov 22, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 7d4756e

@bitsandfoxes bitsandfoxes marked this pull request as ready for review November 27, 2024 18:39
@bitsandfoxes bitsandfoxes requested review from vaind and bruno-garcia and removed request for vaind November 27, 2024 18:39
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added CI complexity was something I didn't realize at first. Challenging without the other step in CI (duping it all) is it easy thing to do?

@@ -2,6 +2,10 @@

## Unreleased

### API Changes

- The native layer on iOS no longer self-initializes before the Unity game starts. Instead, it accepts the options at the end of the configure call. To restore the old behavior, users can opt-in to initializing native first via `IosInitializeNativeFirst`. Note that using this option comes with the limitation of baking the options into the generated Xcode project at build-time. ([#1915](https://github.com/getsentry/sentry-unity/pull/1915))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that using this option comes with the limitation of baking the options into the generated Xcode project at build-time.

Would be nice to link to the docs on this topic since it's quite complex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will follow!

@bitsandfoxes bitsandfoxes merged commit 2c6293a into main Dec 4, 2024
94 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/ios-init-cocoa branch December 4, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants