diff options
Diffstat (limited to 'meta/classes/cargo.bbclass')
-rw-r--r-- | meta/classes/cargo.bbclass | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/meta/classes/cargo.bbclass b/meta/classes/cargo.bbclass new file mode 100644 index 0000000000..0ca38143c0 --- /dev/null +++ b/meta/classes/cargo.bbclass | |||
@@ -0,0 +1,89 @@ | |||
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}" | ||
16 | DEPENDS:append:class-native = " rust-native" | ||
17 | |||
18 | # Enable build separation | ||
19 | B = "${WORKDIR}/build" | ||
20 | |||
21 | # In case something fails in the build process, give a bit more feedback on | ||
22 | # where the issue occured | ||
23 | export 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 | ||
27 | CARGO_SRC_DIR ??= "" | ||
28 | |||
29 | # The actual path to the Cargo.toml | ||
30 | MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml" | ||
31 | |||
32 | RUSTFLAGS ??= "" | ||
33 | BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}" | ||
34 | CARGO_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. | ||
38 | BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}" | ||
39 | CARGO_TARGET_SUBDIR="${HOST_SYS}/${BUILD_DIR}" | ||
40 | oe_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 | |||
49 | do_compile[progress] = "outof:\s+(\d+)/(\d+)" | ||
50 | cargo_do_compile () { | ||
51 | oe_cargo_fix_env | ||
52 | oe_cargo_build | ||
53 | } | ||
54 | |||
55 | cargo_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 | |||
89 | EXPORT_FUNCTIONS do_compile do_install | ||