Skip to content

Commit

Permalink
Fix msvc stdout not shown on error
Browse files Browse the repository at this point in the history
Fixed #1260
  • Loading branch information
NobodyXu authored Nov 24, 2024
1 parent 1eefa74 commit bb56c0d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,9 @@ impl Build {
if cfg!(target_os = "macos") {
self.fix_env_for_apple_os(&mut cmd)?;
}
if msvc {
disable_localization(&mut cmd);
}

Ok((cmd, name))
}
Expand Down Expand Up @@ -4094,6 +4097,21 @@ fn check_disabled() -> Result<(), Error> {
Ok(())
}

/// Copied from https://github.com/rust-lang/rust/blob/5db81020006d2920fc9c62ffc0f4322f90bffa04/compiler/rustc_codegen_ssa/src/back/linker.rs#L27-L38
///
/// Disables non-English messages from localized linkers.
/// Such messages may cause issues with text encoding on Windows
/// and prevent inspection of msvc output in case of errors, which we occasionally do.
/// This should be acceptable because other messages from rustc are in English anyway,
/// and may also be desirable to improve searchability of the linker diagnostics.
fn disable_localization(cmd: &mut Command) {
// No harm in setting both env vars simultaneously.
// Unix-style linkers.
cmd.env("LC_ALL", "C");
// MSVC's `link.exe`.
cmd.env("VSLANG", "1033");
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit bb56c0d

Please sign in to comment.