Setup cross compilation toolchain for custom sysroot/compiler

#1

Hi,

I’m trying to set up a rust cross-tool-chain for our custom C/C++ cross compiler + sysroot.

Basically it’s a similar scenario as to buildroot, but the project we’re using is called openadk. And it doesn’t come with an option to use rust.

I searched this forum and the internet far and wide. I found

https://github.com/Ogeon/rust-on-raspberry-pi/
https://github.com/japaric/rust-cross
[Solved] Cross Compile against a sysroot / SDK (like Raspberry Pi)

and a few others. But trying to follow them I failed. The most promising approach has been to check out a specific revision of rust-lang/rust.git and follow Ogeons advice. But in the end this reliably fails trying to compile something with the ARM gcc that’s supposed to be a x86 target and failing.

The final error message is then

  Compiling rustc-main v0.0.0 (file:///home/dir/software/vc/rust/src/rustc)
    Finished release [optimized] target(s) in 5m 9.22s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building LLVM for x86_64-unknown-linux-gnu
running: "cmake" "/home/dir/software/vc/rust/src/llvm" "-DLLVM_ENABLE_ASSERTIONS=OFF" "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;Mips;PowerPC;SystemZ;MSP430;Sparc;NVPTX;Hexagon" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly" "-DLLVM_INCLUDE_EXAMPLES=OFF" "-DLLVM_INCLUDE_TESTS=OFF" "-DLLVM_INCLUDE_DOCS=OFF" "-DLLVM_ENABLE_ZLIB=OFF" "-DWITH_POLLY=OFF" "-DLLVM_ENABLE_TERMINFO=OFF" "-DLLVM_ENABLE_LIBEDIT=OFF" "-DLLVM_ENABLE_LIBXML2=OFF" "-DLLVM_PARALLEL_COMPILE_JOBS=32" "-DLLVM_TARGET_ARCH=x86_64" "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu" "-DLLVM_OCAML_INSTALL_PATH=usr/lib/ocaml" "-DLLVM_LINK_LLVM_DYLIB=ON" "-DCMAKE_C_COMPILER=cc" "-DCMAKE_CXX_COMPILER=c++" "-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_INSTALL_PREFIX=/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm" "-DCMAKE_BUILD_TYPE=Release"
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/dir/projects/ableton/ableton-os/modules/openadk/toolchain_raspberry-pi3_glibc_cortex_a53_hard_eabihf/usr/arm-openadk-linux-gnueabihf/bin/c++
-- Check for working CXX compiler: /home/dir/projects/ableton/ableton-os/modules/openadk/toolchain_raspberry-pi3_glibc_cortex_a53_hard_eabihf/usr/arm-openadk-linux-gnueabihf/bin/c++ -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCXXCompiler.cmake:45 (message):
  The C++ compiler

    "/home/dir/projects/ableton/ableton-os/modules/openadk/toolchain_raspberry-pi3_glibc_cortex_a53_hard_eabihf/usr/arm-openadk-linux-gnueabihf/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_fb93e/fast"
    make[1]: Entering directory '/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeTmp'
    /usr/bin/make -f CMakeFiles/cmTC_fb93e.dir/build.make CMakeFiles/cmTC_fb93e.dir/build
    make[2]: Entering directory '/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_fb93e.dir/testCXXCompiler.cxx.o
    /home/dir/projects/ableton/ableton-os/modules/openadk/toolchain_raspberry-pi3_glibc_cortex_a53_hard_eabihf/usr/arm-openadk-linux-gnueabihf/bin/c++    -ffunction-sections -fdata-sections -fPIC -m64    -o CMakeFiles/cmTC_fb93e.dir/testCXXCompiler.cxx.o -c /home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    c++: error: unrecognized command line option '-m64'
    CMakeFiles/cmTC_fb93e.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_fb93e.dir/testCXXCompiler.cxx.o' failed
    make[2]: *** [CMakeFiles/cmTC_fb93e.dir/testCXXCompiler.cxx.o] Error 1
    make[2]: Leaving directory '/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_fb93e/fast' failed
    make[1]: *** [cmTC_fb93e/fast] Error 2
    make[1]: Leaving directory '/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeTmp'




  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:45 (project)


-- Configuring incomplete, errors occurred!
See also "/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeOutput.log".
See also "/home/dir/software/vc/rust/build/x86_64-unknown-linux-gnu/llvm/build/CMakeFiles/CMakeError.log".
thread 'main' panicked at '
command did not execute successfully, got: exit code: 1

build script failed, must exit now', /home/dir/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.30/src/lib.rs:643:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
	finished in 0.751
failed to run: /home/dir/software/vc/rust/build/bootstrap/debug/bootstrap build
Build completed unsuccessfully in 0:06:47
Makefile:28: recipe for target 'all' failed
make: *** [all] Error 1

Any suggestions on how to approach this are much appreciated.

0 Likes

#2

To late for an answer but this is for those that will stumble on this.
Please see: https://github.com/japaric/xargo
You could also contact Japaric on Twitter: @ japaricious

0 Likes