I am trying to build a small command line executable using the recently introduced Benchmark Package.
I can build and run the binary in my package after I have added the dependency on the benchmark package:
swift run -c release
warning: failed to retrieve search paths with pkg-config; maybe pkg-config is not installed
warning: you may be able to install jemalloc using your system-packager:
brew install jemalloc
Building for production...
[4/4] Linking bm1
Build of product 'bm1' complete! (4.63s)
Hello, Swift!
but what about these warning about pkg-config missing?
Despite the above working, when I try and run the benchmarks I get an error:
% swift package benchmark
warning: failed to retrieve search paths with pkg-config; maybe pkg-config is not installed
warning: you may be able to install jemalloc using your system-packager:
brew install jemalloc
Building for debugging...
<module-includes>:1:9: note: in file included from <module-includes>:1:
1 | #import "../../Headers/jemalloc.h"
| `- note: in file included from <module-includes>:1:
2 |
/Users/giik/Developer/CLI/BMPackage1/.build/checkouts/package-jemalloc/Sources/jemalloc/../../Headers/jemalloc.h:1:10: error: 'jemalloc/jemalloc.h' file not found
1 | #include <jemalloc/jemalloc.h>
| `- error: 'jemalloc/jemalloc.h' file not found
What is pkg-config? Is it something my system was already supposed to have (this is on MacOS 15 with Xcode and the tools installed, and so far I haven't had any issues depending on packages in Xcode or in CL tools using the SwiftPM)?
I have only
% pkg
pkgbuild pkgutil
and looking around I found pkgconf on homebrew. Does SwiftPM expect to find this on my machine? If yes, why did it not come with SwiftPM or the developer tools, etc.? I searched the SwiftPM documentation quickly but did not find any mention of pkg-config.
I'd install it if I have to but wanted to make sure I am not doing something wrong/missing some config somewhere.
You're getting a warning about pkg-config, not an error. The error in question is because you don't have jemalloc installed on your machine, which is understandable because I also had this error when using the benchmark package for the first time and installing it fixed the problem.
Yeah, I fixed it by installing jemalloc. I think I was confused because I expecting that all dependencies of the benchmark package will be pulled automatically.
The .systemLibrary type is used in SwiftPM to designate libraries that are expected to be installed globally on the system. SwiftPM won't ever install a system library; it expects it to exist in one of the standard include and library paths for your system.
pkg-config is a tool that builds a local database of system libraries and where to find the header and dylib files for those. If pkg-config is installed on your system, SwiftPM will query the pkg-config database to find the include and library search paths for any system library targets declared by a package. It's optional, though, because SwiftPM will always fall back on the default include and library search paths that make sense for your system, I believe.
I don't think pkg-config is installed by default on macOS, but you can install it via Homebrew with brew install pkgconf (which you have already found).
On my machine, I can run e.g. these commands to find out how to compile and link against jemalloc (also installed via Homebrew):