Skip to content

build.rs prevents cross-compiling. Solution: remove it! πŸŽ‰Β #17

@bmisiak

Description

@bmisiak

Build scripts, such as your build.rs, since they are built for execution on the compiling machine, don't receive the --target i686-… memo. As a result, their cfg!(target_arch) always matches the architecture of the rustc which compiles them - usually x86_64.

Because build.rs always sees x86_64, cross-compilation of your library from x86_64 hosts always fails, except for the scenario where a Windows user installs the whole 32-bit Rust toolchain (which 64-bit Windows happens to be able to execute thanks to WOW64) and uses it to compile the 32-bit plugin - I believe this is what you did.

When I removed build.rs in my fork, cross-compilation from x86_64 Windows (using the default stable-x86_64-pc-windows-msvc toolchain) to the i686-unknown-linux-gnu target worked perfectly! 🎈 There is no need to install a linux toolchain (which wouldn't even execute on Windows if you tried) nor the 32-bit windows toolchain. All that's needed to compile for Linux is:

rustup target add i686-unknown-linux-gnu
cargo build --target=i686-unknown-linux-gnu

And likewise, for 32-bit Windows:

rustup target add i686-pc-windows-msvc
cargo build --target=i686-pc-windows-msvc

You don't have to run the 32-bit version of rustc to compile for 32-bit targets. You're only supposed to change the target. The library, because of the build.rs quirk, needlessly restricts cross-compilation. 😟

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions