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_common.bbclass | |
parent | 8e0a655a51bb8ce57a6581209325642d1b9a97de (diff) | |
download | openembedded-core-contrib-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_common.bbclass')
-rw-r--r-- | meta/classes/cargo_common.bbclass | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/meta/classes/cargo_common.bbclass b/meta/classes/cargo_common.bbclass new file mode 100644 index 0000000000..b0b039a22e --- /dev/null +++ b/meta/classes/cargo_common.bbclass @@ -0,0 +1,129 @@ +## +## Purpose: +## This class is to support building with cargo. It +## must be different than cargo.bbclass because Rust +## now builds with Cargo but cannot use cargo.bbclass +## due to dependencies and assumptions in cargo.bbclass +## that Rust & Cargo are already installed. So this +## is used by cargo.bbclass and Rust +## + +# add crate fetch support +inherit crate-fetch +inherit rust-common + +# Where we download our registry and dependencies to +export CARGO_HOME = "${WORKDIR}/cargo_home" + +# The pkg-config-rs library used by cargo build scripts disables itself when +# cross compiling unless this is defined. We set up pkg-config appropriately +# for cross compilation, so tell it we know better than it. +export PKG_CONFIG_ALLOW_CROSS = "1" + +# Don't instruct cargo to use crates downloaded by bitbake. Some rust packages, +# for example the rust compiler itself, come with their own vendored sources. +# Specifying two [source.crates-io] will not work. +CARGO_DISABLE_BITBAKE_VENDORING ?= "0" + +# Used by libstd-rs to point to the vendor dir included in rustc src +CARGO_VENDORING_DIRECTORY ?= "${CARGO_HOME}/bitbake" + +CARGO_RUST_TARGET_CCLD ?= "${RUST_TARGET_CCLD}" +cargo_common_do_configure () { + mkdir -p ${CARGO_HOME}/bitbake + + cat <<- EOF > ${CARGO_HOME}/config + # EXTRA_OECARGO_PATHS + paths = [ + $(for p in ${EXTRA_OECARGO_PATHS}; do echo \"$p\",; done) + ] + EOF + + cat <<- EOF >> ${CARGO_HOME}/config + + # Local mirror vendored by bitbake + [source.bitbake] + directory = "${CARGO_VENDORING_DIRECTORY}" + EOF + + if [ -z "${EXTERNALSRC}" ] && [ ${CARGO_DISABLE_BITBAKE_VENDORING} = "0" ]; then + cat <<- EOF >> ${CARGO_HOME}/config + + [source.crates-io] + replace-with = "bitbake" + local-registry = "/nonexistant" + EOF + fi + + cat <<- EOF >> ${CARGO_HOME}/config + + [http] + # Multiplexing can't be enabled because http2 can't be enabled + # in curl-native without dependency loops + multiplexing = false + + # Ignore the hard coded and incorrect path to certificates + cainfo = "${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt" + + EOF + + if [ -n "${http_proxy}" ]; then + echo "proxy = \"${http_proxy}\"" >> ${CARGO_HOME}/config + fi + + cat <<- EOF >> ${CARGO_HOME}/config + + # HOST_SYS + [target.${HOST_SYS}] + linker = "${CARGO_RUST_TARGET_CCLD}" + EOF + + if [ "${HOST_SYS}" != "${BUILD_SYS}" ]; then + cat <<- EOF >> ${CARGO_HOME}/config + + # BUILD_SYS + [target.${BUILD_SYS}] + linker = "${RUST_BUILD_CCLD}" + EOF + 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 + + cat <<- EOF >> ${CARGO_HOME}/config + + [term] + progress.when = 'always' + progress.width = 80 + EOF +} + +oe_cargo_fix_env () { + export CC="${RUST_TARGET_CC}" + export CXX="${RUST_TARGET_CXX}" + export CFLAGS="${CFLAGS}" + export CXXFLAGS="${CXXFLAGS}" + export AR="${AR}" + export TARGET_CC="${RUST_TARGET_CC}" + export TARGET_CXX="${RUST_TARGET_CXX}" + export TARGET_CFLAGS="${CFLAGS}" + export TARGET_CXXFLAGS="${CXXFLAGS}" + export TARGET_AR="${AR}" + export HOST_CC="${RUST_BUILD_CC}" + export HOST_CXX="${RUST_BUILD_CXX}" + export HOST_CFLAGS="${BUILD_CFLAGS}" + export HOST_CXXFLAGS="${BUILD_CXXFLAGS}" + export HOST_AR="${BUILD_AR}" +} + +EXTRA_OECARGO_PATHS ??= "" + +EXPORT_FUNCTIONS do_configure |