From 42369813e439a6725c864a53cd733c55fcab113a Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 19:30:34 +1100 Subject: [PATCH 1/8] 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::*; From ea1f9ccf8c088c4649cf468aa8fb2a409edd4463 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 19:40:48 +1100 Subject: [PATCH 2/8] Fix clippy lint --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a23d8cad..388435cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4097,7 +4097,7 @@ 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 +/// Copied from /// /// Disables non-English messages from localized linkers. /// Such messages may cause issues with text encoding on Windows From b4e0dbf94112d8424feab10baf55e602e8eec71a Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:21:36 +1100 Subject: [PATCH 3/8] Call disable_localization unconditionally --- src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 388435cb..b3209916 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1784,9 +1784,8 @@ impl Build { if cfg!(target_os = "macos") { self.fix_env_for_apple_os(&mut cmd)?; } - if msvc { - disable_localization(&mut cmd); - } + + disable_localization(&mut cmd); Ok((cmd, name)) } From 268fa7097cd6b8e7527fdf5123add2944913e180 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:24:48 +1100 Subject: [PATCH 4/8] Call disable_localization in try_get_compiler` --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b3209916..6cf8a9c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1785,8 +1785,6 @@ impl Build { self.fix_env_for_apple_os(&mut cmd)?; } - disable_localization(&mut cmd); - Ok((cmd, name)) } @@ -1952,6 +1950,8 @@ impl Build { cmd.push_cc_arg(warnings_to_errors_flag); } + disable_localization(&mut cmd); + Ok(cmd) } From f6f209a8849c9956aeb51e20ac9c5a696e6982d2 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:47:33 +1100 Subject: [PATCH 5/8] Set localization env based on msvc --- src/lib.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6cf8a9c5..d9dd9879 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1950,7 +1950,22 @@ impl Build { cmd.push_cc_arg(warnings_to_errors_flag); } - disable_localization(&mut cmd); + // Copied from + // + // 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. + + // No harm in setting both env vars simultaneously. + // Unix-style linkers. + if matches!(cmd.family, ToolFamily::Msvc { clang_cl: false }) { + cmd.env.push(("LC_ALL".into(), "C".into())); + } else { + // MSVC's `link.exe`. + cmd.env.push(("VSLANG".into(), "1033".into())); + } Ok(cmd) } @@ -4096,21 +4111,6 @@ fn check_disabled() -> Result<(), Error> { Ok(()) } -/// Copied from -/// -/// 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::*; From 5fedb08d0ec36ec7e6c8f170ef48403a43ced063 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:49:27 +1100 Subject: [PATCH 6/8] Fix setting env --- src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d9dd9879..258919d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1957,14 +1957,10 @@ impl Build { // 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. - - // No harm in setting both env vars simultaneously. - // Unix-style linkers. if matches!(cmd.family, ToolFamily::Msvc { clang_cl: false }) { - cmd.env.push(("LC_ALL".into(), "C".into())); + cmd.env.push(("VSLANG".into(), "1033".into())); } else { - // MSVC's `link.exe`. - cmd.env.push(("VSLANG".into(), "1033".into())); + cmd.env.push(("LC_ALL".into(), "C".into())); } Ok(cmd) From fc1de420fe4e9d5256243a3ca9ba7f08b762e529 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:52:37 +1100 Subject: [PATCH 7/8] Fix fmt --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 258919d8..8f80332d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1958,7 +1958,7 @@ impl Build { // 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. if matches!(cmd.family, ToolFamily::Msvc { clang_cl: false }) { - cmd.env.push(("VSLANG".into(), "1033".into())); + cmd.env.push(("VSLANG".into(), "1033".into())); } else { cmd.env.push(("LC_ALL".into(), "C".into())); } From b99cb103da036618a2ae79a909b187dcdbbffff6 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:35:45 +1100 Subject: [PATCH 8/8] Fix confusing wording in comment --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8f80332d..da1b91be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1956,7 +1956,7 @@ impl Build { // 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. + // and may also be desirable to improve searchability of the compiler diagnostics. if matches!(cmd.family, ToolFamily::Msvc { clang_cl: false }) { cmd.env.push(("VSLANG".into(), "1033".into())); } else {