[swift-users] System Modules and pkgConfig
Etan Kissling
etan at scriptreactor.com
Wed Dec 28 10:12:57 CST 2016
Hi,
before Swift 3, for System Modules to work, these steps were necessary:
1. Creating module map
2. Creating System Module package
3. Creating git repo for System Module package, tagging with version
4. Referencing the System Module package from main package
5. Adding -Xcc -I and -Xlinker -L flags to the swift build command.
The problem here is, that absolute system-depending paths are required at:
- module map "header" entry.
- Xcc -I flag when building.
- Xlinker -L flag when building.
To solve this, Swift 3 introduced support for System Module search paths:
https://github.com/apple/swift-evolution/blob/master/proposals/0063-swiftpm-system-module-search-paths.md
In my case, I end up with the following for the System Module package:
module CFoo [system] {
header "/system/depending/path/to/my/header.h"
link "foo"
export *
}
import PackageDescription
let package = Package(
name: "CFoo",
pkgConfig: "foo",
providers: [
.Brew("foo")
]
)
With this setup, I can run
PKG_CONFIG_PATH=/system/depending/path/to/my/pc/file swift build
and build the project without specifying custom Xcc -I / Xlinker -L flags.
However, the absolute system-depending path is still required in the modulemap.
When I change the module map to
module CFoo [system] {
header "header.h"
link "foo"
export *
}
, I get build errors like
/module.modulemap:2:##: error: header 'header.h' not found
This is kind of different than what is suggested by the proposal (that it should recommend installing via Brew / Apt in that case).
==> How do I need to set up the project so that system-depending paths are required at no point?
==> Is there an example project available on github that demonstrates the pkgConfig feature of SwiftPM?
Thanks
Etan
More information about the swift-users
mailing list