Skip to content

fix(macos): Keep the player's code signature valid with Sentry's native binaries - #2953

Draft
bitsandfoxes wants to merge 4 commits into
mainfrom
spire/unity-macos-signing
Draft

bitsandfoxes wants to merge 4 commits into
mainfrom
spire/unity-macos-signing

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A macOS player built with native support breaks its own code signature. Sentry copies its macOS binaries into the app after Unity has built and signed it: Sentry.dylib for Cocoa, and libsentry-native.dylib plus sentry-crash for native. codesign --verify then fails on the app, and on Apple Silicon the universal dylib's x86_64 slice is left unsigned. "Create Xcode Project" exports are missing the binaries altogether, because the copy never reaches the Xcode project, so the Cocoa bridge logs dlopen() failed at runtime.

How

The user chooses the macOS backend in the Sentry options, as before. Unity now places and signs Sentry's files along with the rest of the app, so both a direct build and an Xcode export come out with a valid signature and the chosen backend's files inside.

Diagram

Diagram source
flowchart LR
    B{macOS native support on?} -- no --> N[No Sentry binaries in the app]
    B -- yes --> C{Backend}
    C -- Cocoa --> D[Sentry.dylib in PlugIns]
    C -- Native --> E[libsentry-native.dylib and SentryCrash.bundle in PlugIns]
    D --> S([Unity or Xcode signs the app: signature valid]):::good
    E --> S
    N --> S
  • Plugins:
    • Sentry's macOS binaries are ordinary plugins enabled for OSXUniversal only: Plugins/macOS/Sentry/Sentry.dylib, Plugins/macOS/SentryNative/libsentry-native.dylib and Plugins/macOS/SentryNative/SentryCrash.bundle.
    • An include-in-build delegate (PluginImporter.SetIncludeInBuildDelegate) excludes the files of the backend that isn't selected, and all of them when macOS native support is off.
    • The dSYMs stay in the tilde folders, and the dSYM upload is unchanged.
  • The crash daemon:
    • sentry-crash ships as the executable of SentryCrash.bundle.
    • When NativeHandlerPath is empty, the SDK points sentry-native at Contents/PlugIns/SentryCrash.bundle/Contents/MacOS/sentry-crash, or at the same path next to the executable on a dedicated server. A path the user set is never overwritten.
  • Before the build:
    • When building into an existing .app, the other backend's files and the files earlier SDK versions copied in (MacOS/sentry-crash, PlugIns/libsentry.dylib) are removed before Unity signs the app.
    • The build fails with a message naming the file when the selected backend's binaries are missing.
    • The bundled sentry-crash is made executable before Unity copies it.
  • The macOS post-build copy is removed. Windows and Linux are unchanged.
  • SDK build: the macOS binaries and the bundle are ad-hoc signed, so every architecture slice carries a signature.
  • CI signing (scripts/sign-macos-binaries.sh):
    • On main and release/*, build.yml runs the script. It signs the macOS binaries for notarization with rcodesign 0.29.0 (checksum-pinned), verifies them and notarizes them. Signing on main too means an expired certificate or a rejected binary shows up before release day. Pull requests never sign, so they never see the certificate.
    • It uses the APPLE_CERT_DATA, APPLE_CERT_PASSWORD and APPLE_API_KEY secrets, passed from ci.yml. The job fails with an error naming each secret that is missing.
    • rcodesign reads the certificate, its password and the API key only from files. They are written under umask 077 into a private temp directory, which is removed when the script exits, whether it succeeds or fails. The password never goes on the command line.
    • Notarization waits at most 15 minutes (--max-wait-seconds), and the step has a 30-minute timeout.
  • CI checks:
    • test-build-macos.yml runs codesign --verify --deep --strict --all-architectures after each macOS build.
    • It also checks that the app holds only the selected backend's files, including the native build made over the Cocoa app.
    • The macOS SDK artifacts no longer carry .meta files.
    • The native SDK's cache key covers the committed macOS plugin settings.
  • Sample builds: scripts/build-sample.ps1 writes the unity build provenance file next to the build output instead of inside the .app, where it broke the signature.

Caveats

  • Signing and notarization run for the first time on the first main build after this merges. The Apple secrets have to be repository Actions secrets, not only environment secrets, since the build job has no environment.
  • Exporting into an existing Xcode project in append mode, after switching backends, can leave the other backend's files in that project folder. Replace mode and direct builds start clean.
  • The cache-key change in sdk.yml overlaps with ci: key the native SDK caches on their own inputs and skip the workload restore #2909.

Fixes #2950

Unity places Sentry.dylib, libsentry-native.dylib and SentryCrash.bundle
in the app before it signs it, so the app's signature stays valid and
Create Xcode Project exports include them. Only the selected backend's
files ship. Release CI signs and notarizes the binaries with rcodesign.

Fixes #2950
…in metas out of SDK artifacts

The macOS pre-build fails with a BuildFailedException naming the missing
file and the command that restores it, and warns when a plugin's importer
isn't found. The macOS SDK artifacts leave out .meta files, and the
MacOSNative cache key hashes the committed macOS files. The handler path
tests build their expectation from the production relative path.
@bitsandfoxes
bitsandfoxes force-pushed the spire/unity-macos-signing branch from ff49a32 to d7bc8e6 Compare November 25, 2026 14:33
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.

macOS native post-build step invalidates Unity’s app signature

1 participant