blob: 0ca38143c0b3dd59de53d1d96064001158d4cc89 [file] [log] [blame]
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05001##
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-native = " rust-native"
17
18# Enable build separation
19B = "${WORKDIR}/build"
20
21# In case something fails in the build process, give a bit more feedback on
22# where the issue occured
23export RUST_BACKTRACE = "1"
24
25# The directory of the Cargo.toml relative to the root directory, per default
26# assume there's a Cargo.toml directly in the root directory
27CARGO_SRC_DIR ??= ""
28
29# The actual path to the Cargo.toml
30MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml"
31
32RUSTFLAGS ??= ""
33BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
34CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} ${BUILD_MODE} --manifest-path=${MANIFEST_PATH}"
35
36# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
37# change if CARGO_BUILD_FLAGS changes.
38BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}"
39CARGO_TARGET_SUBDIR="${HOST_SYS}/${BUILD_DIR}"
40oe_cargo_build () {
41 export RUSTFLAGS="${RUSTFLAGS}"
42 export RUST_TARGET_PATH="${RUST_TARGET_PATH}"
43 bbnote "cargo = $(which ${CARGO})"
44 bbnote "rustc = $(which ${RUSTC})"
45 bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
46 "${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
47}
48
49do_compile[progress] = "outof:\s+(\d+)/(\d+)"
50cargo_do_compile () {
51 oe_cargo_fix_env
52 oe_cargo_build
53}
54
55cargo_do_install () {
56 local have_installed=false
57 for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do
58 case $tgt in
59 *.so|*.rlib)
60 install -d "${D}${rustlibdir}"
61 install -m755 "$tgt" "${D}${rustlibdir}"
62 have_installed=true
63 ;;
64 *examples)
65 if [ -d "$tgt" ]; then
66 for example in "$tgt/"*; do
67 if [ -f "$example" ] && [ -x "$example" ]; then
68 install -d "${D}${bindir}"
69 install -m755 "$example" "${D}${bindir}"
70 have_installed=true
71 fi
72 done
73 fi
74 ;;
75 *)
76 if [ -f "$tgt" ] && [ -x "$tgt" ]; then
77 install -d "${D}${bindir}"
78 install -m755 "$tgt" "${D}${bindir}"
79 have_installed=true
80 fi
81 ;;
82 esac
83 done
84 if ! $have_installed; then
85 die "Did not find anything to install"
86 fi
87}
88
89EXPORT_FUNCTIONS do_compile do_install