diff --git a/.github/workflows/sample-application.yml b/.github/workflows/sample-application.yml index 5d5a687904..647719c9a9 100644 --- a/.github/workflows/sample-application.yml +++ b/.github/workflows/sample-application.yml @@ -43,7 +43,7 @@ jobs: caller_ref: ${{ github.ref }} build-ios: - name: Build ${{ matrix.rn-architecture }} ios ${{ matrix.build-type }} ${{ matrix.ios-use-frameworks }} + name: Build ${{ matrix.rn-architecture }} ios ${{ matrix.build-type }} ${{ matrix.ios-use-frameworks }} ${{ matrix.sentry-consumption }} runs-on: macos-26-xlarge needs: [diff_check, detect-changes] if: >- @@ -60,6 +60,15 @@ jobs: rn-architecture: ["new"] ios-use-frameworks: ["no-frameworks"] build-type: ["dev", "production"] + sentry-consumption: ["spm"] + # SPM is the default consumption path for sentry-cocoa on RN >= 0.75. + # Keep a single CocoaPods job to catch regressions in the fallback path + # used by older React Native versions. + include: + - rn-architecture: "new" + ios-use-frameworks: "no-frameworks" + build-type: "production" + sentry-consumption: "cocoapods" steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 @@ -95,6 +104,7 @@ jobs: [[ "${{ matrix.build-type }}" == "production" ]] && export ENABLE_PROD=1 || export ENABLE_PROD=0 [[ "${{ matrix.rn-architecture }}" == "new" ]] && export ENABLE_NEW_ARCH=1 || export ENABLE_NEW_ARCH=0 [[ "${{ matrix.ios-use-frameworks }}" == "dynamic-frameworks" ]] && export USE_FRAMEWORKS=dynamic + [[ "${{ matrix.sentry-consumption }}" == "cocoapods" ]] && export SENTRY_USE_SPM=0 ./scripts/pod-install.sh @@ -112,7 +122,9 @@ jobs: ./scripts/build-ios.sh - name: Archive iOS App - if: ${{ matrix.rn-architecture == 'new' && matrix.build-type == 'production' && matrix.ios-use-frameworks == 'no-frameworks' }} + # Only upload from the SPM job (the default consumption path) to avoid + # duplicate artifact names when the CocoaPods regression job runs. + if: ${{ matrix.rn-architecture == 'new' && matrix.build-type == 'production' && matrix.ios-use-frameworks == 'no-frameworks' && matrix.sentry-consumption == 'spm' }} working-directory: ${{ env.REACT_NATIVE_SAMPLE_PATH }} run: | zip -r \ @@ -120,7 +132,7 @@ jobs: sentryreactnativesample.app - name: Upload iOS APP - if: ${{ matrix.rn-architecture == 'new' && matrix.build-type == 'production' && matrix.ios-use-frameworks == 'no-frameworks' }} + if: ${{ matrix.rn-architecture == 'new' && matrix.build-type == 'production' && matrix.ios-use-frameworks == 'no-frameworks' && matrix.sentry-consumption == 'spm' }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: name: sample-rn-${{ matrix.rn-architecture }}-${{ matrix.build-type }}-${{ matrix.ios-use-frameworks}}-ios @@ -131,7 +143,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: - name: build-sample-${{ matrix.rn-architecture }}-ios-${{ matrix.build-type }}-${{ matrix.ios-use-frameworks}}-logs + name: build-sample-${{ matrix.rn-architecture }}-ios-${{ matrix.build-type }}-${{ matrix.ios-use-frameworks}}-${{ matrix.sentry-consumption }}-logs path: ${{ env.REACT_NATIVE_SAMPLE_PATH }}/ios/*.log build-android: diff --git a/CHANGELOG.md b/CHANGELOG.md index 37243643ca..ca01437b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,11 @@ ### Changes - Default `mobileReplayIntegration({ networkCaptureBodies })` to `true`, matching the iOS and Android native SDK defaults ([#6372](https://github.com/getsentry/sentry-react-native/pull/6372)) +- Consume `sentry-cocoa` via Swift Package Manager by default on React Native >= 0.75 ([#6381](https://github.com/getsentry/sentry-react-native/pull/6381)) + + **Warning** + + **This may be a breaking change for some setups.** On RN 0.75+, `pod install` now pulls Sentry as a pre-built binary xcframework, instead of building Sentry from source as a CocoaPod. If your iOS build breaks after upgrading (e.g. when another pod also depends on the `Sentry` CocoaPod), set `SENTRY_USE_SPM=0` before `pod install` to restore the previous behavior. On older React Native versions the SPM helper is unavailable and RNSentry transparently falls back to the CocoaPods source build. Use `SENTRY_USE_SPM=1` to require SPM. ### Fixes diff --git a/packages/core/RNSentry.podspec b/packages/core/RNSentry.podspec index ea38efc95b..63763c1124 100644 --- a/packages/core/RNSentry.podspec +++ b/packages/core/RNSentry.podspec @@ -56,20 +56,30 @@ Pod::Spec.new do |s| sentry_cocoa_version = '9.19.0' - # Opt-in to consuming sentry-cocoa via Swift Package Manager. - # When `SENTRY_USE_SPM=1` is set, RNSentry pulls `Sentry` from the - # sentry-cocoa SPM package as a binary xcframework instead of from - # the Sentry CocoaPods source build. Defaults to CocoaPods consumption - # for backward compatibility with the full RN version range we support. + # Consume sentry-cocoa via Swift Package Manager by default. # - # Requires React Native >= 0.75 because the SPM helper - # (`react-native/scripts/cocoapods/spm.rb`) is loaded transitively from - # the Podfile via `react_native_pods.rb`. - if ENV['SENTRY_USE_SPM'] == '1' - unless defined?(SPM) && SPM.respond_to?(:dependency) + # On React Native >= 0.75, RNSentry pulls `Sentry` from the sentry-cocoa SPM + # package (a pre-built binary xcframework). On older RN, the SPM helper + # (`react-native/scripts/cocoapods/spm.rb`) is not available and we + # transparently fall back to the Sentry CocoaPods source build. + # + # Override the choice with the `SENTRY_USE_SPM` environment variable: + # * `SENTRY_USE_SPM=0` — force CocoaPods consumption even on RN >= 0.75. + # * `SENTRY_USE_SPM=1` — force SPM (errors if the helper is unavailable). + spm_helper_available = defined?(SPM) && SPM.respond_to?(:dependency) + env_use_spm = ENV['SENTRY_USE_SPM'] + use_spm = case env_use_spm + when '1' then true + when '0' then false + else supports_spm(rn_version) && spm_helper_available + end + + if use_spm + unless spm_helper_available raise 'SENTRY_USE_SPM=1 is set but the SPM helper is not loaded. ' \ - 'This requires React Native >= 0.75 and a Podfile that imports ' \ - 'react_native_pods.rb.' + 'This requires React Native >= 0.75 and a Podfile that loads ' \ + '`react_native_pods.rb`. Either upgrade React Native, or set ' \ + 'SENTRY_USE_SPM=0 to fall back to the Sentry CocoaPods build.' end SPM.dependency(s, url: 'https://github.com/getsentry/sentry-cocoa', diff --git a/packages/core/scripts/sentry_utils.rb b/packages/core/scripts/sentry_utils.rb index 5dc57a3b52..36d1bc0da0 100644 --- a/packages/core/scripts/sentry_utils.rb +++ b/packages/core/scripts/sentry_utils.rb @@ -40,3 +40,12 @@ def should_use_folly_flags(rn_version) def is_new_hermes_runtime(rn_version) return (rn_version[:major] >= 1 || (rn_version[:major] == 0 && rn_version[:minor] >= 81)) end + +# React Native >= 0.75 transitively loads `react-native/scripts/cocoapods/spm.rb` +# via `react_native_pods.rb`, which exposes the `SPM` helper that the RNSentry +# podspec uses to pull `sentry-cocoa` as a Swift Package binary xcframework. +# Below 0.75 the helper is unavailable and we fall back to consuming Sentry as +# a regular CocoaPods source build. +def supports_spm(rn_version) + return (rn_version[:major] >= 1 || (rn_version[:major] == 0 && rn_version[:minor] >= 75)) +end diff --git a/scripts/clang-format.sh b/scripts/clang-format.sh index 6a642f4215..b9e94c77d1 100755 --- a/scripts/clang-format.sh +++ b/scripts/clang-format.sh @@ -64,6 +64,7 @@ cmd="find . -type f \( \ -path \"**android/build/**\" -or \ -path \"**.cxx/**\" -or \ -path \"**build/generated/**\" -or \ + -path \"**/DerivedData/**\" -or \ -path \"**/Carthage/Checkouts/*\" -or \ -path \"**/libs/**\" -or \ -path \"**/.yalc/**\" -or \