-
Notifications
You must be signed in to change notification settings - Fork 153
Description
Bug description
I was getting myself familiar with nix, and faced some issues while compiling esp-idf rust project.
Since using rustup is not a good thing in nix (everything should be declarative and separate tools managing packets or versions are generally discouraged), I've created a flake locally in my project dir, which would prepare clean environment with nightly toolchain ready (cargo and rustc). Therefore I don't have rustup and espup in my build environment.
I've created empty test project and minimal nix configuration, and I am getting compilation error:
thread 'main' (1217628) panicked at /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bindgen-0.71.1/lib.rs:604:27:
Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"
After a few hours trying to fix this, trying different configurations and setting env variables, I came up with a solution, but it requires changes in esp-idf-sys crate:
- clone esp-idf-sys locally and make changes to function setup_clang_env in build::common:
pub fn setup_clang_env(path: Option<&Path>) -> Result<()> {
// If the user already set LIBCLANG_PATH, respect it and skip auto-detection
if std::env::var_os("LIBCLANG_PATH").is_some() {
return Ok(());
}
// ...
- modify
flake.nix
From
devShells.x86_64-linux.default =
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in pkgs.mkShell {
buildInputs = [ pkgs.rustup pkgs.ldproxy ];
shellHook = "rustup show";
};
to
devShells.x86_64-linux.default =
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in pkgs.mkShell {
buildInputs = [ pkgs.rustup pkgs.ldproxy ];
packages = [
pkgs.llvmPackages.libclang
];
env.LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
And after this project builds successfully.
- Would you like to work on a fix? y
To Reproduce
- Clone https://github.com/skibon02/esp-nix-issue
- Install nix package manager
- In project directory run
nix developandcargo build -r
Expected behavior
Build without errors
Environment
- Crate (
esp-idf-sys) version: 0.37.1 - ESP-IDF branch or tag: 5.4.3
- Target device (MCU): esp32c6
- OS: Linux Mint 22.2, Nix package manager with environment from flake
Metadata
Metadata
Assignees
Labels
Type
Projects
Status