Skip to content

spawn() assumption of UTF-8 output may not hold on Windows #424

Open
@indygreg

Description

@indygreg

(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 the cc 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions