Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kozo2/cde1797d91b1e20941924c4faec18f7a to your computer and use it in GitHub Desktop.
Save kozo2/cde1797d91b1e20941924c4faec18f7a to your computer and use it in GitHub Desktop.
Rust cross compile - Linux x86_64 -> Linux Sparc64 (gcc 5.4.0)
$ docker run -it ubuntu:xenial
Unable to find image 'ubuntu:xenial' locally
xenial: Pulling from library/ubuntu
...
Digest: sha256:a0ee7647e24c8494f1cf6b94f1a3cd127f423268293c25d924fbe18fd82db5a4
Status: Downloaded newer image for ubuntu:xenial
root@3479ac349e68:/# cd
root@3479ac349e68:~# uname -a
Linux 3479ac349e68 4.7.3-coreos-r2 #1 SMP Thu Feb 2 02:26:10 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
root@3479ac349e68:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
root@3479ac349e68:~# apt update
...
10 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@3479ac349e68:~# apt install -y gcc-5-sparc64-linux-gnu
...
root@3479ac349e68:~# apt install -y curl file
...
root@3479ac349e68:~# sparc64-linux-gnu-gcc-5 --version
sparc64-linux-gnu-gcc-5 (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root@3479ac349e68:~# sparc64-linux-gnu-ld --version
GNU ld (GNU Binutils for Ubuntu) 2.26.1
Copyright (C) 2015 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
root@3479ac349e68:~# curl https://sh.rustup.rs -sSf | sh
...
stable installed - rustc 1.18.0 (03fc9d622 2017-06-06)
Rust is installed now. Great!
...
root@3479ac349e68:~# source $HOME/.cargo/env
root@3479ac349e68:~# rustup target add sparc64-unknown-linux-gnu
root@3479ac349e68:~# echo $USER
root@3479ac349e68:~# export USER=root
root@3479ac349e68:~# cargo new --bin hello
Created binary (application) `hello` project
root@3479ac349e68:~# cd hello
root@3479ac349e68:~/hello# RUSTFLAGS="-C linker=sparc64-linux-gnu-gcc-5" cargo build --target=sparc64-unknown-linux-gnu
Compiling hello v0.1.0 (file:///root/hello)
Finished dev [unoptimized + debuginfo] target(s) in 0.65 secs
root@3479ac349e68:~/hello# file target/sparc64-unknown-linux-gnu/debug/hello
target/sparc64-unknown-linux-gnu/debug/hello: ELF 64-bit MSB shared object, SPARC V9, total store ordering, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=1c94adfdaf50b6a6d0b6ee5c09443a1c8317feb2, not stripped
root@3479ac349e68:~/hello# rustc --emit obj --target=sparc64-unknown-linux-gnu -C linker=sparc64-linux-gnu-gcc-5 src/main.rs
root@3479ac349e68:~/hello# file main.o
main.o: ELF 64-bit MSB relocatable, SPARC V9, total store ordering, version 1 (SYSV), not stripped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment