I have a Rust application that generates a number of bindings to a custom Linux kernel device driver via bindgen. The application builds and runs correctly under Ubuntu.
The application needs to run on custom embedded hardware which uses a Linux kernel built using Yocto.
I have used cargo bitbake to generate a recipe for my application and I have added it to a custom **Yocto **layer. When I try and build my application the compilation fails because bitbake fails to locate libclang
The error is as follows:
| --- stderr
| thread 'main' panicked at '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: [])"', /mnt/data-001/ahk-dev/Views/View01/ngh-yocto-nuc/build/tmp/work/corei7-64-poky-linux/demo-driver/0.1.0.AUTOINC+a8bbb460f8-r0/cargo_home/bitbake/bindgen-0.59.2/src/lib.rs:2144:31
| stack backtrace:
| 0: rust_begin_unwind
| 1: core::panicking::panic_fmt
| 2: core::result::unwrap_failed
| 3: core::result::Result<T,E>::expect
| 4: core::ops::function::FnOnce::call_once
| 5: lazy_static::lazy::Lazy<T>::get::{{closure}}
| 6: std::sync::once::Once::call_once::{{closure}}
| 7: std::sync::once::Once::call_inner
| 8: std::sync::once::Once::call_once
| 9: <bindgen::ensure_libclang_is_loaded::LIBCLANG as core::ops::deref::Deref>::deref
| 10: bindgen::ensure_libclang_is_loaded
| 11: bindgen::Bindings::generate
| 12: bindgen::Builder::generate
| 13: build_script_build::main
| 14: core::ops::function::FnOnce::call_once
| note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
| warning: build failed, waiting for other jobs to finish...
| Building [========================> ] 90/95: clap
| warning: `clap` (lib) generated 2 warnings (2 duplicates)
| error: build failed
| WARNING: exit code 101 from a shell command.
Can anyone advise on how I should update my bitbake recipe so that libclang.so is build and available?
Yocto builds the complete OS including any toolchains via the "bitbake" command. In the case of Rust it will invoke cargo after pulling & building the required components.
So it now looks like cargo is not finding it when it tries to build my Rust application:
Caused by:
| process didn't exit successfully: `/mnt/data-001/ahk-dev/Views/View01/
ngh-yocto-nuc/build/tmp/work/corei7-64-poky-linux/
demo-driver/0.1.0.AUTOINC+a8bbb460f8-r0/build/target/
release/build/ngh_dummy_driver_if-ca354be690695b41/build-script-build`
(exit status: 101)
| --- stderr
| thread 'main' panicked at '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: [])"',
/mnt/data-001/ahk-dev/Views/View01/ngh-yocto-nuc/build/tmp/work/
corei7-64-poky-linux/demo-driver/0.1.0.AUTOINC+a8bbb460f8-r0/
cargo_home/bitbake/bindgen-0.59.2/src/lib.rs:2144:31
| stack backtrace:
Does anyone know how to configure my recipe such that LIBCLANG_PATH is set correctly to one of the versions of libclang.so which have been built by bitbake?
Although that is a directory which contains libclang.so the build still fails with the following:
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at
/mnt/data-001/ahk-dev/Views/View01/ngh-yocto-nuc/build/tmp/work/corei7-64-poky-linux/
demo-driver/0.1.0.AUTOINC+a8bbb460f8-r0/recipe-sysroot//usr/lib/libclang.so.14.0.3
could not be opened:
libncurses.so.5: cannot open shared object file: No such file or directory"',
/mnt/data-001/ahk-dev/Views/View01/ngh-yocto-nuc/build/tmp/work/corei7-64-poky-linux/
demo- driver/0.1.0.AUTOINC+a8bbb460f8-r0/cargo_home/bitbake/bindgen-0.59.2/src/lib.rs:2144:31
This means that libclang.so is coming from ${WORKDIR}/recipe-sysroot/usr/lib
I have found libncurses.so.5 is available in ${WORKDIR}/recipe-sysroot/lib, if I manually create a link for the missing library in ${WORKDIR}/recipe-sysroot/lib to ${WORKDIR}/recipe-sysroot/usr/lib the build continues completes successfully.
I thought I could simply modify LIBCLANG_PATH to include the second location , i.e.: