From bb56c0d84028f858a1eccf7d7e35797baf1da51d Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 19:30:33 +1100 Subject: [PATCH] Fix msvc stdout not shown on error Fixed #1260 --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 187eb705..a23d8cad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)) } @@ -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::*;