Error: Could not build CSQLiteMac in Vapor - swift

My Package.swift looks like this -
import PackageDescription
let package = Package(
name: "Hello",
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 2),
.Package(url: "https://github.com/vapor/sqlite-provider.git", majorVersion: 1, minor: 1)
],
exclude: [
"Config",
"Database",
"Localization",
"Public",
"Resources",
"Tests",
]
)
And my main.swift looks like this -
import Vapor
let drop = Droplet()
drop.get("/version") { request in
do{
let version = try drop.database?.driver.raw("SELECT sqlite_version()")
return try JSON(node: version)
} catch {
return "Sorry"
}
}
drop.resource("posts", PostController())
drop.run()
And my sqlite.json looks like this -
{
"path": "/Users/nikhil.manapure/Desktop/Helo/newDB"
}
And my error looks like -
Please help me with using sqlite3 with Vapor.

If you haven't already, you need to install the headers for SQLite on your Mac.
brew install sqlite3 assuming you have installed Homebrew.

Related

Using SPM with multiple targets causes casting issues

I've created an SPM package that has two targets. The second target uses the first one as a dependency.
Here is how it's description looks like:
let package = Package(
name: "MyPackage",
platforms: [.iOS(.v15)],
products: [
.library(
name: "MyPackage",
targets: ["MyPackage"]),
.library(
name: "MyPackage2",
targets: ["MyPackage2"])
],
dependencies: [
.package(name: "A", path: "../A"),
.package(name: "B", path: "../B"),
.package(name: "C", path: "../C"),
.package(name: "D", path: "../D"),
.package(name: "E", path: "../E"),
.package(name: "F", path: "../F")
],
targets: [
.target(
name: "MyPackage",
dependencies: [
"A",
"B",
"C",
"D",
"E",
"F"
],
resources: [
.process("Resources")
]
),
.testTarget(
name: "MyPackageTests",
dependencies: [
"MyPackage"
]
),
.target(
name: "MyPackage2",
dependencies: [
"MyPackage"
],
resources: [
.process("Resources")
]
)
]
)
When I try to load a nib in the first target (the nib location is in the first target) it fails to cast it as itself.
This is the code I use to load the nib:
public final class func loadFrom(_ bundle: Bundle) -> Self {
let nibName = String(describing: self)
return bundle.loadNibNamed(nibName, owner: nil, options: nil)?.first as! Self
}
Please note that the loading of the nib doesn't fail. If I print the following line I get the correct result:
bundle.loadNibNamed(nibName, owner: nil, options: nil)?.first
But it actually fails on as! Self
This is the error message:
Could not cast value of type 'X' (0x1109e0c98) to 'X' (0x103db62e8).
This issue started happening after adding the second target, but i'm not sure what am I doing wrong here? Anyone has any idea?

SPM "Bundle format unrecognized, invalid, or unsuitable"

I'm preparing the SPM package, with resources folder. When I compile it for device, it work ok and I got successful. But when I try to build to simulator, I got error: ... bundle format unrecognized, invalid, or unsuitable
What can be wrong?
Tried to make Resource folder empty - no result.
Package.swift
defaults variants with delete DerivenData - no result.
let package = Package(
name: "GPUVideo",
platforms: [
.macOS(.v10_13), .iOS(.v13),
],
products: [
.library(
name: "GPUVideo",
targets: ["GPUVideo"]),
],
dependencies: [
],
targets: [
.target(
name: "GPUVideo",
dependencies: [],
exclude: ["Metal"],
resources: [
.copy("Resources")
])
]
)
Solved by change: .copy on .process
resources: [
.process("Resources")
])
It is unclear to me why its helps

SPM artifact not found for target 'AAA' - Xcode 13.3 only

I have SDK that installed with SPM. It works as expected from Xcode 13.2 but on Xcode 13.3 I got this error.
import PackageDescription
let package = Package(
name: "AAA",
products: [
.library(
name: "AAA",
targets: ["AAA"]),
],
dependencies: [
],
targets: [
.binaryTarget(
name: "AAA",
path: "artifacts/BBB.xcframework"
),
.testTarget(
name: "AAATests",
dependencies: ["AAA"]),
]
The artifact name has to match the target name (This is a new Xcode 13.3 thing).
Since your artifact name is BBB.xcframework, the example below should work for you:
let package = Package(
name: "BBB",
products: [
.library(
name: "BBB",
targets: ["BBB"]),
],
dependencies: [
],
targets: [
.binaryTarget(
name: "BBB",
path: "artifacts/BBB.xcframework"
),
]
)
In my case, the only way to solve this was by downloading earlier Xcode version (13.2) from https://developer.apple.com/download/all/

Swift Package Manager not assigning dependencies

I am trying to create a package for iOS using Swift Package Manager.
I have a Package.swift that looks like this -
import PackageDescription
let package = Package(
name: "MyPackage",
platforms: [.iOS(.v12)],
products: [
.library(name: "MyPackage", targets: ["MyPackage"]),
],
dependencies: [
.package(url: "https://github.com/yannickl/AwaitKit", from: "5.0.0"),
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", from: "4.0.0"),
.package(url: "https://github.com/OAuthSwift/OAuthSwift", from: "2.0.0")
],
targets: [
.target(name: "MyPackage", dependencies: []),
.testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]),
]
)
But my project does not build, my classes that reference these dependencies say they do not exist and I also get a warning in Xcode that there are no targets using these dependencies.
I tried to update targets as follows -
targets: [
.target(name: "MyPackage", dependencies: ["AwaitKit","KeychainAccess","OAuthSwift"]),
.testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]),
]
But this made no difference?

Swift backend with perfct framwork

Hi i am learning Swift perfect backend i am stuck how to add mongodb dependencies in my project, If someone know how to do please help me
import PackageDescription
let package = Package(
name: "SwiftBackend",
products: [
.library(name: "PerfectMongoDB", targets: ["PerfectMongoDB"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
.package(url: "https://github.com/PerfectSideRepos/Perfect-CMongo.git", from: "0.0.0"),
.package(url: "https://github.com/PerfectSideRepos/Perfect-CBSON.git", from: "0.0.0"),
.package(url: "https://github.com/PerfectlySoft/PerfectLib.git", from: "3.0.0")
],
targets: [
.target(
name: "SwiftBackend",
dependencies: ["PerfectHTTPServer" , "PerfectLib" , "PerfectMongoDB"]),
]
)
please follow this instruction to add dependencies to your Swift project:
create a blank folder with your project name.
Inside this folder, use swift package init --type=executable to initialize the Package.swift automatically:
In your case, it looks like this:
$ mkdir SwiftBackend && cd SwiftBackend && swift package init --type=executable
modify the dependencies. Should be like this:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "SwiftBackend",
dependencies: [
.package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
.package(url: "https://github.com/PerfectlySoft/Perfect-MongoDB.git", from: "3.0.0"),
],
targets: [
.target(
name: "SwiftBackend",
dependencies: ["PerfectHTTPServer", "PerfectMongoDB"]),
]
)
there may be some warnings but should work without any issues.
i found the ans its `import PackageDescription
let package = Package(
name: "SwiftBackend",
products: [
.library(name: "PerfectMongoDB", targets: ["SwiftBackend"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
.package(url: "https://github.com/PerfectlySoft/Perfect-MongoDB.git", from: "0.0.0"),
.package(url: "https://github.com/PerfectlySoft/PerfectLib.git", from: "3.0.0")
],
targets: [
.target(
name: "SwiftBackend",
dependencies: ["PerfectHTTPServer" , "PerfectLib" , "MongoDB"]),
]
)`