swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.66k stars 1.31k forks source link

[SR-12937] [Regression][5.2][macOS] SwiftPM can not properly get pkg-config libs and C flags for some libraries #4537

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12937
Radar None
Original Reporter PALKOVNIK (JIRA User)
Type Bug

Attachment: Download

Environment OS: macOS 10.15.5 Xcode 11.4/11.5
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 93258efbe2740a983119fe6423c1ea6f

Issue Description:

Most of the dev libraries installed via homebrew provide pkg-config configuration files which swift package manager is able to locate and parse in order to get needed linking libraries and C flags to pass to compiler for "system library" targets.
Up till swift 5.1.x shipped with Xcode 11.3.x this worked perfectly fine. Starting from swift 5.2.x shipped with Xcode 11.4 and newer the parser fails to get the needed flags.
One example is the library called "pango".
It can be installed via homebrew (pango has hard dependency on glib):
```
brew install pango glib
```
After that you can inspect that pkg-config file located at `/usr/local/lib/pkgconfig/pango.pc`
I've added a sample project that adds the pango C module. Hit `swift build -v` and you can easily the the error on newer swift vesions:

swift-ci commented 4 years ago

Comment by Max Liberman (JIRA)

I'm running into this issue as well, in my case with the cairo library. It looks like the problem in both cases is that the gobject-2.0 library's .pc file has an absolute path in its Requires.private field, which SPM does not currently support.

$ cat $(brew --prefix)/opt/glib/lib/pkgconfig/gobject-2.0.pc
prefix=/usr/local/Cellar/glib/2.64.3
libdir=${prefix}/lib
includedir=${prefix}/include

Name: GObject
Description: GLib Type, Object, Parameter and Signal Library
Version: 2.64.3
Requires: glib-2.0
Requires.private: /usr/local/opt/libffi/lib/pkgconfig/libffi.pc >=  3.0.0
Libs: -L${libdir} -lgobject-2.0
Libs.private: -lintl
Cflags:-I${includedir}
swift-ci commented 4 years ago

Comment by Max Liberman (JIRA)

I opened a PR here.

swift-ci commented 4 years ago

Comment by Serhii Mumriak (JIRA)

mliberman (JIRA User) oh my god, thank you so much! can i ask how did you find the underlying problem? I was thinking about debugging swiftpm itself, but it's not really possible which i tried to find help for here: https://forums.swift.org/t/is-there-a-way-to-debug-swift-package-manager-in-xcode/37185/5

swift-ci commented 4 years ago

Comment by Max Liberman (JIRA)

PALKOVNIK (JIRA User) I tracked down the warning message ("you may be able to install...") to here. I discovered that PkgConfig is part of the SwiftToolsSupport library (specifically, the TSCUtility module), so I created a new executable Swift package that pulled in that dependency, and was able to debug the PkgConfig constructor that way.

swift-ci commented 4 years ago

Comment by Max Liberman (JIRA)

PALKOVNIK (JIRA User) by the way, as a local workaround, you can just change the Requires.private line in gobject-2.0.pc to:

Requires.private: libffi >=  3.0.0

The file should be located at:

$(brew --prefix)/opt/glib/lib/pkgconfig/gobject-2.0.pc
swift-ci commented 4 years ago

Comment by Serhii Mumriak (JIRA)

mliberman (JIRA User) yea, I was also going thru `TSCUtility`, did not know about the `Requires.private` in pkg-config (I mean I don't know much about it at all). Also thanks for the workaround, I'll try it today 🙂

swift-ci commented 4 years ago

Comment by Serhii Mumriak (JIRA)

mliberman (JIRA User) I tried that workaround with changing the absolute path to just `libffi >= 3.0.0` and the issue is still there. I assume that's the one you've fixed is a different one.

UPD. oops, did not remove the file extension and it works correctly. Thanks for fix!

swift-ci commented 3 years ago

Comment by Tobias H (JIRA)

Hello, I think I've also encountered a similar, maybe the same problem. I think this issue has actually been fixed in the `main` branch of `apple/swift-tools-support-core`:

See my post here: https://forums.swift.org/t/possible-bug-regression-with-regards-to-pc-files/42306