/usr/lib:/usr/local/lib is not always a sufficient -L search path
/usr/include:/usr/local/include is not always a sufficient -I C compiler search path
Installing the system library is left up to the end-user to figure out
The solution involves use of a tool called pkg-config which can be used to ask a system module about its -I search paths and -L flags and most system modules already conform to pkg-config however it does make swiftpm dependent on it for system modules.
Lets try to do this and make a simple Gtk window.
Create a package called CGtk with two files Package.swift and module.modulemap
This is a normal modulemap wrapper package for a system module with two extra things in Package().
pkgConfig - is the name of system module which has to be used while querying pkg-config, the proposal suggested to parse modulemap and infer name from link but looks like they won’t always match.
providers - is an array of enum which will suggest system packagers to use depending upon the system in case the system module is not installed.
These variables have to be added in Package class of PackageDescription module:
Since manifest files is loaded, dumped to TOML and then reconverted back to swift, these should be made TOML convertible.
Also, need to update fromTOML().swift in ManifestParser module to parse the TOML representation.
Now, lets create a class called PkgConfig that will wrap the pkg-config’s functionality. It’ll throw error if pkg-config or the system package is not installed.
We need to display the right provider help in case system module is not installed. Create an extension in Build module which would take array of the provider enums and try to figure out the provider for current platform.
Only thing left is asking PkgConfig what flags to add for each CModule which defined a pkgConfig name and append those flags in build params.