Search code examples
rustyoctobitbakeopenembeddedyocto-recipe

Yocto & Rust - recipe fails to generate correct build dependencies


I am trying to build a Rust application for Yocto which uses a number of bindgen generated bindings to custom ioctl calls. My recipe includes the following dependency line:

DEPENDS += " clang ncurses ncurses-native libsdl2"
export LIBCLANG_PATH = "${WORKDIR}/recipe-sysroot/${libdir}"

When I try to build the recipe with bitbake I get the following error:

|   thread 'main' panicked at 'Unable to find libclang: "the `libclang` 
    shared library at 
${WORKDIR}/tmp/work/corei7-64-poky-linux/dummy-reader-sdl2/
          0.1.0.AUTOINC+d2766c10a0-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"', 

${WORKDIR}/tmp/work/corei7-64-poky-linux/dummy-reader-sdl2/
          0.1.0.AUTOINC+d2766c10a0-r0/
          cargo_home/bitbake/bindgen-0.59.2/src/lib.rs:2144:31

When I look in the recipe-sysroot/usr/lib/ I can see that it is populated with lib clang.so but libncurses.so.5 is missing (there is a libncurses.so library).

Further searching revealed that the missing libncurses.so.5 is present in recipe-sysroot/lib/. If I manually add a link (i.e. ln -s ../../lib/libncurses.so.5 libncurses.so.5 I can re-run bitbake and by application builds correctly and runs on the target hardware. This is obviously a hack and I need to find a proper solution.

Note. recipe-sysroot/lib/ does not contain libclang.so

How do I configure my recipe so that either:

libclang.so

  1. libncurses.so.5 & libclang.so are populated to the same directory (either recipe-sysroot/lib/or recipe-sysroot/usr/lib/)
  2. The dependencies for libclang.so search in recipe-sysroot/lib/

Solution

  • My eventual solution involves manually creating links to the required libraries within the configure step of the recipe. The code below checks if the require library exists in the {WORKDIR}/usr/lib directory, if not it creates a symbolic link to the version in the {WORKDIR}/lib directory.

    DEPENDS += " clang ncurses libsdl2"
    
    USR_LIB_WORKDIR = "${WORKDIR}/recipe-sysroot/${libdir}"
    BASE_LIB_WORKDIR = "${WORKDIR}/recipe-sysroot/${base_libdir}"
    export LIBCLANG_PATH = "${USR_LIB_WORKDIR}"
    
    do_configure:append() {
        if [ -f ${USR_LIB_WORKDIR}/libncurses.so.5 ];
        then
          echo "libncurses.so.5 already exists"
        else
            ln -s ${BASE_LIB_WORKDIR}/libncurses.so.5 ${USR_LIB_WORKDIR}/libncurses.so.5
        fi
    
        if [ -f ${USR_LIB_WORKDIR}/libtinfo.so.5 ];
        then
          echo "libtinfo.so.5 already exists"
        else
            ln -s ${BASE_LIB_WORKDIR}/libtinfo.so.5 ${USR_LIB_WORKDIR}/libtinfo.so.5
        fi
    }
    

    I am sure the recipe could be improved by extracting the test & create link operation above into a separate function but at present I am unsure how to create/call functions that take parameters in Yocto recipes.