-
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
Indicate when build errors occur in build.rs
, rather than in main compilation
#10834
Comments
Transferred to rust-lang/cargo as this is likely something cargo would need to handle. |
Tip: You can run Generally, when seeing $ cargo b --verbose
Fresh unicode-ident v1.0.1
Compiling example v0.1.0 (/projects/example)
Compiling ...
Compiling serde v1.0.139
+ Running `rustc --crate-name build_script_build --edition=2021 build.rs --error-format=json
+ --json=diagnostic-rendered-ansi,artifacts,fu ture-incompat --crate-type bin
+ --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2
+ -C metadata=39a8aabaeae1d ec5 -C extra-filename=-39a8aabaeae1dec5 --out-dir
+ /projects/example/target/debug/build/example-39a8aabaeae1dec5 -C
+ incremental=/projects/example/target/debug/incremental
+ -L dependency=/projects/example/target/debug/deps`
Running ...
Running ...
error[E0433]: failed to resolve: use of undeclared crate or module `serde`
--> src/sometimes_working/mod.rs:1:30
|
1 | #[derive(Clone, Debug, Hash, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
| ^^^^^ use of undeclared crate or module `serde`
error[E0433]: failed to resolve: use of undeclared crate or module `serde`
--> src/sometimes_working/mod.rs:1:50
|
1 | #[derive(Clone, Debug, Hash, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
| ^^^^^ use of undeclared crate or module `serde`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `example` due to 2 previous errors
+ Caused by:
+ process didn't exit successfully: `rustc --crate-name build_script_build --edition=2021
+ build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat
+ --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked
+ -C debuginfo=2 -C metadata=39a8aabaeae1dec5 -C extra-filename=-39a8aabaeae1dec5
+ --out-dir /projects/example/target/debug/build/example-39a8aabaeae1dec5
+ -C incremental=/projects/example/target/debug/incremental
+ -L dependency=/projects/example/target/debug/deps` (exit status: 1)
warning: build failed, waiting for other jobs to finish...
|
See also #11598 for some discussion. |
Coming from #11598, when you hop in a new codebase or one you've not worked for a bit of time, it's very easy not to think about the |
Now I feel like this approach is doable. If anyone is interested in contributing, here is one of the solutions. Cargo is already more informative when indicating what is being warned. You can read from this piece of code. We can reuse that in the error path here. The error message would look like the following: Compiling foo v0.1.0 (/home/user/projects/foo)
error[E0432]: unresolved import `crate::Lib`
--> src/foo.rs:2:5
|
2 | use crate::Lib;
| ^^^^^^^^^^ no `Lib` in the root
For more information about this error, try `rustc --explain E0432`.
- error: could not compile `foo` due to previous error
+ error: could not compile `foo` (build-script) due to previous error If you have any question, please don't hesitate to ask here or ping me on Zulip. |
This reverts commit 09f3293.
- Adding display of which target failed to compile - Consistent messages for warnings/errors. - Fixing assertions on related tests.
When compilation errors occur during
build.rs
execution, there is no indication in the error output that the error occurred at that stage. This can cause confusing behavior that is difficult to debug.I encountered this issue when adding serde serialization to an enum which was also imported in build.rs to generate tab completions for clap. Despite using serde in another module, I was seeing missing crate errors. This turned out to be very time consuming to track down, and wasn't found until I tried to make a sanitized reproduction of the problem to share with others after initial consultation in the rust Discord was unsuccessful in debugging the issue.
To avoid time lost due to similar issues in the future, the compiler should clearly indicate if the errors were produced while compiling
build.rs
, rather than the main[[bin]]
or[[lib]]
.Given the attached code:
example.zip
The current output is:
Ideally the output should look like:
The text was updated successfully, but these errors were encountered: