Skip to content

Build failed due to the side effect of homebrew #50

@wold9168

Description

@wold9168

Since Homebrew includes pkg-config as a dependency for some software packages, on systems where Homebrew and specific Homebrew packages are installed, the deployment of such packages may fail due to pkg-config's inability to locate libsystemd — even if the corresponding system has already installed systemd-devel and its equivalent packages.

$ cargo build --release
# ... Unimportant output
  --- stderr
  pkg_config could not find "libsystemd": 
  pkg-config exited with status code 1
  > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags libsystemd

  The system library `libsystemd` required by crate `libsystemd-sys` was not found.
  The file `libsystemd.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  The PKG_CONFIG_PATH environment variable is not set.

  HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `libsystemd.pc`.

warning: build failed, waiting for other jobs to finish...

This issue arises because Homebrew places its binaries‘ path early in the $PATH environment variable.

$ which pkg-config
/home/linuxbrew/.linuxbrew/bin/pkg-config
$ pkg-config --libs libsystemd
Package libsystemd was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsystemd.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libsystemd' not found
$ /bin/pkg-config --libs libsystemd
-lsystemd
$ PKG_CONFIG_PATH=/usr/lib64/pkgconfig pkg-config --libs libsystemd
-L/usr/lib64 -lsystemd
$ rpm -qa | grep systemd-devel
systemd-devel-257.7-1.fc42.x86_64
$ rpm -ql systemd-devel|grep 'libsystemd.pc'
/usr/lib64/pkgconfig/libsystemd.pc

Homebrew is used by a large number of users, and many of them have installed software packages like pyenv that depend on pkg-config exactly provided by Homebrew. Therefore, this issue deserves attention.

Here is a temporary solution.

export PKG_CONFIG_PATH=/usr/lib64/pkgconfig # use pkg-config files provided by system

Or just remove Homebrew's bin from your $PATH temporarily:

export PATH=$(echo $PATH | awk -v RS=: -v ORS=: '/homebrew|linuxbrew|\/usr\/local\/(bin|sbin)/ {next} {print}' | sed 's/:$//')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions