cargo: Enable build separation

Place generated artifacts in the directory suggested by bitbake (${B})
instead of directly in the source directory. This has multiple
advantages such as the ability to share source directory between
multiple machine types without risking cross contamination.
This commit is contained in:
Johan Anderholm
2019-09-19 19:49:19 +02:00
parent 2a4bb8966a
commit a673320995
3 changed files with 18 additions and 4 deletions
+6 -3
View File
@@ -15,16 +15,19 @@ BASEDEPENDS_append = " cargo-native"
DEPENDS_append_class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}" DEPENDS_append_class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}"
DEPENDS_append_class-native = " rust-native" DEPENDS_append_class-native = " rust-native"
# Cargo only supports in-tree builds at the moment # Enable build separation
B = "${S}" B = "${WORKDIR}/build"
# In case something fails in the build process, give a bit more feedback on # In case something fails in the build process, give a bit more feedback on
# where the issue occured # where the issue occured
export RUST_BACKTRACE = "1" export RUST_BACKTRACE = "1"
# Assume there's a Cargo.toml directly in the source directory
MANIFEST_PATH ??= "${S}/Cargo.toml"
RUSTFLAGS ??= "" RUSTFLAGS ??= ""
BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}" BUILD_MODE = "${@['--release', ''][d.getVar('DEBUG_BUILD') == '1']}"
CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} ${BUILD_MODE}" 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 # This is based on the content of CARGO_BUILD_FLAGS and generally will need to
# change if CARGO_BUILD_FLAGS changes. # change if CARGO_BUILD_FLAGS changes.
+11
View File
@@ -73,6 +73,17 @@ cargo_common_do_configure () {
echo "[target.${BUILD_SYS}]" >> ${CARGO_HOME}/config echo "[target.${BUILD_SYS}]" >> ${CARGO_HOME}/config
echo "linker = '${RUST_BUILD_CCLD}'" >> ${CARGO_HOME}/config echo "linker = '${RUST_BUILD_CCLD}'" >> ${CARGO_HOME}/config
fi fi
# Put build output in build directory preferred by bitbake instead of
# inside source directory unless they are the same
if [ "${B}" != "${S}" ]; then
cat <<- EOF >> ${CARGO_HOME}/config
[build]
# Use out of tree build destination to avoid poluting the source tree
target-dir = "${B}/target"
EOF
fi
} }
oe_cargo_fix_env () { oe_cargo_fix_env () {
+1 -1
View File
@@ -29,7 +29,7 @@ do_compile_prepend () {
do_install () { do_install () {
install -d "${D}${bindir}" install -d "${D}${bindir}"
install -m 755 "${RUSTSRC}/target/${CARGO_TARGET_SUBDIR}/cargo" "${D}${bindir}" install -m 755 "${B}/target/${CARGO_TARGET_SUBDIR}/cargo" "${D}${bindir}"
} }
# Disabled due to incompatibility with libgit2 0.28.x (https://github.com/rust-lang/git2-rs/issues/458, https://bugs.gentoo.org/707746#c1) # Disabled due to incompatibility with libgit2 0.28.x (https://github.com/rust-lang/git2-rs/issues/458, https://bugs.gentoo.org/707746#c1)