diff options
author | Randy MacLeod <Randy.MacLeod@windriver.com> | 2021-08-10 13:52:19 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-08-26 22:09:24 +0100 |
commit | 3ed57578cca93ff1ba4e0bf3f25566e10659a2f9 (patch) | |
tree | adf55dc33aee6d0403bcf9a9c4f1da6c310e7f65 /meta/classes/cargo.bbclass | |
parent | 8e0a655a51bb8ce57a6581209325642d1b9a97de (diff) | |
download | openembedded-core-3ed57578cca93ff1ba4e0bf3f25566e10659a2f9.tar.gz |
rust: initial merge of most of meta-rust
In the meta-rust repo at commit:
448047c Upgrade to 1.54.0 (#359)
Make the required directories:
mkdir ../oe-core/meta/recipes-devtools/rust
mkdir ../oe-core/meta/recipes-devtools/cargo
mkdir ../oe-core/meta/recipes-example
and then:
cp recipes-devtools/rust/* ../oe-core/meta/recipes-devtools/rust
cp recipes-devtools/cargo/* ../oe-core/meta/recipes-devtools/cargo
cp lib/crate.py ../oe-core/meta/lib
cp recipes-example/* ../oe-core/meta/recipes-example
cp conf/distro/include/rust_* ../oe-core/meta/conf/distro/include/
cp classes/* ../oe-core/meta/classes/
cp recipes-core/packagegroups/packagegroup-rust-cross-canadian.bb ../oe-core/meta/recipes-core/packagegroups
Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
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 @@ +## +## Purpose: +## This class is used by any recipes that are built using +## Cargo. + +inherit cargo_common + +# the binary we will use +CARGO = "cargo" + +# We need cargo to compile for the target +BASEDEPENDS:append = " cargo-native" + +# Ensure we get the right rust variant +DEPENDS:append:class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" +DEPENDS:append:class-native = " rust-native" + +# Enable build separation +B = "${WORKDIR}/build" + +# In case something fails in the build process, give a bit more feedback on +# where the issue occured +export RUST_BACKTRACE = "1" + +# The directory of the Cargo.toml relative to the root directory, per default +# assume there's a Cargo.toml directly in the root directory +CARGO_SRC_DIR ??= "" + +# The actual path to the Cargo.toml +MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml" + +RUSTFLAGS ??= "" +BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}" +CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} ${BUILD_MODE} --manifest-path=${MANIFEST_PATH}" + +# This is based on the content of CARGO_BUILD_FLAGS and generally will need to +# change if CARGO_BUILD_FLAGS changes. +BUILD_DIR = "${@['release', 'debug'][d.getVar('DEBUG_BUILD') == '1']}" +CARGO_TARGET_SUBDIR="${HOST_SYS}/${BUILD_DIR}" +oe_cargo_build () { + export RUSTFLAGS="${RUSTFLAGS}" + export RUST_TARGET_PATH="${RUST_TARGET_PATH}" + bbnote "cargo = $(which ${CARGO})" + bbnote "rustc = $(which ${RUSTC})" + bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@" + "${CARGO}" build ${CARGO_BUILD_FLAGS} "$@" +} + +do_compile[progress] = "outof:\s+(\d+)/(\d+)" +cargo_do_compile () { + oe_cargo_fix_env + oe_cargo_build +} + +cargo_do_install () { + local have_installed=false + for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do + case $tgt in + *.so|*.rlib) + install -d "${D}${rustlibdir}" + install -m755 "$tgt" "${D}${rustlibdir}" + have_installed=true + ;; + *examples) + if [ -d "$tgt" ]; then + for example in "$tgt/"*; do + if [ -f "$example" ] && [ -x "$example" ]; then + install -d "${D}${bindir}" + install -m755 "$example" "${D}${bindir}" + have_installed=true + fi + done + fi + ;; + *) + if [ -f "$tgt" ] && [ -x "$tgt" ]; then + install -d "${D}${bindir}" + install -m755 "$tgt" "${D}${bindir}" + have_installed=true + fi + ;; + esac + done + if ! $have_installed; then + die "Did not find anything to install" + fi +} + +EXPORT_FUNCTIONS do_compile do_install |