Skip to content

feat(macos): add Swift Package Manager support - #1

Open
tadelv wants to merge 1 commit into
AurelienBallier:mainfrom
tadelv:main
Open

feat(macos): add Swift Package Manager support#1
tadelv wants to merge 1 commit into
AurelienBallier:mainfrom
tadelv:main

Conversation

@tadelv

@tadelv tadelv commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Flutter 3.44 enables Swift Package Manager by default. This adds a Package.swift for macOS so the plugin resolves natively via SPM, while keeping full CocoaPods compatibility (dual support, as required by the Flutter plugin migration guide).

Changes

  • Restructure macOS sources into macos/flutter_libserialport/Sources/ per the Flutter SPM plugin layout; the podspec is re-pointed at the new path so CocoaPods integration keeps working.
  • Add a libserialport C target compiled from copies of third_party/libserialport (SPM targets cannot reference files outside the package directory) with a configure-generated macOS config.h — mirroring the vendored-config approach the android/linux/windows CMake builds already use.
  • Ship the product as type: .dynamic: dart:ffi needs a loadable binary for the sp_* symbols, and LGPL libserialport should remain a separate, replaceable dynamic library.
  • FlutterLibserialportPlugin keeps pointing LIBSERIALPORT_PATH at the CocoaPods libserialport.framework when present, and falls back to its own framework binary under SPM (the C target is linked into the plugin's dynamic framework).
  • Example: commit Flutter's at-build-time SPM migration of the Runner project, and await SerialPort.availablePorts (async since the usb_serial changes).

Verification

  • Example app builds and runs with SPM enabled: the embedded flutter-libserialport.framework exports 80 sp_* symbols, port enumeration works.
  • Example app builds with CocoaPods (flutter config --no-enable-swift-package-manager) from a pristine Runner project.
  • A consumer app using the git-dependency shape builds green on macOS with SPM.

🤖 Generated with Claude Code

Flutter 3.44 defaults to SPM; reaprime keeps SPM enabled on macOS, so
the plugin needs a Package.swift (same migration as tadelv/dart_js
c7cde7b for flutter_js).

- restructure macos sources into macos/flutter_libserialport/Sources/
  per the Flutter SPM plugin layout; podspec updated so CocoaPods
  integration keeps working (dual support)
- add a libserialport C target compiled from copies of
  third_party/libserialport (SPM targets cannot reference files outside
  the package directory) with a configure-generated macOS config.h,
  mirroring the vendored-config approach of the android/linux/windows
  builds
- ship the product as type .dynamic: dart:ffi needs a loadable binary
  for the sp_* symbols, and LGPL libserialport must stay a replaceable
  dynamic library
- FlutterLibserialportPlugin now falls back to its own framework binary
  for LIBSERIALPORT_PATH when the CocoaPods libserialport.framework is
  absent (the C target lives inside the plugin framework under SPM)
- example: commit Flutter's at-build-time SPM migration of the Runner
  project, and await SerialPort.availablePorts (async since the
  usb_serial fork changes)

Verified: example builds and runs with SPM (framework exports 80 sp_*
symbols, port enumeration clean) and builds with CocoaPods after
restoring a pristine Runner project.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant