-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
When a custom build script fails, Cargo prints a very verbose output. It's often difficult to find the actual error message from the build script among all other debugging information printed just in case.
For example, it's common for pkg-config crate to fail, but the name of the library that user needs to install is buried under 30 other lines (and even worse with RUST_BACKTRACE=1)
error: failed to run custom build command for `tst v0.1.0 (/private/tmp/tst)`
Caused by:
process didn't exit successfully: `/private/tmp/tst/target/debug/build/tst-2429227eb6585f3e/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=IDONTEXIST_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_darwin
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=IDONTEXIST_STATIC
cargo:rerun-if-env-changed=IDONTEXIST_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_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
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_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
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_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: `"pkg-config" "--libs" "--cflags" "idontexist"` did not exit successfully: exit status: 1
--- stderr
Package idontexist was not found in the pkg-config search path.
Perhaps you should add the directory containing `idontexist.pc'
to the PKG_CONFIG_PATH environment variable
No package 'idontexist' found
', build.rs:2:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
It would be nice to trim this output and perhaps extract the error message from the build script and present it like "native" Cargo/Rust errors.
Steps
fn main() {
pkg_config::probe_library("idontexist").unwrap();
}
Possible Solution(s)
It needs multiple steps:
-
Cargo could hide valid directives like
cargo:rerun-if-env-changed=
from the stdout output, unless run with--verbose
(with a note about it, similar to how backtrace is hidden). -
It would be nice if Cargo could recognize when a build script panics, and present such information as an explicit build error. Instead of printing "--- stderr thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: `oops`" print just "error: oops" at the top with other Cargo/Rust errors. I'm not sure what the communication protocol for this could look like. Just parsing stderr for "thread 'main' panicked" might work, but feels inelegant.
-
Perhaps support
cargo:error=
directive, similar tocargo:warning=
, but also support it in stderr output, so that errors printed due to.unwrap()
can use it.
Notes
No response
Version
cargo 1.58.0