-
Notifications
You must be signed in to change notification settings - Fork 450
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
spawn() assumption of UTF-8 output may not hold on Windows #424
Comments
Thanks for the report! This definitely sounds like a bug, but this is likely also a bug in Cargo as well as This is definitely going to be a really tricky one to fix, and it's something I'd prefer to ideally not have a ton of code for handling in this crate and instead just have something which defers the problem to elsewhere... |
I just spent a few minutes poking around the cargo source and I don't believe this is true. I don't know exactly what command the folks in the PyOxidizer issue were running but they both mentioned invoking For reference, I believe everything in cargo that takes the output of a subprocess and sends it to stdout/stderr uses Honestly pulling that whole FWIW, we struggled with streaming stdout/stderr from child processes on Windows in Firefox automation code for years and never managed to get a solution that worked well, mostly because Python uses |
I would go a step further with breaking the |
Good points! I wonder though if perhaps it's best to just do what Cargo already does by using @luser I'm curious, did y'all ever try out something like rust-lang/rust#62021 setting As for putting the functionality on crates.io and/or in libstd, I don't really disagree with either :). I probably don't have the time myself to maintain that though. |
(This issue is derived from indygreg/PyOxidizer#105.)
https://github.com/alexcrichton/cc-rs/blob/85bc5b9fce81177ed8024e5241136417c6008db8/src/lib.rs#L2377-L2413 creates a new process, reads its output as a byte stream, then proceeds to re-emit each line via
std::io::stdout().write_all()
.Unfortunately, this may not just work on Windows. That's because on Windows, Rust's stdio streams enforce that written bytes from Rust are UTF-8 when things are operating in console mode (https://github.com/rust-lang/rust/blob/03f19f7ff128a3b01eeab3f87f04cce22883f006/src/libstd/sys/windows/stdio.rs#L68).
If we invoke a process that emits bytes that aren't UTF-8 (say
cl.exe
emitting a localized warning message when the system code page isn't UTF-8),spawn()
will proxy these non UTF-8 bytes to Rust's stdio handler, which will summarily reject the bytes. The impact of this bug is that Windows users not using a system code page and localization that doesn't emit UTF-8 will not be able to use thecc
crate under certain use cases.The workaround is for
spawn()
to convert the output bytes to UTF-8 to placate Rust's standard library. @luser has pointed me at https://github.com/mozilla/sccache/blob/6ba6f6c15c106768b914a7697a763e2232fa253a/src/compiler/msvc.rs#L154 as an example of such code.The text was updated successfully, but these errors were encountered: