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

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

Open
bmisiak opened this issue May 19, 2019 · 3 comments
Open

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

bmisiak opened this issue May 19, 2019 · 3 comments

Comments

@bmisiak
Copy link

bmisiak commented May 19, 2019

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. 😟

@Pycckue-Bnepeg
Copy link
Owner

Hi! Thanks to you for the notice!
I'll think about it. There is HOST and TARGET environment variables in compile time which may replace cfg!(target_arch).
I guess it's also a reason why https://docs.rs couldn't build documentation for samp-sdk

@bmisiak
Copy link
Author

bmisiak commented May 21, 2019

For sure.
Please mind rust-lang/cargo#4423.
The issue also bit me because WSL only supports 64-bit binaries, so I wasn't able to run the 32-bit toolchain on it. I had to remove build.rs to compile my Linux binaries from WSL.

@jameshilliard
Copy link

Possible fix for this in #9322.

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