cargo.bbclass: replace with what was cargo_util.bbclass
The old cargo.bbclass had no users in meta-rust and had lots of problems (not least of which was lots of duplicated lines with cargo_util.bbclass). Delete the old cargo.bbclass and replace it entirely wiht cargo_util
This commit is contained in:
+42
-26
@@ -1,20 +1,23 @@
|
|||||||
inherit rust
|
inherit rust-vars
|
||||||
|
# add crate fetch support
|
||||||
|
inherit crate-fetch
|
||||||
|
|
||||||
CARGO ?= "cargo"
|
# the binary we will use
|
||||||
|
CARGO = "cargo"
|
||||||
|
|
||||||
|
# Where we download our registry and dependencies to
|
||||||
export CARGO_HOME = "${WORKDIR}/cargo_home"
|
export CARGO_HOME = "${WORKDIR}/cargo_home"
|
||||||
|
|
||||||
def cargo_base_dep(d):
|
# We need cargo to compile for the target
|
||||||
deps = ""
|
BASEDEPENDS_append = " cargo-native"
|
||||||
if not d.getVar('INHIBIT_DEFAULT_DEPS', True) and not d.getVar('INHIBIT_CARGO_DEP', True):
|
|
||||||
deps += " cargo-native"
|
|
||||||
return deps
|
|
||||||
|
|
||||||
BASEDEPENDS_append = " ${@cargo_base_dep(d)}"
|
# Ensure we get the right rust variant
|
||||||
|
DEPENDS_append_class-target = " virtual/${TARGET_PREFIX}rust ${RUSTLIB_DEP}"
|
||||||
|
DEPENDS_append_class-native = " rust-native"
|
||||||
|
|
||||||
# Cargo only supports in-tree builds at the moment
|
# Cargo only supports in-tree builds at the moment
|
||||||
B = "${S}"
|
B = "${S}"
|
||||||
|
|
||||||
|
|
||||||
# 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"
|
||||||
@@ -24,22 +27,26 @@ export RUST_BACKTRACE = "1"
|
|||||||
# for cross compilation, so tell it we know better than it.
|
# for cross compilation, so tell it we know better than it.
|
||||||
export PKG_CONFIG_ALLOW_CROSS = "1"
|
export PKG_CONFIG_ALLOW_CROSS = "1"
|
||||||
|
|
||||||
EXTRA_OECARGO_PATHS ??= ""
|
|
||||||
|
|
||||||
cargo_do_configure () {
|
cargo_do_configure () {
|
||||||
# FIXME: we currently make a mess in the directory above us
|
mkdir -p ${CARGO_HOME}
|
||||||
# (${WORKDIR}), which may not be ideal. Look into whether this is
|
|
||||||
# allowed
|
|
||||||
mkdir -p ../.cargo
|
|
||||||
# NOTE: we cannot pass more flags via this interface, the 'linker' is
|
# NOTE: we cannot pass more flags via this interface, the 'linker' is
|
||||||
# assumed to be a path to a binary. If flags are needed, a wrapper must
|
# assumed to be a path to a binary. If flags are needed, a wrapper must
|
||||||
# be used.
|
# be used.
|
||||||
echo "paths = [" >../.cargo/config
|
echo "paths = [" > ${CARGO_HOME}/config
|
||||||
|
|
||||||
for p in ${EXTRA_OECARGO_PATHS}; do
|
for p in ${EXTRA_OECARGO_PATHS}; do
|
||||||
printf "\"%s\"\n" "$p"
|
printf "\"%s\"\n" "$p"
|
||||||
done | sed -e 's/$/,/' >>../.cargo/config
|
done | sed -e 's/$/,/' >> ${CARGO_HOME}/config
|
||||||
echo "]" >>../.cargo/config
|
echo "]" >> ${CARGO_HOME}/config
|
||||||
|
|
||||||
|
# Point cargo at our local mirror of the registry
|
||||||
|
cat >> ${CARGO_HOME}/config <<EOF
|
||||||
|
[source.local]
|
||||||
|
local-registry = "${WORKDIR}/cargo_registry"
|
||||||
|
[source.crates-io]
|
||||||
|
replace-with = "local"
|
||||||
|
registry = "https://github.com/rust-lang/crates.io-index"
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# All the rust & cargo ecosystem assume that CC, LD, etc are a path to a single
|
# All the rust & cargo ecosystem assume that CC, LD, etc are a path to a single
|
||||||
@@ -52,6 +59,7 @@ export RUST_CFLAGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${CFLAGS}"
|
|||||||
export RUST_BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc"
|
export RUST_BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc"
|
||||||
export RUST_BUILD_CFLAGS = "${BUILD_CC_ARCH} ${BUILD_CFLAGS}"
|
export RUST_BUILD_CFLAGS = "${BUILD_CC_ARCH} ${BUILD_CFLAGS}"
|
||||||
|
|
||||||
|
RUSTFLAGS ??= ""
|
||||||
export CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
export CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
||||||
|
|
||||||
# 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
|
||||||
@@ -59,9 +67,9 @@ export CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
|||||||
export CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
export CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
||||||
oe_cargo_build () {
|
oe_cargo_build () {
|
||||||
export RUSTFLAGS="${RUSTFLAGS}"
|
export RUSTFLAGS="${RUSTFLAGS}"
|
||||||
which cargo
|
bbnote "cargo = $(which cargo)"
|
||||||
which rustc
|
bbnote "rustc = $(which rustc)"
|
||||||
bbnote ${CARGO} build ${CARGO_BUILD_FLAGS} "$@"
|
bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
|
||||||
"${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
|
"${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,18 +85,26 @@ oe_cargo_fix_env () {
|
|||||||
export HOST_AR="${BUILD_AR}"
|
export HOST_AR="${BUILD_AR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXTRA_OECARGO_PATHS ??= ""
|
||||||
|
|
||||||
cargo_do_compile () {
|
cargo_do_compile () {
|
||||||
cd "${B}"
|
# prevent cargo from trying to fetch down new data
|
||||||
|
mkdir -p "${WORKDIR}/cargo_home/registry/index/github.com-1ecc6299db9ec823"
|
||||||
|
touch "${WORKDIR}/cargo_home/registry/index/github.com-1ecc6299db9ec823/.cargo-index-lock"
|
||||||
|
|
||||||
oe_cargo_fix_env
|
oe_cargo_fix_env
|
||||||
oe_cargo_build
|
oe_cargo_build
|
||||||
}
|
}
|
||||||
|
|
||||||
# All but the most simple projects will need to override this.
|
|
||||||
cargo_do_install () {
|
cargo_do_install () {
|
||||||
local have_installed=false
|
local have_installed=false
|
||||||
install -d "${D}${bindir}"
|
|
||||||
for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do
|
for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do
|
||||||
if [ -f "$tgt" ] && [ -x "$tgt" ]; then
|
if [[ $tgt == *.so || $tgt == *.rlib ]]; then
|
||||||
|
install -d "${D}${rustlibdir}"
|
||||||
|
install -m755 "$tgt" "${D}${rustlibdir}"
|
||||||
|
have_installed=true
|
||||||
|
elif [ -f "$tgt" ] && [ -x "$tgt" ]; then
|
||||||
|
install -d "${D}${bindir}"
|
||||||
install -m755 "$tgt" "${D}${bindir}"
|
install -m755 "$tgt" "${D}${bindir}"
|
||||||
have_installed=true
|
have_installed=true
|
||||||
fi
|
fi
|
||||||
@@ -98,4 +114,4 @@ cargo_do_install () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_FUNCTIONS do_compile do_install do_configure
|
EXPORT_FUNCTIONS do_configure do_compile do_install
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
inherit rust-vars
|
|
||||||
# add crate fetch support
|
|
||||||
inherit crate-fetch
|
|
||||||
|
|
||||||
# the binary we will use
|
|
||||||
CARGO = "cargo"
|
|
||||||
|
|
||||||
# Where we download our registry and dependencies to
|
|
||||||
export CARGO_HOME = "${WORKDIR}/cargo_home"
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# Cargo only supports in-tree builds at the moment
|
|
||||||
B = "${S}"
|
|
||||||
|
|
||||||
# In case something fails in the build process, give a bit more feedback on
|
|
||||||
# where the issue occured
|
|
||||||
export RUST_BACKTRACE = "1"
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# All the rust & cargo ecosystem assume that CC, LD, etc are a path to a single
|
|
||||||
# command. Fixup the ones we give it so that is the case.
|
|
||||||
# XXX: this is hard coded based on meta/conf/bitbake.conf
|
|
||||||
# TODO: we do quite a bit very similar to this in rust.inc, see if it can be
|
|
||||||
# generalized.
|
|
||||||
export RUST_CC = "${CCACHE}${HOST_PREFIX}gcc"
|
|
||||||
export RUST_CFLAGS = "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${CFLAGS}"
|
|
||||||
export RUST_BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc"
|
|
||||||
export RUST_BUILD_CFLAGS = "${BUILD_CC_ARCH} ${BUILD_CFLAGS}"
|
|
||||||
|
|
||||||
RUSTFLAGS ??= ""
|
|
||||||
export CARGO_BUILD_FLAGS = "-v --target ${HOST_SYS} --release"
|
|
||||||
|
|
||||||
# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
|
|
||||||
# change if CARGO_BUILD_FLAGS changes.
|
|
||||||
export CARGO_TARGET_SUBDIR="${HOST_SYS}/release"
|
|
||||||
oe_cargo_build () {
|
|
||||||
export RUSTFLAGS="${RUSTFLAGS}"
|
|
||||||
bbnote "cargo = $(which cargo)"
|
|
||||||
bbnote "rustc = $(which rustc)"
|
|
||||||
bbnote "${CARGO} build ${CARGO_BUILD_FLAGS} $@"
|
|
||||||
"${CARGO}" build ${CARGO_BUILD_FLAGS} "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
oe_cargo_fix_env () {
|
|
||||||
export CC="${RUST_CC}"
|
|
||||||
export CFLAGS="${RUST_CFLAGS}"
|
|
||||||
export AR="${AR}"
|
|
||||||
export TARGET_CC="${RUST_CC}"
|
|
||||||
export TARGET_CFLAGS="${RUST_CFLAGS}"
|
|
||||||
export TARGET_AR="${AR}"
|
|
||||||
export HOST_CC="${RUST_BUILD_CC}"
|
|
||||||
export HOST_CFLAGS="${RUST_BUILD_CFLAGS}"
|
|
||||||
export HOST_AR="${BUILD_AR}"
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTRA_OECARGO_PATHS ??= ""
|
|
||||||
|
|
||||||
cargo_util_do_configure () {
|
|
||||||
mkdir -p ${CARGO_HOME}
|
|
||||||
# NOTE: we cannot pass more flags via this interface, the 'linker' is
|
|
||||||
# assumed to be a path to a binary. If flags are needed, a wrapper must
|
|
||||||
# be used.
|
|
||||||
echo "paths = [" > ${CARGO_HOME}/config
|
|
||||||
|
|
||||||
for p in ${EXTRA_OECARGO_PATHS}; do
|
|
||||||
printf "\"%s\"\n" "$p"
|
|
||||||
done | sed -e 's/$/,/' >> ${CARGO_HOME}/config
|
|
||||||
echo "]" >> ${CARGO_HOME}/config
|
|
||||||
|
|
||||||
# Point cargo at our local mirror of the registry
|
|
||||||
cat >> ${CARGO_HOME}/config <<EOF
|
|
||||||
[source.local]
|
|
||||||
local-registry = "${WORKDIR}/cargo_registry"
|
|
||||||
[source.crates-io]
|
|
||||||
replace-with = "local"
|
|
||||||
registry = "https://github.com/rust-lang/crates.io-index"
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
cargo_util_do_compile () {
|
|
||||||
# prevent cargo from trying to fetch down new data
|
|
||||||
mkdir -p "${WORKDIR}/cargo_home/registry/index/github.com-1ecc6299db9ec823"
|
|
||||||
touch "${WORKDIR}/cargo_home/registry/index/github.com-1ecc6299db9ec823/.cargo-index-lock"
|
|
||||||
|
|
||||||
oe_cargo_fix_env
|
|
||||||
oe_cargo_build
|
|
||||||
}
|
|
||||||
|
|
||||||
cargo_util_do_install () {
|
|
||||||
local have_installed=false
|
|
||||||
for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do
|
|
||||||
if [[ $tgt == *.so || $tgt == *.rlib ]]; then
|
|
||||||
install -d "${D}${rustlibdir}"
|
|
||||||
install -m755 "$tgt" "${D}${rustlibdir}"
|
|
||||||
have_installed=true
|
|
||||||
elif [ -f "$tgt" ] && [ -x "$tgt" ]; then
|
|
||||||
install -d "${D}${bindir}"
|
|
||||||
install -m755 "$tgt" "${D}${bindir}"
|
|
||||||
have_installed=true
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if ! $have_installed; then
|
|
||||||
die "Did not find anything to install"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPORT_FUNCTIONS do_configure do_compile do_install
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
inherit cargo_util
|
inherit cargo
|
||||||
inherit patch
|
inherit patch
|
||||||
inherit rust-installer
|
inherit rust-installer
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ do_configure () {
|
|||||||
${EXTRA_OECONF} \
|
${EXTRA_OECONF} \
|
||||||
|| die "Could not configure cargo"
|
|| die "Could not configure cargo"
|
||||||
|
|
||||||
cargo_util_do_configure
|
cargo_do_configure
|
||||||
}
|
}
|
||||||
|
|
||||||
do_compile () {
|
do_compile () {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ SRC_URI += "\
|
|||||||
DEPENDS += "compiler-rt"
|
DEPENDS += "compiler-rt"
|
||||||
|
|
||||||
RUSTLIB_DEP = ""
|
RUSTLIB_DEP = ""
|
||||||
inherit cargo_util
|
inherit cargo
|
||||||
|
|
||||||
# Needed so cargo can find libbacktrace
|
# Needed so cargo can find libbacktrace
|
||||||
RUSTFLAGS += "-L ${STAGING_LIBDIR}"
|
RUSTFLAGS += "-L ${STAGING_LIBDIR}"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
inherit cargo_util
|
inherit cargo
|
||||||
|
|
||||||
SRC_URI = "git://github.com/jmesmon/rust-hello-world.git;protocol=https"
|
SRC_URI = "git://github.com/jmesmon/rust-hello-world.git;protocol=https"
|
||||||
SRCREV="e0fa23f1a3cb1eb1407165bd2fc36d2f6e6ad728"
|
SRCREV="e0fa23f1a3cb1eb1407165bd2fc36d2f6e6ad728"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
inherit cargo_util
|
inherit cargo
|
||||||
|
|
||||||
CARGO_INDEX_COMMIT = "3b3994e099281c394a6a66604d1af6c0920e4c31"
|
CARGO_INDEX_COMMIT = "3b3994e099281c394a6a66604d1af6c0920e4c31"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user