-
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
Invalid UTF-8 output in build scripts silently prevents displaying any output on error #14787
Comments
I believe this is being done at cargo/crates/cargo-util/src/process_error.rs Lines 72 to 89 in d050945
That is in contrast to how we get stdout/stderr in non-error cases:
As this code is generic, a part of me worries about making a blanket assumption that the output is text and rendering it in a lossy manner. For example, we've been discussing binary formats for Cargo (https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/.60cargo.20metadata.60.20performance/near/476523460). If we extend that to rustc, then we could have the rustc binary output rendered as lossy UTF-* which would be messy. Maybe in cases like |
I would only note that |
Yes, this ties into my comment
All of the build script non-error processing,. including |
Problem
Usually when a build script panics, cargo will display whatever was output to stdout and stderr. However, if a build script outputs invalid UTF-8 then the output is suppressed.
Steps
Create a new project with the following build.rs:
Use
cargo build
. Note the output is missing an--- stdout
section:If you amend the above build.rs to print
bad
tostderr
then it'll also be missing the---stderr
section.Possible Solution(s)
At the very least warn in this situation. A better fix would be to warn and display the output with the replacement character used in place of the bad bytes (or perhaps some more complex escaping).
Notes
The real world source of this report is rust-lang/cc-rs#1260. The best fix there would be for cc-rs to correctly re-encode the output of
cl.exe
as UTF-8 (if it isn't already). However, I think Cargo should do something here too.Version
cargo 1.82.0 (8f40fc5 2024-08-21)
release: 1.82.0
commit-hash: 8f40fc5
commit-date: 2024-08-21
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]
The text was updated successfully, but these errors were encountered: