Skip to content
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

Fix msvc stdout not shown on error #1303

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only when linking for MSVC? Seems like we'd want to do this everywhere, if we wanted to do it in the first place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks updated.

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");
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
}

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