Skip to content
Merged
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
Binary file removed Flutter.xcframework.zip
Binary file not shown.
32 changes: 10 additions & 22 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,17 @@ func tryGuessSwiftRoot() -> String {
}

let SwiftRoot = EnvSysRoot ?? tryGuessSwiftRoot()
var FlutterPlatform: String
var FlutterPlatform: String = ""
var FlutterUnsafeLinkerFlags: [String] = []

#if os(macOS) // Note: This is the _build_ platform
// platformSwiftSettings += []
// On Darwin (macOS/iOS), Flutter.framework / FlutterMacOS.framework is provided
// by the consumer Xcode project (via $(FRAMEWORK_SEARCH_PATHS) populated by
// Flutter's xcode_backend.sh / macos_assemble.sh build phases). FlutterSwift
// therefore declares no Darwin framework dependency at the package level;
// `swift build` outside of Xcode will compile the codecs but `canImport` will
// hide the Messenger.

let FlutterRoot = "/opt/flutter"
let _FlutterLibPath = "\(FlutterRoot)/bin/cache/artifacts/engine"

FlutterPlatform = "darwin-x64"
let FlutterFramework = "FlutterMacOS"
let FlutterLibPath = "\(_FlutterLibPath)/\(FlutterPlatform)"
FlutterUnsafeLinkerFlags = [
"-Xlinker", "-F", "-Xlinker", FlutterLibPath,
"-Xlinker", "-rpath", "-Xlinker", FlutterLibPath,
"-Xlinker", "-framework", "-Xlinker", FlutterFramework,
]
#elseif os(Linux)
#if os(Linux)
// FIXME: this is clearly not right
let FlutterRoot = ".build/artifacts/flutterswift/CFlutterEngine/flutter-engine.artifactbundle"
#if arch(arm64)
Expand Down Expand Up @@ -526,15 +519,14 @@ let package = Package(
name: "FlutterSwift",
dependencies: [
.target(name: "CxxFlutterSwift", condition: .when(platforms: [.linux])),
.target(name: "Flutter", condition: .when(platforms: [.iOS])),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "Atomics", package: "swift-atomics"),
"AsyncExtensions",
] + targetDependencies,
cxxSettings: platformCxxSettings,
swiftSettings: platformSwiftSettings,
linkerSettings: [
.unsafeFlags(FlutterUnsafeLinkerFlags, .when(platforms: [.macOS, .linux])),
.unsafeFlags(FlutterUnsafeLinkerFlags, .when(platforms: [.linux])),
]
),
.testTarget(
Expand All @@ -545,13 +537,9 @@ let package = Package(
cxxSettings: platformCxxSettings,
swiftSettings: platformSwiftSettings,
linkerSettings: [
.unsafeFlags(FlutterUnsafeLinkerFlags, .when(platforms: [.macOS, .linux])),
.unsafeFlags(FlutterUnsafeLinkerFlags, .when(platforms: [.linux])),
]
),
.binaryTarget(
name: "Flutter",
path: "Flutter.xcframework.zip"
),
] + targets,
cLanguageStandard: .c17,
cxxLanguageStandard: .cxx17
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ The following assumes a reasonable degree of familiarity both with Flutter (spec

On mobile and desktop platforms such as macOS, iOS and Android, the `FlutterPlatformMessenger` class wraps the platform's existing [binary messenger](https://api.flutter.dev/flutter/services/BinaryMessenger-class.html). This is due to the platform binary messenger not being replaceable, as it is used by host platform plugins.

On Darwin platforms (that is, iOS and macOS), you can simply add FlutterSwift as a Swift package dependency from Xcode. On Android, you will need to link FlutterSwift into a Java Native Interface (JNI) library that is bundled with your APK (more of which below).
On Darwin platforms (that is, iOS and macOS), you can simply add FlutterSwift as a Swift package dependency from Xcode. `Flutter.framework` / `FlutterMacOS.framework` is provided by your Flutter project's own xcconfig (via `xcode_backend.sh` / `macos_assemble.sh`), so FlutterSwift declares no Darwin framework dependency at the package level and ships no bundled Flutter binaries — the same mechanism Flutter's SwiftPM-aware plugins (e.g. `url_launcher_macos`) use. Note that standalone `swift build` on Darwin therefore compiles only the codecs; `FlutterPlatformMessenger` is `#if canImport`'d out unless built inside an Xcode project that wires up Flutter.

On Android, you will need to link FlutterSwift into a Java Native Interface (JNI) library that is bundled with your APK (more of which below).

### Embedded platforms

Expand Down
Loading