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

Cross-compiling on windows: howto #28

Open
mzji opened this issue Nov 8, 2016 · 7 comments
Open

Cross-compiling on windows: howto #28

mzji opened this issue Nov 8, 2016 · 7 comments

Comments

@mzji
Copy link

mzji commented Nov 8, 2016

Recently I want to compile something to a specific windows target. My development environment is Win10 64-bit, VS 2015 Update 3, with x86_64-pc-windows-msvc rustc/cargo/stdlib. I want to compile my crate for a 32-bit windows environment. Since VS contains both 32-bit and 64-bit linker, I think cross compiling from 64-bit Windows host to 32-bit Windows target is possible. However I don't find something helpful in this repository.

Since the purpose of this repository is

Everything you need to know about cross compiling Rust programs!

, I think adding some document will help those people who is in the same situation with me.

@Emilgardis
Copy link

Cross compiling for i686-pc-windows-msvc from x86_64-pc-windows-msvc should be done just as any other cross compilation.

Assuming rustup is installed (highly recommended)

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

@mzji
Copy link
Author

mzji commented Nov 8, 2016

@Emilgardis Yeah, but what I asked is adding this kind of thing, or this link, to the document.

@Emilgardis
Copy link

https://github.com/japaric/rust-cross#the-target-triple

https://github.com/japaric/rust-cross#cross-compiling-with-rustc

https://github.com/japaric/rust-cross#cross-compiling-with-cargo

How do those not explain how to cross-compile for different targets? (I am sorry if I sound rude, I'm just trying to understand what you want to improve on)

@mzji
Copy link
Author

mzji commented Nov 8, 2016

@Emilgardis If what I said made you feeling offensive, please accept my apologize here.

Maybe I didn't express well what I mean. Let me try to explain it in another way:
If a user known there is a thing called "cross-compiling", and known that it will let him/her compile a binary on one platform which will finally run on another platform, but known nothing about the whole process, what tool is needed, and what result could be got, then when they read this document, they feel depressed.

Basically here I think we could add some detailed tutorial for the user, for example:

If you want to cross-compile your rust program from Win32 to Win64, or vise versa, then do the following steps:

  1. ...
  2. ...
  3. ...
    After these steps, usually you will get an executable which runs on Win32/Win64 platforms! However, some other points might need be aware:
  4. ...
  5. ...
  6. ...

I think this is helpful for newbies (like me).

@Emilgardis
Copy link

Emilgardis commented Nov 8, 2016

That does seem like something that is missing. Maybe a more general example could be done or the TL;DR could be generalized for any (supported) target.

@mzji
Copy link
Author

mzji commented Nov 8, 2016

Cross compiling from Win32 to Win64 (or vise versa) is easy, to some extent:

  1. rustup target add i686-pc-windows-msvc/x86_64-pc-windows-msvc
  2. cargo build --target i686-pc-windows-msvc/x86_64-pc-windows-msvc
  3. Done!

Sometimes you may need to check the portability of your binary if some asm/C/C++ code is involved, in other situations these steps just work. However, in Linux/macOS world, things may different.
Maybe a hello world example (.Net Core uses this example to show its cross-compiling ability) is enough? I don't sure about this.

@avkonst
Copy link

avkonst commented Nov 8, 2017

When I run rustup on Windows it warns that I need to install C++ build tools, which I might get from Visual Studio. When I install Visual Studio, I can choose 2 packages: Windows development with C++ and Linux development with C++. If I install both, would it be possible to build binaries for linux on windows?

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