-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Presentation of build script errors is noisy, difficult to understand #10159
Comments
We talked about this in today's @rust-lang/cargo meeting. We agreed that
The idea of parsing it out of stderr seems a little harder, primarily because we don't currently parse anything out of stderr, so I don't think we'd want to do that in a first pass. |
Separately from the discussion in the meeting: I personally think cleaning up error messages in these cases seems like a good idea. Hiding the extensive stdout behind |
Thank you @joshtriplett Do you think it would be worthwhile to make a distinction between workspace crates and non-workspace? I'm thinking that a verbose build script output is important for debugging of the build script itself during its development. However, once the build script is done, and is used by others as a dependency, only the result (reported error) of the build script is relevant to users. The heuristic for choosing between "developer of build.rs" vs "user of build.rs" could be whether the crate with a build script belongs to the current workspace. |
In the end I've decided against making exceptions for local/workspace crates, because crate authors should be able to see the same error formatting as their downstream users. |
I decided not to make
So I suggest to keep using exit code, and threat |
Personally, I think its a problem that we can't add new directives and we should find a way to resolve this.
imo if something isn't an error, it shouldn't be reported as such
I see this being like compile_error!. I also think showing errors without erroring out would be confusing to users. |
@kornelski the cargo team talked about your compatibly concern which I broke out into #11461. In there is a proposed solution from the cargo team. We understand that a dependency might emit an error but the build.rs wants to swallow it and not automatically fail the build.rs independent of exit code. We feel that is an API negotiation between the build.rs author and the dependency but we should have a note of caution about that within the build script documentation as part of the PR adding |
This has been sitting for a year now, and continues to be a problem, e.g. https://users.rust-lang.org/t/problems-building-a-package/103268 |
#12201 finished FCP and I just kicked off bors which unblocks adding |
How is that a negotiation between the build.rs author and the dependency? If the dependency chooses to emit a |
I'm sorry if I'm coming here with a maybe off-topic or naive question, but how feasible would it be to have build.rs not just exposing a main() function, but exposing a function taking (or a type that implementing) some pre-defined trait like "CargoBuildScriptContext", wherein both logging, and outcome/severity would be much more explicit, controlled, and structured ? |
Some questions about behaviour. The docs state that:
I believe the answer to the second question should be yes. Any warnings may provide valuable context to make sense of the error message. And if the answer to the second question is yes, I think it should be the same for the first question, for consistency. EDIT: The docs just aren't precise. A code comment says this about warnings:
I'll update the docs. |
Either the dependency needs to not use |
The interface between Cargo and a build script is the calling of a binary. That means we can't use any Rust types for the bare bones interface. We are interested in providing an API to encapsulate that interface, see #12432 |
We'll likely have to try and see. Thankfully this is a question of UX and we can change it. |
I still think it's a mistake to have two redundant ways of reporting build failures. A script returning success code and a fatal error text at the same time is giving an incoherent response. This should be treated as a bug in the build script. |
Allow build scripts to report error messages through `cargo::error` Related to #10159. Adds the `cargo::error` build script directive. It is similar to `cargo::warning`, but it emits an error message and it also fails the build.
There was a concern raised about potential use of `cargo::error` by libraries, which could make it difficult for build script authors to decide what is an error. rust-lang#10159 (comment)
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)
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
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
The text was updated successfully, but these errors were encountered: