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

The good error message provided by pkg-config itself is suppressed and replaced by a rust-level error message that isn't always accurate or useful #174

Open
eli-schwartz opened this issue Jan 12, 2025 · 0 comments

Comments

@eli-schwartz
Copy link

eli-schwartz commented Jan 12, 2025

I tried to build a package which links to libgit2-sys. It is a bit finicky about which system libgit2 version to use. I can upgrade or downgrade libgit2 as needed, however. I just need to know what the actual problem is...

This is the error message I got:

warning: [email protected]+1.9.0: failed to probe system libgit2: 

error: failed to run custom build command for `libgit2-sys v0.18.0+1.9.0`

Caused by:
  process didn't exit successfully: `/var/tmp/portage/dev-vcs/git-absorb-0.6.17/work/git-absorb-0.6.17/target/release/build/libgit2-sys-3dc86e5cce7dbd79/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-check-cfg=cfg(libgit2_vendored,)
  cargo:rerun-if-env-changed=LIBGIT2_NO_VENDOR
  cargo:rerun-if-env-changed=LIBGIT2_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=LIBGIT2_STATIC
  cargo:rerun-if-env-changed=LIBGIT2_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:warning=failed to probe system libgit2: 
  pkg-config exited with status code 1
  > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 x86_64-pc-linux-gnu-pkg-config --libs --cflags libgit2 libgit2 >= 1.9.0 libgit2 < 1.10.0

  The system library `libgit2` required by crate `libgit2-sys` was not found.
  The file `libgit2.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 `libgit2.pc`.


  --- stderr
  thread 'main' panicked at /var/tmp/portage/dev-vcs/git-absorb-0.6.17/work/cargo_home/gentoo/libgit2-sys-0.18.0+1.9.0/build.rs:45:13:
  The environment variable `LIBGIT2_NO_VENDOR` has been set but no compatible system libgit2 could be found.
  The build is now aborting. To disable, unset the variable or use `LIBGIT2_NO_VENDOR=0`.

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Most of this can be ignored, and seems to come from cargo's handling of "build-script". The critical bit is cargo:warning, which tells me that pkg-config failed, and helpfully reports a command-line I can run to get more details:

PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 x86_64-pc-linux-gnu-pkg-config --libs --cflags libgit2 libgit2 >= 1.9.0 libgit2 < 1.10.0

This doesn't work

bash: 1.10.0: No such file or directory

which is apparently a bit of an edge case caused by:

pkg-config-rs/src/lib.rs

Lines 230 to 236 in 91fcbdb

/// Output a command invocation that can be copy-pasted into the terminal.
/// `Command`'s existing debug implementation is not used for that reason,
/// as it can sometimes lead to output such as:
/// `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_ALLOW_SYSTEM_LIBS="1" "pkg-config" "--libs" "--cflags" "mylibrary"`
/// Which cannot be copy-pasted into terminals such as nushell, and is a bit noisy.
/// This will look something like:
/// `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 pkg-config --libs --cflags mylibrary`

Side note: Maybe rust Command needs to borrow python's shlex module:

>>> command = ['PKG_CONFIG_ALLOW_SYSTEM_LIBS=1', 'PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1', 'x86_64-pc-linux-gnu-pkg-config', '--libs', '--cflags', 'libgit2', 'libgit2 >= 1.9.0', 'libgit2 < 1.10.0']
>>> print(shlex.join(command))
PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 x86_64-pc-linux-gnu-pkg-config --libs --cflags libgit2 'libgit2 >= 1.9.0' 'libgit2 < 1.10.0'

Anyways, I run the real command:

$ PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 x86_64-pc-linux-gnu-pkg-config \
         --libs --cflags libgit2 'libgit2 >= 1.9.0' 'libgit2 < 1.10.0'
Package dependency requirement 'libgit2 >= 1.9.0' could not be satisfied.
Package 'libgit2' has version '1.8.4', required version is '>= 1.9.0'

pkg-config tells me quite clearly what the problem is. It also does something similar if I try to ask for "doesnt-exist":

$ x86_64-pc-linux-gnu-pkg-config --libs --cflags doesnt-exist
Package doesnt-exist was not found in the pkg-config search path.
Perhaps you should add the directory containing `doesnt-exist.pc'
to the PKG_CONFIG_PATH environment variable
Package 'doesnt-exist' not found

This new error message is very similar to the error message pkg-config-rs gives, except that pkg-config itself knows when to give a better error message for partially matched version bounds.

awilfox added a commit to awilfox/pkg-config-rs that referenced this issue Jan 12, 2025
Otherwise, we are still not copy-paste friendly.

Ref: rust-lang#174
Fixes: a0640aa ("Wrap std::process::Command to track arguments and environment variables")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant