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

State of Linux->Windows cross compilation #42

Open
piegamesde opened this issue Jun 17, 2022 · 2 comments
Open

State of Linux->Windows cross compilation #42

piegamesde opened this issue Jun 17, 2022 · 2 comments

Comments

@piegamesde
Copy link

Hi, what's the current state of cross compilation from Windows? The README says:

Note that using this crate on non windows platform is undefined behavior. It does not contain safeguards against doing so.

What actions would be necessary to get this to work on Linux? If this is not easily possible, can at least some safeguards please be added?

@olback
Copy link

olback commented Oct 21, 2022

My build.rs looks something like this:

fn main() {
    output_dir();
    gen();
    match std::env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
        "linux" | "macos" => { /* Nothing to do here */ }
        // If building *FOR* Windows
        "windows" => {
            generate_manifest();
            generate_rc();
            let mut rc = winres::WindowsResource::new();
            rc.set_manifest_file(&(String::from(env!("CARGO_MANIFEST_DIR")) + "/" + MANIFEST_OUT));
            rc.set_resource_file(&(String::from(env!("CARGO_MANIFEST_DIR")) + "/" + RC_OUT));

            #[cfg(not(target_os = "windows"))]
            {
                rc.set_ar_path("x86_64-w64-mingw32-gcc-ar");
                rc.set_windres_path("x86_64-w64-mingw32-windres");
            }

            rc.compile().unwrap()
        }
        _ => panic!("Target not supported"),
    }
}

It works fine on Linux. If you're using Rust 1.61 or greater, you'll have to use this fork.

@BenjaminRi
Copy link

Cross-compilation should now work out of the box in v0.1.13 of my fork. I updated the README as well, it had some buggy instructions (target_os is the host OS when you compile build.rs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants