Multiple targets in compiler


#1

rustc (similarly to clang) has a --target option and both rustc and cargo documentations clearly suggest that single build can build for multiple targets. However:

First, is there some way I can ask the compiler which targets it can build and which it can build?

And second, I have the pre-built nightly rust, x86_64-unknown-linux-gnu build, installed. I also have native gcc and clang with multilib support and i686-w64-mingw32 gcc cross-compiler. My native clang accepts all of -m32, --target=i586-linux-gnu and --target=i686-w64-mingw32 and builds the correct products (modulo correct default extensions).

So what do I need to do to get rustc capable of building the same targets?

Update: Web search did not seem to turn up anything that would look like documentation, but I eventually got to 6b130e3d that tells me the corresponding targets are called i686-unknown-linux-gnu and i686-pc-windows-gnu. And then rustc tells me:

test.rs:1:1: 1:1 error: can't find crate for `std`

Can I just unpack them from the other archives?


#2

It should work and allow you to progress further, yeah. I don’t know if it will magically work immediately after that, though. (Be sure to get the archives that correspond exactly to the compiler you have, or else things may be utterly broken.)


#3

I tried and got to the point where I got

/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0x1f22): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0x2151): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0x2174): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0x2bf3): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0x2d5c): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0x5130): more undefined references to `_Unwind_Resume' follow
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0xaec72): undefined reference to `_Unwind_RaiseException'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0xaf79d): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0xaf8be): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0xafc08): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libstd-4e7c5e5c.rlib(std-4e7c5e5c.o):(.text+0xafdd2): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libcollections-4e7c5e5c.rlib(collections-4e7c5e5c.o):(.text+0x414): undefined reference to `_Unwind_Resume'
/usr/local/stow/rust-nightly/lib/rustlib/i686-pc-windows-gnu/lib/libcollections-4e7c5e5c.rlib(collections-4e7c5e5c.o):(.text+0xb98): more undefined references to `_Unwind_Resume' follow
collect2: error: ld returned 1 exit status

for i686-pc-windows-gnu target. Which is apparently issue #12859. So I am now installing the 64-bit variant that according to that bug should work.

Two things surprise me:

  1. Why do I have to tell rustc which linker to use while the system clang 3.5 can make it out on it’s own?
  2. And does that mean that the i686-w64-mingw32-gcc cross-compiler is configured differently from the native compiler for the same target?

#4

In 64-bit mode it seems to work.

I’ve downloaded both native (x86_64-unknown-linux-gnu) and win64 (x86_64-pc-windows-gnu) builds, from the same channel, installed the native and copied bin/rustlib/x86_64-pc-windows-gnu from the win64 one to lib/rustlib/x86_64-pc-windows-gnu in the installation (yes, it’s bin on windows, but lib on linux`). And then rustc generates working executables.

Edit: oops, spoke too fast. The executable works in 64-bit wine (which is pain to use alongside wine32 but whatever), but not on actual windows machine. It crashes there.