[image] 0xtyls: Can't find crate for 'serde_derive' which 'thoth' depends on... serde_derive is a procedural macro crate, so it is compiled to the host cpu, not the target cpu. I don't know how your build system works, so I can only guess. for cross compiling scenarios, certain crates are comโ€ฆ Answer from nerditation on users.rust-lang.org
๐ŸŒ
Rust
rust-lang.github.io โ€บ rustup โ€บ cross-compilation.html
Cross-compilation - The rustup book
Note that rustup target add only installs the Rust standard library for a given target. There are typically other tools necessary to cross-compile, particularly a linker. For example, to cross compile to Android the Android NDK must be installed. In the future, rustup will provide assistance installing the NDK components as well.
๐ŸŒ
Rust Programming Language
users.rust-lang.org โ€บ help
Cross compiling arm - help - The Rust Programming Language Forum
July 5, 2023 - Hi, I'm trying to cross compile raylib(essentially glfw w/ extras) from my host x86 archlinux to arm64 linux /usr/lib/gcc/aarch64-linux-gnu/13.1.0/../../../../aarch64-linux-gnu/bin/ld: cannot find -lX11: No such file or directory collect2: error: ld returned 1 exit status ^ with cargo build --target aarch64-unknown-linux-gnu , I presume I need the arm64 version of x11 installed or something? and the following is done with cross --- stderr CMake Error at /usr/local/share/cmake-3....
๐ŸŒ
Bryan Burgers
burgers.io โ€บ cross-compile-rust-from-arm-to-x86-64
Cross-compiling Rust from ARM to x86-64 | Bryan Burgers
July 14, 2020 - I decided we needed to figure out how to build our lambda runtimes from an ARM server: I needed to cross-compile Rust from ARM to x86-64. So here we go. I launched two Ubuntu 20.04 instances: a c6g.medium for the build machine and a t3.micro as an x86-64 to run the results on.
๐ŸŒ
Reddit
reddit.com โ€บ r/rust โ€บ using rust on windows for arm?
r/rust on Reddit: Using Rust on Windows for ARM?
March 27, 2022 -

I'm extremely new to Rust, and so I have some questions about platforms.

How is Rust on Windows for ARM? Can I target ARM64 when building on ARM-based Windows? If I am on an x64 Windows PC, can I target ARM64 Windows? I also couldn't find a Rust download for Windows on ARM, does it work on Windows for ARM?

Sorry if these questions are kind of basic. I am super new to Rust and I couldn't exactly find answers to these questions. Thank you!

Top answer
1 of 2
12

Thanks to @Notlikethat's comment:

a) Yes you need to provide your own GCC cross-compiler.

b) You can get one here (select a mingw32 build).

Just unzip linaro's GCC then point cargo to it:

[target.armv7-unknown-linux-gnueabihf]
linker = "C:/Users/me/gcc-linaro-5.3.1-2016.05-i686-mingw32_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc.exe"

It seems to work even though it is arm- and not armv7-. I guess linking doesn't depend on the ISA. Actually I haven't run it yet, but it builds without errors!

Edit:

You can now use armv7-unknown-linux-musleabihf instead and get an actually portable binary (i.e. it doesn't depend on the GNU C library which often causes compatibility issues).

2 of 2
9

For MacOS better use: musleabihf, for Windows you can use gnueabihf as bellow:

Mac

$ brew install arm-linux-gnueabihf-binutils
$ rustup target add armv7-unknown-linux-musleabihf

In .cargo/config

[build]
target = "armv7-unknown-linux-musleabihf"
[target.armv7-unknown-linux-c]
linker = "arm-linux-gnueabihf-ld"

With simple src/main.rs

fn main() {
    println!("Hello, Raspberry!");
}

Then things are fine:

Hasans-Air:rpi hasan$ cargo build
   Compiling rpi v0.1.0 (/Users/hasan/PycharmProjects/rpi)
    Finished dev [unoptimized + debuginfo] target(s) in 0.41s
Hasans-Air:rpi hasan$ scp target/armv7-unknown-linux-musleabihf/debug/rpi [email protected]:
[email protected]'s password: 
rpi                                                                                         100% 2702KB   2.6MB/s   00:01    
Hasans-Air:rpi hasan$ ssh [email protected] 'chmod +x ~/rpi && ~/rpi'
[email protected]'s password: 
Hello, Raspberry!

Win 10 Get the linker from here, and run:

rustup target add armv7-unknown-linux-gnueabihf

Creating file .cargo/config with content:

[build]
target = "armv7-unknown-linux-gnueabihf"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

And with simple src/main.rs:

fn main() {
    println!("Hello, Raspberry! from Win 10");
}

I was able to get things done

Find elsewhere
๐ŸŒ
Rust Forge
forge.rust-lang.org โ€บ platform-support.html
Platform Support - The rustc book
Redirecting to... https://doc.rust-lang.org/nightly/rustc/platform-support.html
๐ŸŒ
Modio
modio.se โ€บ cross-compiling-rust-binaries-to-armv7.html
Cross compiling Rust binaries to ARMv7 | Modio
With Rust this is usually all handled by Cargo, by adding the --target option when compiling your code. So if you normally do cargo build you instead do cargo build --target armv7-unknown-linux-gnueabihf.
๐ŸŒ
Medium
medium.com โ€บ @wizofe โ€บ cross-compiling-rust-for-arm-e-g-raspberry-pi-using-any-os-11711ebfc52b
Cross compiling Rust for ARM (e.g. Raspberry Pi) using any OS! | by ioannis valasakis | Medium
July 8, 2018 - Here is a small walkthrough, on how to use Mac OSx, Linux or even Windows (hey not tested but I am sure you can make it work, the tools are the same) to compile your Rust marvellousness and run the binary directly on the Raspberry Pi (2/3/3+).
๐ŸŒ
Embedded Rust
docs.rust-embedded.org โ€บ embedonomicon โ€บ compiler-support.html
A note on compiler support - The Embedonomicon
Default target: x86_64-unknown-linux-gnu Host CPU: skylake Registered Targets: aarch64 - AArch64 (little endian) aarch64_be - AArch64 (big endian) arm - ARM arm64 - ARM64 (little endian) armeb - ARM (big endian) hexagon - Hexagon mips - Mips mips64 - Mips64 [experimental] mips64el - Mips64el ...
๐ŸŒ
FreeBSD
forums.freebsd.org โ€บ non-i386/amd64 and embedded โ€บ embedded
Cross-compiling Rust for aarch64 from amd64 | The FreeBSD Forums
May 6, 2024 - It actually worked for me, to a point. As long as pure rust code was compiled everything was okay. But then it needed to link to a shared library, so I needed to somehow put it in the right place, etc/ That's where I gave up and decided to build directly on a small arm64 system that I have.
๐ŸŒ
Rust Internals
internals.rust-lang.org โ€บ compiler
How to build arm64e apps on macOS / iOS - compiler - Rust Internals
August 28, 2023 - So, I have tried to patch the Rust compiler, but I got the linked error for std, panic_unwind, etc.: building for iOS-arm64e but attempting to link with file build for unknown-arm64 I have tried to add two new targets: arm64e-apple-ios and arm64e-apple-dawrin.
๐ŸŒ
Embedded Rust
docs.rust-embedded.org โ€บ faq.html
Frequently Asked Questions - Embedded Rust documentation
Default target: x86_64-unknown-linux-gnu Host CPU: skylake Registered Targets: aarch64 - AArch64 (little endian) aarch64_be - AArch64 (big endian) arm - ARM arm64 - ARM64 (little endian) armeb - ARM (big endian) hexagon - Hexagon mips - Mips mips64 - Mips64 [experimental] mips64el - Mips64el ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 72583828 โ€บ cross-compiling-rust-on-win10-for-aarch64-linux
windows - Cross-compiling Rust on Win10 for aarch64/Linux - Stack Overflow
I think it's a problem with freetype because it requires installing a library first. Maybe it's not possible to cross-compile at all because of this. ... You might have more joy using WSL to build the cross-tools. I built musl-cross-make (to target the RG351 handheld) without issue under WSL and am moving onto rust next.
๐ŸŒ
The Rust Programming Language
doc.rust-lang.org โ€บ rustc โ€บ platform-support โ€บ arm64ec-pc-windows-msvc.html
arm64ec-pc-windows-msvc - The rustc book
You can build Rust with support ... require no special configuration. Tests can be run on AArch64 Windows 11 devices. C code can be built using the Arm64-targeting MSVC or Clang toolchain....
๐ŸŒ
Rustprojectprimer
rustprojectprimer.com โ€บ building โ€บ cross.html
Cross-Compiling - Rust Project Primer
To cross-compile for ARM64 on a Debian-based system: # install the cross-compiler and target libraries sudo dpkg --add-architecture arm64 sudo apt update sudo apt install gcc-aarch64-linux-gnu libssl-dev:arm64 # add the Rust target rustup target add aarch64-unknown-linux-gnu # tell Cargo which ...