Skip to content

Cannot run cargo when cross-compiling for Windows from Linux #550

Open
@jeysal

Description

@jeysal

Repro

In a binary crate with the following code:

use std::process::Command;

fn main() {
    print!(
        "{}",
        String::from_utf8_lossy(
            &Command::new(env!("CARGO"))
                .arg("version")
                .output()
                .unwrap()
                .stdout
        )
    )
}

run cross run --target "x86_64-pc-windows-gnu" on x86_64 Linux.

Expected

Like cargo run, prints

    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/cross-run-cargo`
cargo 1.51.0 (43b129a20 2021-03-16)

Actual

Errors trying to spawn the cargo process

   Compiling cross-run-cargo v0.1.0 (/project)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s
     Running `wine /target/x86_64-pc-windows-gnu/debug/cross-run-cargo.exe`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 6, kind: Other, message: "Invalid handle." }', src/main.rs:10:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I didn't find much regarding this error and unfortunately don't know much about cross internal workings. At first I thought it might just be a general "you're running a Linux binary on Windows/Wine", but a lot of people report Windows error 6 invalid handle in connection with terminal handles/std streams. Using piped streams doesn't seem to help, however.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions