Skip to content

[SwiftPM Add2App] Copy plugins and add FlutterFramework dependency #181207

@vashworth

Description

@vashworth

Design

When building for SwiftPM add2app, the plugins that support SwiftPM should be copied from pubcache to the --output directory, under a Plugins subdirectory.

├── FlutterPluginRegistrant
├── Plugins
│   ├── plugin_a
│   ├── plugin_b
...

If a plugin does not have a dependency on the FlutterFramework, it should add it. For example, if the plugin's Package.swift looks like this:

let package = Package(
    name: "plugin_a",
    products: [
        .library(name: "plugin-a", targets: ["plugin_a"]),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "plugin_a",
            dependencies: [
                .target(name: "plugin_a_helper"),
            ]
        ),
        .target(
            name: "plugin_a_helper",
            dependencies: []
        ),
    ]
)

You can run the following commands to update the Package.swift

  • swift package add-dependency ../FlutterFramework --type path
  • swift package add-target-dependency FlutterFramework plugin_a --package FlutterFramework
  • swift package add-target-dependency FlutterFramework plugin_a_helper --package FlutterFramework

The resulting Package.swift would looked like:

let package = Package(
    name: "plugin_a",
    products: [
        .library(name: "plugin-a", targets: ["plugin_a"]),
    ],
    dependencies: [
        .package(name: "FlutterFramework", path: "../FlutterFramework")
    ],
    targets: [
        .target(
            name: "plugin_a",
            dependencies: [
                .target(name: "plugin_a_helper"),
                .product(name: "FlutterFramework", package: "FlutterFramework")
            ]
        ),
        .target(
            name: "plugin_a_helper",
            dependencies: [
                .product(name: "FlutterFramework", package: "FlutterFramework")
            ]
        ),
    ]
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listcustomer: castawayteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions