rust-cross / cargo-xwin

Cross compile Cargo project to Windows MSVC target with ease
Other
346 stars 30 forks source link

Build Scripts ignore target cfg #35

Closed RinLovesYou closed 1 year ago

RinLovesYou commented 1 year ago

Hi there! Want to just preface this by saying thank you for making this tool, it's been a great help!

It seems that build scripts will ignore target os, when building for windows, on linux

fn main() {
    #[cfg(target_os = "windows")]
    {
        println!("cargo:warning=Linking Exports File..");
        use std::path::Path;
        let lib_path = Path::new("deps").join("Exports.def");
        let absolute_path = std::fs::canonicalize(&lib_path).unwrap();
        println!(
            "cargo:rustc-cdylib-link-arg=/DEF:{}",
            absolute_path.display()
        );
    }
}

building this with cargo xwin build --target x86_64-pc-windows-msvc on linux, will result in no output, and no linking of the definition file. if i remove the target_os attribute, linking succeeds. Obviously this is not good if we're not compiling for windows, as it would require a manual change to the build.rs each time.

messense commented 1 year ago

You are doing it wrong, see https://github.com/Byron/trash-rs/issues/39#issue-981022414

messense commented 1 year ago

See https://kazlauskas.me/entries/writing-proper-buildrs-scripts