aws-amplify / aws-sdk-ios-spm

This repository enables Swift Package Manager support for the AWS Mobile SDK for iOS
Apache License 2.0
29 stars 15 forks source link

It doesn't seem possible to use this package as a dependency of another #115

Closed valentary closed 5 months ago

valentary commented 6 months ago

I was trying to separate out a component of ours into it's own swift package. This component manages uploads to our cloud service and relies on aws-sdk-ios-spm package.

In my app, the AWS package works just fine, but once I packaged all my code, and tried to add the AWS package as a dependency, I could not make it work, the dependency package would download, but there seemed no way to add it to any target. I would get errors similar to

"product AWSiOSSDKV2 required by package aws-sdk-test-package target aws-sdk-test-target not found"

I tried various different targets, products strings etc from what I could find in the AWS package file, but nothing would work

It can be recreated with any simple package structure, a default XCode created one works to replicate the issue, here is my swift.package file

// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "aws-sdk-test-package",
    platforms: [
        .iOS(.v15)
    ],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "aws-sdk-test-package",
            targets: ["aws-sdk-test-package"]),
    ],
    dependencies: [
        .package(url: "https://github.com/aws-amplify/aws-sdk-ios-spm.git", from: .init(2, 34, 0))
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "aws-sdk-test-package",
        dependencies: [
            // Things that didn't work
            "AWSiOSSDKV2",
            // "aws-sdk-ios-spm",
            // "AWSCore",
            // .product(name: "AWSCore"),
            // .target(name: "AWSCore")
        ]
        ),
        .testTarget(
            name: "aws-sdk-test-packageTests",
            dependencies: ["aws-sdk-test-package"]),
    ]
)
ruisebas commented 6 months ago

Hi @valentary! Thanks for opening this issue.

To add a product from this package as a dependency, you'll need to set both its name and its package:

dependencies: [
    .product(name: [Product Name], package: "aws-sdk-ios-spm")
]

So your package file would look like this:

let package = Package(
    name: "aws-sdk-test-package",
    platforms: [
        .iOS(.v15)
    ],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "aws-sdk-test-package",
            targets: ["aws-sdk-test-package"]),
    ],
    dependencies: [
        .package(url: "https://github.com/aws-amplify/aws-sdk-ios-spm.git", from: .init(2, 34, 0))
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "aws-sdk-test-package",
            dependencies: [
                .product(name: "AWSCore", package: "aws-sdk-ios-spm")
                // + other products your package uses, .e.g "AWSS3", "AWSPinpoint", etc
            ]
        ),
        .testTarget(
            name: "aws-sdk-test-packageTests",
            dependencies: ["aws-sdk-test-package"]),
    ]
)
valentary commented 5 months ago

Thanks!

github-actions[bot] commented 5 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.