PerfectSwift: swift package update runs endlessly - perfect

I do have an older Perfect Swift project where my package.swift looks the following:
// Generated automatically by Perfect Assistant Application
// Date: 2017-09-24 18:44:24 +0000
import PackageDescription
let package = Package(
name: "SomeName",
targets: [],
dependencies: [
.Package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", majorVersion: 2),
.Package(url: "https://github.com/PerfectlySoft/Perfect-LocalAuthentication-MySQL.git", majorVersion: 1),
.Package(url: "https://github.com/PerfectlySoft/Perfect-CURL.git", majorVersion: 2),
.Package(url: "https://github.com/SwiftORM/StORM.git", majorVersion: 3),
.Package(url: "https://github.com/PerfectlySoft/Perfect-MySQL.git", majorVersion: 3),
.Package(url: "https://github.com/PerfectlySoft/Perfect-SMTP.git", majorVersion: 1),
.Package(url: "https://github.com/PerfectlySoft/Perfect-RequestLogger.git", majorVersion: 1)
]
)
when I run swift package build I get the following output and then the machine hangs for hours:
Updating https://github.com/PerfectlySoft/Perfect-HTTPServer.git
Updating https://github.com/PerfectlySoft/Perfect-LocalAuthentication-MySQL.git
Updating https://github.com/PerfectlySoft/Perfect-CURL.git
Updating https://github.com/PerfectlySoft/Perfect-RequestLogger.git
Updating https://github.com/SwiftORM/StORM.git
Updating https://github.com/PerfectlySoft/Perfect-MySQL.git
Updating https://github.com/PerfectlySoft/Perfect-SMTP.git
Updating https://github.com/PerfectlySoft/Perfect-Net.git
Updating https://github.com/PerfectlySoft/Perfect-HTTP.git
Updating https://github.com/PerfectlySoft/Perfect-Thread.git
Updating https://github.com/PerfectlySoft/Perfect-LinuxBridge.git
Updating https://github.com/PerfectlySoft/Perfect-Crypto.git
Updating https://github.com/PerfectlySoft/PerfectLib.git
Updating https://github.com/PerfectlySoft/Perfect-COpenSSL-Linux.git
Updating https://github.com/SwiftORM/MySQL-StORM.git
Updating https://github.com/PerfectlySoft/Perfect-Mustache.git
Updating https://github.com/iamjono/JSONConfig.git
Updating https://github.com/PerfectlySoft/Perfect-Session-MySQL.git
Updating https://github.com/iamjono/SwiftRandom.git
Updating https://github.com/PerfectlySoft/Perfect-Logger.git
Updating https://github.com/iamjono/SwiftMoment.git
Updating https://github.com/PerfectlySoft/Perfect-libcurl.git
What can I do to make this run again? swift --version gets
Swift version 4.2.1-dev (LLVM 4ba03d9389, Clang 78aa734eee, Swift f4134ebef6)
Target: x86_64-unknown-linux-gnu

Try .package(url: "package_url", from: "version") instead.

Have you tried updating everything, including Perfect itself? Consider that your older project was written under a different version of Swift, the dependencies may have had breaking changes since then, and the older version of the dependencies probably didn't support the new version yet.
After doing this, try getting Perfect to regenerate the Package.swift, since another user pointed out that syntax has changed.

Related

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"]),
]

Swift Package Compiler Issue

I have a Project has 4 Swift Package Dependencies. Package A, B, C, D. Each package uses the previous packages as dependencies.
I'm facing an issue where Package D is having issues compiling due to do errors inside Package B that don't actually exist. (Cannot find type 'CustomType' in scope) As Package B and the xcode project I'm using the packages in both work fine.
This is preventing me from working efficiently because the complier wont work inside Package D.
I've tried deleting derived data, cleaning the build folder, reseting package cache and none of this has worked. I'm assuming I'm doing something wrong, but I have no idea what it is.
let package = Package(
name: "PackageD",
defaultLocalization: "en",
platforms: [
.iOS(.v13),
.macOS(.v10_15)
],
products: [
.library(
name: "PackageD",
targets: ["PackageD"]),
],
dependencies: [
.package(url: "PackageA", "0.0.1"..<"1.0.0"),
.package(url: "PackageB", "0.0.1"..<"1.0.0"),
.package(url: "PackageC", "0.0.1"..<"1.0.0"),
],
targets: [
.target(
name: "PackageD",
dependencies: [
"PackageA",
"PackageB",
"PackageC"
],
resources: [.process("Resources")]
),
]
)
It looks like there were a few different structs that required the use of UIKit. Which mean that UIKit needed to be able to be imported. Which wasn't an issue in the xcode project, but was an issue in the package that was built upon other packages.
Adding #if canImport(UIKit) and #endif to all the files that required it solved the issue.

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

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

Add Alamofire as dependency through Swift 3 package manager

Swift 3 introduced package manager, with which I can add dependencies to my project.
For example, in my Package.swift , I can declare my dependency by:
import PackageDescription
let package = Package(
name: "my-project",
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 0, minor: 16),
]
)
Now, I need to add Alamofire to my project, how can I get it through Swift 3 package manager?
You can't use Alamofire yet because they haven't released Swift 3 support.
Once they've released this, I'm sure they will make it obvious on their GitHub readme how to import it.
Luckily Vapor comes with a great HTTP and even WebSockets client. Read more about the HTTP client in the documentation: https://vapor.github.io/documentation/http/client.html
Well, today you just have to add the following line in your Package.swift file:
.Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 4)
Really easy :)

Using Alamofire in a command line OS X app (Xcode 7) - code encapsulation?

I'm trying to figure out how to use Alamofire in a command line app.
I can't use frameworks, so I've added the Alamofire source code into the app (so no import statement) and I'm able to directly reference the request() and other methods.
Is there a cleaner way to encapsulate Alamofire or is this a limitation in Swift 2.X at the moment?
For those who gonna need it here is the solution.
If you don't have the file xcodeproject please generate
$ swift package generate-xcodeproj
You may need to fix the Deployment Target
Now time to add the Alamofire
import PackageDescription
let package = Package(
name: "SuiteTest",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0")
],
targets: [
.target(
name: "SuiteTest",
dependencies: ["Files", "Alamofire"]),
.testTarget(
name: "ASuiteTestTests",
dependencies: ["Assure-SuiteTest"]),
]
)
I hope I have helped anyone who has the same problem :)