Runtime detection of sysroot
⚓ Rust 📅 2026-05-28 👤 surdeus 👁️ 1Hi,
I'm cross compiling a mixed project for embedded targets (arm cortex-m4 and cortex-m33). Before I was using arm-none-eabi-gcc to compile C code and link, but to take advantage of LTO I would like to use clang to compile the C code and rustc to link.
The issue I run into is that arm-none-eabi-gcc knows where sysroot is so I don't have to provide that to bindgen and cc whereas clang doesn't.
What I prefer to do in -sys crates I own is calling out to arm-none-eabi-gcc to find the sysroot and then set it in the calls to cc/bindgen:
$ arm-none-eabi-gcc -print-sysroot
/usr/local/bin/../arm-none-eabi
The most promising solution I found that works in case others maintain them is a global override in .cargo/config.toml:
CFLAGS_thumbv8m.main-none-eabihf = "--sysroot=<HARD CODED SYSROOT>"
However setting variables in .cargo/config.toml cannot be done with runtime detected values, so all contributors need to setup this manually.
Is the best solution to have a ./bootstrap.sh script that generates such a config file or are there any better solutions? It is kind of inconvenient to have a script to run before cargo works.
Regards
1 post - 1 participant
🏷️ Rust_feed