3

I can't seem to build Rust as a cross-compiler, either on Windows with MSYS2 or on a fresh install of Debian Wheezy. The error is the same for both. I run this configure:

./configure --target=arm-unknown-linux-gnueabihf,x86_64-pc-windows-gnu

make works, but then make install fails with:

[...]
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/rustdoc-*.dll
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/fmt_macros-*.dll
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/libmorestack.a
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/libcompiler-rt.a
compile: arm-unknown-linux-gnueabihf/rt/arch/arm/morestack.o
make[1]: arm-linux-gnueabihf-gcc: Command not found
/home/Sandro/rust/mk/rt.mk:94: recipe for target 'arm-unknown-linux-gnueabihf/rt/arch/arm/morestack.o' failed
make[1]: *** [arm-unknown-linux-gnueabihf/rt/arch/arm/morestack.o] Error 127
make[1]: Leaving directory '/home/Sandro/rust'
/home/Sandro/rust/mk/install.mk:22: recipe for target 'install' failed
make: *** [install] Error 2

Everything builds fine if I don't specify a cross architecture. Am I missing some special configure flag to make this work?

1 Answer 1

7

The error message says that make did not find the arm-linux-gnueabihf-gcc binary, which is supposed to be a C compiler producing ARM code. That means that you probably don't have any ARM C cross-compilation toolchain installed.

I know Ubuntu has packages for cross compilers (gcc-arm-linux-gnueabihf in 14.04) so Debian may have the same packages. You can also find fully packaged ARM C cross-compilers for Windows and Linux on the Linaro website. If you are building for the Rapsberry Pi, you can also find toolchains to build for Raspbian and Archlinux on https://github.com/raspberrypi/tools.

Here is an example under Linux with a Linaro toolchain (should be distribution-agnostic for the host)

$ wget http://releases.linaro.org/14.11/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz
$ tar -xf gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz
$ export PATH=$PATH:$PWD/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin
$ cd <your_configured_rustc_build_directory>
$ make

You can then use the cross compiler with the following line. You can provide the full path to the arm-linux-gnueabihf-gcc binary if you don't want to put it in your PATH.

rustc --target=arm-unknown-linux-gnueabihf -C linker=arm-linux-gnueabihf-gcc hello.rs

If you are using Cargo, you can specify the linker to use for each target in the .cargo/config with this option:

[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the links, but the Linaro cross binaries for Windows seem to be built for mingw32 on Windows, so they don't run on msys2 which the Rust build uses. I'll try in my Debian VM. Still, it seems like it should be possible to just build what I need from LLVM, which is already included in the Rust build. Seems unnecessarily convoluted to require the cross chain to be already installed.
LLVM still does not include binutils (ld, as and other fundamental programs) so you would will always need those. Besides, Rust uses jemalloc, written in C, that needs a cross-compiler. So maybe it could be possible to include clang in what is being downloaded and built as an option, but the simplest (and fastest) will still be to rely on a cross-compilation toolchain being already installed.
Ok, so I've managed to build rust cross compiler on Debian Jessie after including the embebian sources and installing the arm gc cross compilers. Native rust progams build and run as before, but building for arm fails with a link error: higherlogics.com/personal/err-arm.txt I'm not sure what it means by file in wrong format. Does ARM not use ELF, so I should somehow get rust to use arm-linux-gnueabihf-ld? I'm not sure how to do that since it clearly used arm-linux-gnueabihf-gcc.
It looks like rustc still tries to use cc which is usually a symlink to gcc, which will in turn try to use ld and not the cross-compiling one arm-linux-gnueabihf-ld. Could you try with rustc --target=arm-unknown-linux-gnueabihf hello.rs -C linker=arm-linux-gnueabihf-gcc?
That seemed to do it, although Raspbian is only on glibc 2.13 where this linked to glibc 2.18. I can just link everything statically for my purposes, so not a big deal. So is there some configure option for rust to use the proper linker given the --target specified?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.