On Linux (Debian), I've cloned a project for using SQLite with Swift.
In trying to learn Swift Package Manager a little better, I created a new folder & library package as per the instructions here. All good so far.
When it came time to compile, I cannot figure out how the original Package.swift
works though.
Granted, it does have a #if os(Linux)
as part of the Package.swift
, but I can't figure out how to collapse it into one. Do I need to?
The first posting is for the original file :
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "SQLite.swift",
products: [.library(name: "SQLite", targets: ["SQLite"])],
targets: [
.target(name: "SQLite", dependencies: ["SQLiteObjc"]),
.target(name: "SQLiteObjc"),
.testTarget(name: "SQLiteTests", dependencies: ["SQLite"], path: "Tests/SQLiteTests")
],
swiftLanguageVersions: [4]
)
#if os(Linux)
package.dependencies = [.package(url: "https://github.com/stephencelis/CSQLite.git", from: "0.0.3")]
package.targets = [
.target(name: "SQLite", exclude: ["Extensions/FTS4.swift", "Extensions/FTS5.swift"]),
.testTarget(name: "SQLiteTests", dependencies: ["SQLite"], path: "Tests/SQLiteTests", exclude: [
"FTS4Tests.swift",
"FTS5Tests.swift"
])
]
#endif
This was then updated to work with my new package folder ... this also compiles ... as it adheres to keeping the second "package.targets"
statement.
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "SwiftSQLite",
products: [ .library( name: "SwiftSQLite", targets: [ "SwiftSQLite" ] ) ],
dependencies:
[
.package(url: "/tmp/shared0/source/CSQLite", from: "0.0.3")
],
targets:
[
.target(name: "SQLiteObjc"),
.target(name: "SwiftSQLite", dependencies: ["SQLiteObjc"], exclude: ["Extensions/FTS4.swift", "Extensions/FTS5.swift"] ),
.testTarget(name: "SQLiteTests", dependencies: ["SwiftSQLite"], path: "Tests/SwiftSQLiteTests")
]
)
package.targets =
[
.target(name: "SwiftSQLite", exclude: ["Extensions/FTS4.swift", "Extensions/FTS5.swift"] )
]
But in trying to eliminate the second "package.targets"
into the main "let package = Package()"
statement, it fails and complains about the bridging header in SQLiteObjc.
If you look at the second package.targets
statement, it is essentially a duplicate of the first without a dependency on the Objc stuff.
For those of you who visual things differently like I do, here is yet another working version of the Package.swift file ..
// swift-tools-version:5.0
import PackageDescription
let package = Package( name: "SwiftSQLite")
package.targets = [ .target(name: "SQLiteObjc"), .target(name: "SwiftSQLite", dependencies: ["SQLiteObjc"]) ]
package.targets = [ .target(name: "SwiftSQLite", exclude: ["Extensions/FTS4.swift", "Extensions/FTS5.swift"]) ]
package.products = [ .library( name: "SwiftSQLite", targets: [ "SwiftSQLite" ]) ]
package.dependencies = [ .package(url: "/tmp/shared0/source/CSQLite", from: "0.0.3") ]
My question boils down to:
a) why does it take two goes at [ .target(name: "SwiftSQLite"]
to make compilation work?
b) how does package.targets = []
, immediately followed by package.targets = []
work?
Any insight as to why two "package.targets"
statements can work together versus just one would be greatly appreciated, as it implies .target(name: "SwiftSQLite")
is in the overall package statement twice?