Cannot add SwiftCalendar as a dependency in vapor3 project via package manager - swift

I am currently trying to add SwiftDate to a Vapor3 project via the swift package manager. Here is my package file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "timeshare",
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
// Custom dependencies
.package(url: "https://github.com/malcommac/SwiftDate.git", from: "5.0.0"),
],
targets: [
.target(name: "App", dependencies: ["Vapor", "SwiftDate"]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"]),
]
)
However, when I try to build my project I get 82 issues in Xcode (all from the SwiftCalendar module). For example this:
I have no idea how I can possible have caused errors in a third party library. Any input is highly appreciated.
Thanks
More errors can be seen here:
PS: Sorry for including screenshots, I know they might be hard to read, but I could not find a way to copy the error list as text.

The project isn’t in the correct format for SPM. All the files need to be declared in the correct target directory, but DateRepresentable is outside of that https://github.com/malcommac/SwiftDate/tree/master/Sources
It’s also worth noting that this doesn’t seem to have any tests on Linux and involves DateManipulation. I’d be very weary about using it since Dates on Linux are notoriously crashy

Related

Swift Package Manager add only selected library

// swift-tools-version:5.5
import PackageDescription
let package = Package(
name: "PKG",
platforms: [.iOS(.v15)],
products: [
.library(name: "Lib1", targets: ["Lib1"]),
.library(name: "Lib2", targets: ["Lib2"]),
.library(name: "Lib3", targets: ["Lib3"]),
],
dependencies: [
],
targets: [
.target(name: "Lib1", dependencies: []),
.target(name: "Lib2", dependencies: []),
.target(name: "Lib3", dependencies: []),
]
)
I'm creating a package with multiple products, I uploaded it to github to use it in SPM in my project,
It's letting me select the libraries I want to add to my project which is what I want, but no matter what I select it bring all the libraries and it's files to my project is this how it works? or can I make it download only the selected libraries and it's dependencies only?
thank you
Unfortunately, SPM will always download the complete repository containing the package/sub-package. You can try out that behaviour at any major library with several products, such as firebase (also note that supporting code such as demo applications and tests will be included in the download as well).
For more information, please see this discussion at swift.org.
The workaround is to split your library into several repositories or use another dependency manager, such as cocoapods which fully supports that feature.
In SPM or swift package manager you can install any libraries that you want for example in install Fire base you may do not need to another libraries, because this framework has a lot libraries.
I use SPM also :)

How to create an SPM package based on ObjC code?

I'd like to create a SwiftPackageManager library based on Objective-C code but I can't seem to grasp what I'm missing.
My latest change to just vanilla ObjC interface .h file inside the include folder was to add an extra C header that includes de ObjC but still had no success. What am I missing?
The Package.swift file is the default generated one and from what I read it should automatically generate the module map from the include folder.
My swift-tools-version is 5.5
Figured it out.
I added a modulemap that specifies my ObjC header and it worked
Not sure if it is the correct way to do it since the include folder should already do this automatically.
So just had the same issue. (my 5 cent)
This is may Package.swift:
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "AlgorithmSDK",
platforms: [
.iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages. , "AlgorithmSDKObjc"
.library(
name: "AlgorithmSDK",
targets: ["AlgorithmSDK","AlgorithmSDKObjc" ]),
],
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: "AlgorithmSDK",
dependencies: []),
.testTarget(
name: "AlgorithmSDKTests",
dependencies: ["AlgorithmSDK"]),
.target(
name: "AlgorithmSDKObjc",
dependencies: [],
publicHeadersPath:"include"),//<----- This path is relative to the target! (and can be ignored)
]
)
With the structure:
The publicHeadersPath should be publicHeadersPath:"include" OR ignored according to docs (it seems that it takes it relative to target and not the root). I don't think we should touch module.modulemap for such a simple structure

Module Not Found for Swift Package referenced by another Swift Package

We have two swift packages that we've created. One has some bare bones swift code and the second has some Swift UI code. When we create a Swift UI application, it can see classes from either of the swift packages. However, we can't get the Swift UI package to see code from the other bare bones swift code package.
Both of the packages are being hosted on github. In the Swift UI package, we added a package dependency to package.swift like this:
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/myorg/myswiftpackage", from: "1.0.1")
],
When we try to use the classes from myswiftpackage, we get a "Module Not Found" error on the import statement.
What are we missing that allows a package to use code from another package?
Thanks Joakim, that was the answer. We had only listed it in the dependencies list, but both the targets also needed to have the package name listed as a dependency. Here's an example both references in case anyone needs it.
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/myorg/myswiftpackage", from: "1.0.1")
],
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: "MySwiftUiPackage",
dependencies: ["MySwiftPackage"]),
.testTarget(
name: "MySwiftUiPackageTests",
dependencies: ["MySwiftUiPackage", "MySwiftPackage"]),
]

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"])
// ...