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

SPM Support #2280

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
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
27 changes: 27 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,33 @@ jobs:
;;
esac

spm:
name: "SPM"
runs-on: macos-15
timeout-minutes: 30
defaults:
run:
shell: bash
working-directory: flutter/example
strategy:
fail-fast: false
matrix:
target: [ios, macos]

steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # [email protected]
with:
channel: main
- run: flutter upgrade
- run: flutter config --enable-swift-package-manager
- name: Run on iOS
if: matrix.target == 'ios'
run: flutter run -d "iPhone 16 Pro"
- name: Run on macOS
if: matrix.target == 'macos'
run: flutter run -d "macOS"

analyze:
uses: ./.github/workflows/analyze.yml
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
);
```

- SPM Support ([#2280](https://github.com/getsentry/sentry-dart/pull/2280))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 🚫 The changelog entry seems to be part of an already released section ## 8.11.0.
    Consider moving the entry to the ## Unreleased section, please.


### Enhancements

- Avoid sending too many empty client reports when Http Transport is used ([#2380](https://github.com/getsentry/sentry-dart/pull/2380))
Expand Down
4 changes: 4 additions & 0 deletions flutter/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ build/
.cxx/

.vscode/launch.json
cocoa_bindings_temp

ios/sentry_flutter/Package.resolved

temp
6 changes: 5 additions & 1 deletion flutter/ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ Icon?
.tags*

/Flutter/Generated.xcconfig
/Flutter/flutter_export_environment.sh
/Flutter/flutter_export_environment.sh

.build
.swiftpm
Package.resolved
Empty file removed flutter/ios/Assets/.gitkeep
Empty file.
10 changes: 0 additions & 10 deletions flutter/ios/Classes/SentryFlutterPlugin.h

This file was deleted.

15 changes: 0 additions & 15 deletions flutter/ios/Classes/SentryFlutterPlugin.m

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flutter/ios/sentry_flutter/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "sentry_flutter",
platforms: [
.iOS("12.0"),
.macOS("10.13")
],
products: [
.library(name: "sentry-flutter", targets: ["sentry_flutter", "sentry_flutter_objc"])
],
dependencies: [
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.40.1")
],
targets: [
.target(
name: "sentry_flutter",
dependencies: [
"sentry_flutter_objc",
.product(name: "Sentry", package: "sentry-cocoa")
]
),
// SPM does not support mixed-language targets, so we need to move the ObjC files into a separate one
.target(
name: "sentry_flutter_objc",
dependencies: [
.product(name: "Sentry", package: "sentry-cocoa")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Sentry

#if SWIFT_PACKAGE
import Sentry._Hybrid
import sentry_flutter_objc
#endif

#if os(iOS)
import Flutter
import UIKit
Expand All @@ -11,7 +17,7 @@ import CoreVideo
// swiftlint:disable file_length function_body_length

// swiftlint:disable:next type_body_length
public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
public class SentryFlutterPlugin: NSObject, FlutterPlugin {
private let channel: FlutterMethodChannel

private static let nativeClientName = "sentry.cocoa.flutter"
Expand Down Expand Up @@ -39,7 +45,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
let channel = FlutterMethodChannel(name: "sentry_flutter", binaryMessenger: registrar.messenger)
#endif

let instance = SentryFlutterPluginApple(channel: channel)
let instance = SentryFlutterPlugin(channel: channel)
instance.registerObserver()
registrar.addMethodCallDelegate(instance, channel: channel)
}
Expand Down Expand Up @@ -323,7 +329,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
}

let version = PrivateSentrySDKOnly.getSdkVersionString()
PrivateSentrySDKOnly.setSdkName(SentryFlutterPluginApple.nativeClientName, andVersionString: version)
PrivateSentrySDKOnly.setSdkName(SentryFlutterPlugin.nativeClientName, andVersionString: version)

// note : for now, in sentry-cocoa, beforeSend is not called before captureEnvelope
options.beforeSend = { event in
Expand Down Expand Up @@ -364,9 +370,9 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {

#if canImport(UIKit) && !SENTRY_NO_UIKIT
#if os(iOS) || os(tvOS)
let breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter()
let screenshotProvider = SentryFlutterReplayScreenshotProvider(channel: self.channel)
PrivateSentrySDKOnly.configureSessionReplay(with: breadcrumbConverter, screenshotProvider: screenshotProvider)
let breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter()
let screenshotProvider = SentryFlutterReplayScreenshotProvider(channel: self.channel)
PrivateSentrySDKOnly.configureSessionReplay(with: breadcrumbConverter, screenshotProvider: screenshotProvider)
#endif
#endif

Expand All @@ -385,7 +391,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
if isValidSdk(sdk: sdk) {

switch sdk["name"] as? String {
case SentryFlutterPluginApple.nativeClientName:
case SentryFlutterPlugin.nativeClientName:
#if os(OSX)
let origin = "mac"
#elseif os(watchOS)
Expand Down Expand Up @@ -500,7 +506,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
let isColdStart = appStartMeasurement.type == .cold

let item: [String: Any] = [
"pluginRegistrationTime": SentryFlutterPluginApple.pluginRegistrationTime,
"pluginRegistrationTime": SentryFlutterPlugin.pluginRegistrationTime,
"appStartTime": appStartTime,
"isColdStart": isColdStart,
"nativeSpanTimes": nativeSpanTimes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#import "SentryFlutterReplayBreadcrumbConverter.h"
#import "include/SentryFlutterReplayBreadcrumbConverter.h"

@import Sentry;

#if SWIFT_PACKAGE
@import Sentry._Hybrid;
#endif

#if SENTRY_TARGET_REPLAY_SUPPORTED

@implementation SentryFlutterReplayBreadcrumbConverter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import Sentry;

#if SWIFT_PACKAGE
@import Sentry._Hybrid;
#endif

#if SENTRY_TARGET_REPLAY_SUPPORTED
#import "SentryFlutterReplayScreenshotProvider.h"
#import <Flutter/Flutter.h>
Expand Down
1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutter.swift

This file was deleted.

1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutterPlugin.h

This file was deleted.

1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutterPlugin.m

This file was deleted.

1 change: 0 additions & 1 deletion flutter/macos/Classes/SentryFlutterPluginApple.swift

This file was deleted.

1 change: 1 addition & 0 deletions flutter/macos/sentry_flutter/Package.swift
Loading