Approach to PkgConfg in SwiftPM

Hi guys,
I'm having problems trying to get my .pc file to work with SwiftPM. I have to set the flags manually for swift build to work.

I decided to download the sources for SwiftPM to try and find the problem. However, I was under the impression that it used pkg-config under the hood to resolve the flags and everything. But rather it's parsing the .pc file.

So I just wanted to ask if this is the current designated approach for this? Since I found a comment in that file that says that the parser is there just so it can be tested?

// FIXME: This is only internal so it can be unit tested.
//
/// Parser for the `pkg-config` `.pc` file format.
///
/// See: https://www.freedesktop.org/wiki/Software/pkg-config/
struct PkgConfigParser {
}

If the parser is here to stay, should it be cleared out in the source so it's not confusing?
OR... should we leverage pkg-config instead of having the parser?

Thanks!

1 Like

You've misread the comment. The comment indicates that the PkgConfigParser has internal visibility so that it can be unit tested (i.e. imported from xctest via @testable import). If it did not need to be tested, it would presumably be declared private instead.

Otherwise, I think this is similar to the issue that caused SR-6317, where SwiftPM parses package config files differently to the way pkg-config does. I proposed to defer to pkg-config on systems where that binary is installed, but the issue has since stalled. @Aciid may have opinions here.

2 Likes