Is it possible to make vscode/RLS use a cross-compiler in a Docker container?

I'm currently working on OSX, cross-compiling my code targeting Raspberry Pi 3 on this docker container: GitHub - dlecan/rust-crosscompiler-arm: Docker images for Rust dedicated to cross compilation for ARM v6 and more
I've set up a docker command that mounts the source and cargo registry inside the container, so running the script is (roughly) equivalent to running cargo.

This works fine, but rls-vscode doesn't work, since my code doesn't compile for OSX.

Is it possible to set up vscode/RLS/cargo in such a way that it would compile using this setup on save?

Is it possible to set up cargo in such a way that I could invoke my build command through cargo?

Alternatively, is there a better way to cross-compile for Raspberry Pi?

It depends on your dependencies. If all your dependencies are native rust crates, i.e. do not link to C-libraries, you can simply compile your project from cargo by invocing --target=armv7-unknown-linux-gnueabihf (you need to add the target first with rustup target add armv7-unknown-linux-gnueabihf).
If you have C-dependencies then things get messy, like it is stated in your referenced git.

You can read more about cross-compiling in Rust at this git.

Thank you for your answer. I have tried what you described before, and unfortunately that doesn't work. This got me thinking, however, and I found something that does work for my simple program:

  1. rustup target add armv7-unknown-linux-musleabihf
  2. brew install arm-linux-gnueabihf-binutils
  3. Add the following to .cargo/config:
[build]
target = "armv7-unknown-linux-musleabihf"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-ld
  1. cargo build

I'm uncertain about the applicability specifically for cross-compilation, but you could look into the vscode "remote development" addon. That includes options to run the vscode backend in the docker container, via ssh, or in WSL.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.