1## 2## Purpose: 3## This class is used by any recipes that are built using 4## Cargo. 5 6inherit cargo_common 7 8# the binary we will use 9CARGO = "cargo" 10 11# We need cargo to compile for the target 12BASEDEPENDS:append = " cargo-native" 13 14# Ensure we get the right rust variant 15DEPENDS:append:class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" 16DEPENDS:append:class-nativesdk = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" 17DEPENDS:append:class-native = " rust-native" 18 19# Enable build separation 20B = "${WORKDIR}/build" 21 22# In case something fails in the build process, give a bit more feedback on 23# where the issue occured 24export RUST_BACKTRACE = "1" 25 26# The directory of the Cargo.toml relative to the root directory, per default 27# assume there's a Cargo.toml directly in the root directory 28CARGO_SRC_DIR ??= "" 29 30# The actual path to the Cargo.toml 31MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml" 32 33RUSTFLAGS ??= "" 34BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}" 35CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} ${BUILD_MODE} --manifest-path=${MANIFEST_PATH}" 36 37# This is based on the content of CARGO_BUILD_FLAGS and generally will need to 38# change if CARGO_BUILD_FLAGS changes. 39BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}" 40CARGO_TARGET_SUBDIR="${HOST_SYS}/${BUILD_DIR}" 41oe_cargo_build () { 42 export RUSTFLAGS="${RUSTFLAGS}" 43 export RUST_TARGET_PATH="${RUST_TARGET_PATH}" 44 bbnote "cargo = $(which ${CARGO})" 45 bbnote "rustc = $(which ${RUSTC})" 46 bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@" 47 "${CARGO}" build ${CARGO_BUILD_FLAGS} "$@" 48} 49 50do_compile[progress] = "outof:\s+(\d+)/(\d+)" 51cargo_do_compile () { 52 oe_cargo_fix_env 53 oe_cargo_build 54} 55 56cargo_do_install () { 57 local have_installed=false 58 for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do 59 case $tgt in 60 *.so|*.rlib) 61 install -d "${D}${rustlibdir}" 62 install -m755 "$tgt" "${D}${rustlibdir}" 63 have_installed=true 64 ;; 65 *examples) 66 if [ -d "$tgt" ]; then 67 for example in "$tgt/"*; do 68 if [ -f "$example" ] && [ -x "$example" ]; then 69 install -d "${D}${bindir}" 70 install -m755 "$example" "${D}${bindir}" 71 have_installed=true 72 fi 73 done 74 fi 75 ;; 76 *) 77 if [ -f "$tgt" ] && [ -x "$tgt" ]; then 78 install -d "${D}${bindir}" 79 install -m755 "$tgt" "${D}${bindir}" 80 have_installed=true 81 fi 82 ;; 83 esac 84 done 85 if ! $have_installed; then 86 die "Did not find anything to install" 87 fi 88} 89 90EXPORT_FUNCTIONS do_compile do_install 91