Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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 this issue Jun 5, 2020 · 8 comments
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jun 5, 2020

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:

  • a warning saying "warning: you may be able to install pango using your system-packager: brew install pango glib"

  • a compilation error saying "error: 'pango/pango.h' file not found".
    None of this happens with swift 5.1.
    Also this is a macOS specific issue - linux runs fine up to 5.2.4.

@swift-ci
Copy link
Contributor Author

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
Copy link
Contributor Author

Comment by Max Liberman (JIRA)

I opened a PR here.

@swift-ci
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants