How to wrap C-library into SwiftPackage to use in my project?

1 week ago 13
ARTICLE AD BOX

I created test project - "TaoTester" and test package with C-library called "SwiftGit2".

After few days of work in package almost all works fine....

EXCEPT: I cannot link C-libraries files into the package using related paths.
It's work fine with absolute path's:

// swift-tools-version: 6.0 import PackageDescription let package = Package( name: "SwiftGit2", platforms: [ .macOS(.v12) ], products: [ .library( name: "SwiftGit2", targets: ["SwiftGit2"] ) ], dependencies: [ .package(url: "https://github.com/apple/swift-collections.git", exact: "1.3.0"), .package(url: "https://github.com/pointfreeco/swift-parsing.git", exact: "0.10.0"), // -------- .package(url: "https://github.com/Quick/Nimble.git", exact: "8.1.2"), .package(url: "https://github.com/Quick/Quick.git", exact: "2.2.1"), ], targets: [ .target( name: "Clibgit2", path: "Sources/Clibgit2", publicHeadersPath: "include", cSettings: [ .headerSearchPath("include") ], linkerSettings: [ .unsafeFlags([ "/Users/User/TaoGitRepos_Empty/TestSG2/SwiftGit2P/Sources/Clibgit2/libgit2.a", "/Users/User/TaoGitRepos_Empty/TestSG2/SwiftGit2P/Sources/Clibgit2/libssh2.a", "/Users/User/TaoGitRepos_Empty/TestSG2/SwiftGit2P/Sources/Clibgit2/libssl.a", "/Users/User/TaoGitRepos_Empty/TestSG2/SwiftGit2P/Sources/Clibgit2/libcrypto.a", ]), .linkedLibrary("z"), // zlib .linkedLibrary("iconv"), // iconv ] ), .target( name: "SwiftGit2", dependencies: [ "Clibgit2", .product(name: "Collections", package: "swift-collections"), .product(name: "Parsing", package: "swift-parsing"), ] ), .testTarget( name: "SwiftGit2Tests", dependencies: [ "SwiftGit2", .product(name: "Quick", package: "Quick"), .product(name: "Nimble", package: "Nimble") ] ) ] )

But doesn't work with relative paths:

.unsafeFlags([ "Sources/Clibgit2/libgit2.a", "Sources/Clibgit2/libssh2.a", "Sources/Clibgit2/libssl.a", "Sources/Clibgit2/libcrypto.a", ]),

My Package have the following structure:

Xcode files structure

I have tried a lot of things but this is best solution that I have at the moment.
But still - absolute path to library is not good enough solution for me as project must be compiled on lot of computers.

Does anyone know how to use package with relative paths to attach "a"-library files?

Read Entire Article