-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Prevent building cargo from invalidating build cache of other tools due to conditionally applied -Zon-broken-pipe=kill
via tracked RUSTFLAGS
#131155
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||
//! Check that `rustc` and `rustdoc` does not ICE upon encountering a broken pipe due to unhandled | ||||
//! panics from raw std `println!` usages. | ||||
//! | ||||
//! Regression test for <https://github.com/rust-lang/rust/issues/34376>. | ||||
|
||||
//@ ignore-cross-compile (needs to run test binary) | ||||
|
||||
#![feature(anonymous_pipe)] | ||||
|
||||
use std::io::Read; | ||||
use std::process::{Command, Stdio}; | ||||
|
||||
use run_make_support::env_var; | ||||
|
||||
#[derive(Debug, PartialEq)] | ||||
enum Binary { | ||||
Rustc, | ||||
Rustdoc, | ||||
} | ||||
|
||||
fn check_broken_pipe_handled_gracefully(bin: Binary, mut cmd: Command) { | ||||
let (reader, writer) = std::pipe::pipe().unwrap(); | ||||
drop(reader); // close read-end | ||||
cmd.stdout(writer).stderr(Stdio::piped()); | ||||
|
||||
let mut child = cmd.spawn().unwrap(); | ||||
|
||||
let mut stderr = String::new(); | ||||
child.stderr.as_mut().unwrap().read_to_string(&mut stderr).unwrap(); | ||||
let status = child.wait().unwrap(); | ||||
|
||||
assert!(!status.success(), "{bin:?} unexpectedly succeeded"); | ||||
|
||||
const PANIC_ICE_EXIT_CODE: i32 = 101; | ||||
|
||||
#[cfg(not(windows))] | ||||
{ | ||||
// On non-Windows, rustc/rustdoc built with `-Zon-broken-pipe=kill` shouldn't have an exit | ||||
// code of 101 because it should have an wait status that corresponds to SIGPIPE signal | ||||
// number. | ||||
assert_ne!(status.code(), Some(PANIC_ICE_EXIT_CODE), "{bin:?}"); | ||||
// And the stderr should be empty because rustc/rustdoc should've gotten killed. | ||||
assert!(stderr.is_empty(), "{bin:?} stderr:\n{}", stderr); | ||||
} | ||||
|
||||
#[cfg(windows)] | ||||
{ | ||||
match bin { | ||||
// On Windows, rustc has a paper that propagates the panic exit code of 101 but converts | ||||
// broken pipe errors into fatal errors instead of ICEs. | ||||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could try changing the windows hack to a rust/compiler/rustc_driver_impl/src/lib.rs Line 1412 in cf24c73
1 .
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do that in a follow-up, I would like to stop run-make cargo rebuilds lol. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair! |
||||
Binary::Rustc => { | ||||
assert_eq!(status.code(), Some(PANIC_ICE_EXIT_CODE), "{bin:?}"); | ||||
// But make sure it doesn't manifest as an ICE. | ||||
assert!(!stderr.contains("internal compiler error"), "{bin:?} ICE'd"); | ||||
} | ||||
// On Windows, rustdoc seems to cleanly exit with exit code of 1. | ||||
Binary::Rustdoc => { | ||||
assert_eq!(status.code(), Some(1), "{bin:?}"); | ||||
assert!(!stderr.contains("panic"), "{bin:?} stderr contains panic"); | ||||
} | ||||
} | ||||
} | ||||
} | ||||
|
||||
fn main() { | ||||
let mut rustc = Command::new(env_var("RUSTC")); | ||||
rustc.arg("--print=sysroot"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this is technically not robust because I exploited the fact that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah idk how specifically that will be handled, but that is left as an exercise for the future reader. Actually I think to clarify, I believe the |
||||
check_broken_pipe_handled_gracefully(Binary::Rustc, rustc); | ||||
|
||||
let mut rustdoc = Command::new(env_var("RUSTDOC")); | ||||
rustdoc.arg("--version"); | ||||
check_broken_pipe_handled_gracefully(Binary::Rustdoc, rustdoc); | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.