Is there any way for a binary target to declare dependencies so that any transitive dependencies needed by a downstream project are resolved?
If I understood correctly, binary
only states the way the package is going to be deployed/consumed. So the transitive dependencies should be declared, normally, in your Package.swift
. When you add the library dependency to your project, Xcode detects all transitive dependencies, download them and pack them. So just add to your package file your dependency, just like:
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/DeclarativeHub/Bond.git", .upToNextMajor(from: "7.4.1"))
]
I have the same question here.
How do we authenticate ourselves when trying to consume a binary dependency stored in an artefact repository other than Github? Is authentication unsupported for "external" binaries?
I guess it depends what authentication we are talking about. I haven't tested it, but a basic auth embedded in the URL should work.
Thanks for the quick reply David. I my case (using Artifactory) I think URL based authentication is not supported on their side. I've noticed there is a PR opened to add netrc support to Swift tools, which would definitely solve my problem. I'll wait for that. For anyone interested: Add support for Netrc for Downloader by sstadelman · Pull Request #88 · apple/swift-tools-support-core · GitHub
If I understood correctly,
binary
only states the way the package is going to be deployed/consumed. So the transitive dependencies should be declared, normally, in yourPackage.swift
. When you add the library dependency to your project, Xcode detects all transitive dependencies, download them and pack them. So just add to your package file your dependency, just like:dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/DeclarativeHub/Bond.git", .upToNextMajor(from: "7.4.1")) ]
@khose and all, I believe my issue is directly related to this question, so I will reply instead of posting a new question. I have specified my dependencies as you mentioned in the manifest file for my binary framework. Even so, when I import my Swift package in to a new project, the modules in the dependencies are not found. Only when I manually add each dependency as a Swift Package in the new project can I successfully build. At this point, however, when I run the app, I get warnings of duplicate definitions for those modules I manually added. Example of one of those warnings:
objc[556]: Class _TtCC9Alamofire17MultipartFormData8BodyPart is implemented in both /private/var/containers/Bundle/Application/BDC359F9-519E-476F-94BF-9F94736B1B66/MyApp.app/Frameworks/MyFramework.framework/MyFramework (0x10578cd08) and /private/var/containers/Bundle/Application/BDC359F9-519E-476F-94BF-9F94736B1B66/MyApp.app/MyApp (0x1050ed3a0). One of the two will be used. Which one is undefined.
Is this a bug or am I misunderstanding how to define my package manifest file?
My manifest file:
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyFramework",
platforms: [
.iOS(.v9)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MyFramework",
targets: ["MyFramework"])
],
dependencies: [
.package(name: "Alamofire", url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "4.8.2")),
...
],
targets: [
.binaryTarget(
name: "MyFramework",
path: "./Sources/MyFramework.xcframework")
]
)
Any help is appreciated! TIA