Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 1 | ## |
| 2 | ## Purpose: |
| 3 | ## This class is used by any recipes that are built using |
| 4 | ## Cargo. |
| 5 | |
| 6 | inherit cargo_common |
| 7 | |
| 8 | # the binary we will use |
| 9 | CARGO = "cargo" |
| 10 | |
| 11 | # We need cargo to compile for the target |
| 12 | BASEDEPENDS:append = " cargo-native" |
| 13 | |
| 14 | # Ensure we get the right rust variant |
| 15 | DEPENDS:append:class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 16 | DEPENDS:append:class-nativesdk = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 17 | DEPENDS:append:class-native = " rust-native" |
| 18 | |
| 19 | # Enable build separation |
| 20 | B = "${WORKDIR}/build" |
| 21 | |
| 22 | # In case something fails in the build process, give a bit more feedback on |
| 23 | # where the issue occured |
| 24 | export 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 |
| 28 | CARGO_SRC_DIR ??= "" |
| 29 | |
| 30 | # The actual path to the Cargo.toml |
| 31 | MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml" |
| 32 | |
| 33 | RUSTFLAGS ??= "" |
| 34 | BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}" |
| 35 | CARGO_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. |
| 39 | BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}" |
| 40 | CARGO_TARGET_SUBDIR="${HOST_SYS}/${BUILD_DIR}" |
| 41 | oe_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 | |
| 50 | do_compile[progress] = "outof:\s+(\d+)/(\d+)" |
| 51 | cargo_do_compile () { |
| 52 | oe_cargo_fix_env |
| 53 | oe_cargo_build |
| 54 | } |
| 55 | |
| 56 | cargo_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 | |
| 90 | EXPORT_FUNCTIONS do_compile do_install |