I work on embedded applications for ARM platform. Source code is in Rust but the build shall occur in a Docker container with the complete toolchain. I am using VSCode + rust-analyzer on MacOS. I just need rust-analyzer for syntax highlight, code completion etc...Any call to rustc (through cargo metadata or cargo check for insatnce) can't work because it has to be performed in the Docker container but I run VSCode locally on MacOS. I have tried to play with the settings, and for instance disabling to run build script build.rs:
but I have still this error raised by rust-analyzer:
Failed to run build scripts of some packages.
Please refer to the logs for more details on the errors.
---
[Extension Info](vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html): Version 0.3.2353, Server Version 0.3.2353-standalone (37acea8052 2025-03-23)
It is like VSCode just ignores the extension settings.
Any idea how can I solve this ?
Thanks !
short answer: install the necessary cross compiling tools on your local development machine; if not possible, use vscode remote development on the cross build environment, e.g. check the "Dev Containers" extension; if not possible, run rust-analyzer without cargo using the low level rust-project.json.
below is longer explanation.
that's not true.
rustc frontend should be able to run on local machine just fine [1], i.e. cargo check should work even for cross compiled targets (for "pure" rust code, that is. ffi is a little complicated, but should not be a problem when done correctly). and cargo metadata is essential for rust-analyzer to work with cargo based projects.
you should not disable build scripts. rather, you should try to fix the build scripts that are broken for cross compiled targets instead.
for packages involving ffi, it is common to use build scripts to detect SDK files (headers, librarys), and to build the native library, and to generate bindings, etc. if not enough care is taken, the build script may be broken when doing cross compiling.
rust-analyzer is works the best with a (locally installed) rust toolchain. although it is actually quite capable of analyzing rust code standalone, e.g. without cargo, but you need to do a lot of setup works to provide the required information, and this is not trivial. see:
how can an ffi wrapper package (a.k.a -sys package) be cross compling capable?
for the linker flag settings, it should allow the user to customize or to override the SDK library detection process, e.g. by environment variables, or, preferably, by adding a links key to the package's manifest and let cargo control the linker settings when required.
for building native libraries from source, examine the TARGET environment variable. crates like cc or cmake handles cross compiling automatically.
for the bindgen integration, this should not be a problem: bindgen don't need to "build" the library, it just parses and analyzes definitions in the header files. for cross compiling, make sure to set the correct preprocessor flags. when no SDK headers was detected, the package should provide fallbacks, e.g. bundle a copy of the header files, or pre-generate the bindings offline.
actually, the codegen backend would also work, only the linking process is target dependent âŠī¸