Add xcframework as Swift Package dependency with SSH - swift

When i try to add my xcframework as a swift package dependency through ssh URL, Xcode give me error
Showing All Messages
x-swift-package-repository-authentication://?scm=com.apple.dt.Xcode.sourcecontrol.Git&url=git#ghe.somegiturl.git#error=-1005 Authentication failed because the credentials were missing
I can clone this repo through same ssh URL through source tree, it works fine. Package.manifest file below
let package = Package(
name: "Test",
platforms: [
.iOS(.v12)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Test",
targets: ["Test"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.binaryTarget(
name: "Test",
path: "Test.xcframework"
),
.testTarget(
name: "TestTests",
dependencies: ["Test"]),
]
)

Related

Conditional dependency for target in SwiftPM

I have a custom swift package I am building that has as one of its dependencies a package (Bugfender) that is an xcframework and is iOS only (and Mac Catalyst). Understandably, when I try to compile this package in Xcode (12.5) I get an error that a mac library for that package cannot be found (all iOS specific code is wrapped in a #if os(iOS) block).
Based on this (https://github.com/apple/swift-evolution/blob/master/proposals/0273-swiftpm-conditional-target-dependencies.md) addition to the Swift package spec, I thought I could use a condition to exclude the dependency for mac, but when I try the following Swift.package file, I still get the same error when building for mac. Is this a bug or am I doing something wrong? It seems like it should work based on this post as well (Swift package manager: How best to indicate platform dependent code?)
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "GTSApplicationLogging",
platforms: [
.iOS(.v12), .macOS(.v10_13),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "GTSApplicationLogging",
targets: ["GTSApplicationLogging"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "BugfenderPackage", url: "https://github.com/bugfender/BugfenderSDK-iOS", .exact("1.10.2")),
.package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .exact("1.9.5")),
.package(url: "https://github.com/marmelroy/Zip.git", .exact("2.1.1")),
.package(path: "../GTSPureAppleExtensions"),
.package(path: "../GTSApplicationError"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "GTSApplicationLogging",
dependencies: ["SwiftyBeaver", "GTSPureAppleExtensions", "GTSApplicationError", "Zip", .product(name: "BugfenderLibrary", package: "BugfenderPackage", condition: .when(platforms: [.iOS]))]),
.testTarget(
name: "GTSApplicationLoggingTests",
dependencies: ["GTSApplicationLogging", "GTSApplicationError"]),
])

Sharing code across test targets when using the Swift Package Manager

I have some code that I need to share across test targets, while I'm using the Swift Package Manager. To do this, I have a .testTarget that I also name as a dependency in another .testTarget.
Here is a simple example:
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ExampleLib",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ExampleLib",
targets: ["ExampleLib"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ExampleLib",
dependencies: []),
.testTarget(
name: "Common",
dependencies: ["ExampleLib"]),
.testTarget(
name: "ExampleLibTests",
dependencies: ["Common"]),
]
)
If I try to build this package in Xcode, I get the following error:
Unable to resolve build file: XCBCore.BuildFile (The workspace has a reference to a missing target with GUID 'PACKAGE-TARGET:Common')
However, if I build from the command line (swift build) or test from the command line (swift test), I get success.
I'm using Xcode 12 beta 6, but have also tried Xcode 11.5 (with a change to the Package.swift header) and get the same results.
Here is the complete Swift package example:
https://www.dropbox.com/s/h6ypvbfonnb2zyk/ExampleLib.zip?dl=0
I really would like to use this in Xcode to build for iOS. Thoughts?
I faced the same issue and solved it by defining a Target (not Test Target) instead for Common.
My Package.swift file:
// ...
.target(name: "Common", dependencies: ["App"], path: "Tests/Common"),
.testTarget(name: "AppTests", dependencies: ["App", "Common"]),
.testTarget(name: "IntegrationTests", dependencies: ["App", "Common"])
// ...

How to add a .framework as dependency to a swift package in Xcode?

I want to know if there is anyway to link a swift package against a framework like SQLite.framework in Xcode? I'm trying to make a swift package for a sqlite library wrapper.
Here is my current swift package manifest:
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SQLiteDB",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SQLiteDB",
targets: ["SQLiteDB"]),
],
dependencies: [
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SQLiteDB",
dependencies: []),
.testTarget(
name: "SQLiteDBTests",
dependencies: ["SQLiteDB"]),
]
)
I ended up creating my own Sqlite package by embedding the amalgamation sources of sqlite. This gives you the ability to have any arbitrary version of Sqlite in your apps.
With the Xcode 12 beta, you can do this if you update your swift-tools-version to 5.3, and then add a binaryTarget to your package's targets:
.binaryTarget(
name: "Stripe",
url: "https://github.com/stripe/stripe-ios/releases/download/v19.3.0/Stripe.xcframework.zip",
checksum: "fe459dd443beee5140018388fd6933e09b8787d5b473ec9c2234d75ff0d968bd"
)

How to you import a 3rd party framework as a dependency using Swift Package Manager?

I'm trying to create a project using Swift Package Manager, but I'm running into issues trying to include the Fabric.framework.
Here is my Package.swift
let package = Package(
name: "TestPackage",
platforms: [
.iOS(.v10), .macOS(.v10_12)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "TestPackage",
targets: ["TestPackageSwift", "TestPackageObjC"]),
],
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.8.2"),
.package(path: "./TestPackage/Libraries/Fabric.framework"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "TestPackageSwift",
dependencies: ["Alamofire", "Fabric"],
path:"./TestPackage/Sources/Swift"),
.target(
name: "TestPackageObjC",
dependencies: ["Fabric"],
path:"./TestPackage/Sources/ObjC"),
.testTarget(
name: "TestPackageTests",
dependencies: ["TestPackageSwift", "TestPackageObjC"],
path:"./TestPackageTests/Sources"),
]
)
And here is the error I am getting:
error: ./TestPackage/Libraries/Fabric.framework has no Package.swift manifest
Is this even possible?
Thanks for the help!

How to specify the name of the output executable?

By default the SPM builds the executable target with the same name (uppercase) as the module folder containing its main.swift. How do I get it to build the binary with a different file name? I cannot find any instructions on the SPM manual.
With Swift 4, given DemoProject created with swift package init --type executable, make the changes to Package.swift (adding the products section).
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "DemoProject",
products: [
.executable(name: "demo", targets: ["DemoProject"]),
],
dependencies: [],
targets: [
.target(
name: "DemoProject",
dependencies: []),
]
)
This will create an executable called demo.
Change executable name
In SPM 5.4, You can set executable name in products.
.executable(name: "ExecutableName", targets: ["ExecutableTargetName"])
Build the executable product directly
and if you want to build the executable directly, try command swift build --product ExecutableName
also you can get where the build result located with --show-bin-path parameter
for example swift build --product ExecutableName --show-bin-path
Demo Package.swift
// swift-tools-version:5.4
import PackageDescription
let package = Package(
name: "PackageName",
platforms: [
.iOS(.v11),
.macOS(.v10_15),
],
products: [
.library(name: "LibraryName", targets: ["LibraryTarget"]),
.executable(name: "ExecutableName", targets: ["ExecutableTargetName"])
],
dependencies: [...],
targets: [
.target(
name: "LibraryTarget",
dependencies: [...],
path: "Sources/..."
),
.executableTarget(
name: "ExecutableTargetName",
dependencies: [...],
path: "Sources/..."
),
]
)
I am in favor of using another build system, for example make, on top of swift build. Currently, swift build does not allow defining custom "hooks" to implement various build automation tasks - generating code, copying resources, deploying the executable, etc. Once you use make you can define whichever tasks you desire, in particular, renaming the binary.