cargo.eclass: Sync with Gentoo

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
This commit is contained in:
James Le Cuirot 2024-06-17 11:02:48 +01:00
parent e90451ff2b
commit 2c2ecc997a
No known key found for this signature in database
GPG Key ID: 1226415D00DD3137
2 changed files with 64 additions and 44 deletions

View File

@ -1,4 +1,4 @@
FLATCAR_VERSION=4000.0.0+nightly-20240613-2100
FLATCAR_VERSION=4000.0.0+nightly-20240613-2100-10-ga2901d9a72
FLATCAR_VERSION_ID=4000.0.0
FLATCAR_BUILD_ID="nightly-20240613-2100"
FLATCAR_BUILD_ID="nightly-20240613-2100-10-ga2901d9a72"
FLATCAR_SDK_VERSION=4000.0.0+nightly-20240613-2100

View File

@ -7,11 +7,11 @@
# @AUTHOR:
# Doug Goldstein <cardoe@gentoo.org>
# Georgy Yakovlev <gyakovlev@gentoo.org>
# @SUPPORTED_EAPIS: 7 8
# @SUPPORTED_EAPIS: 8
# @BLURB: common functions and variables for cargo builds
case ${EAPI} in
7|8) ;;
8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
@ -23,10 +23,6 @@ _CARGO_ECLASS=1
RUST_DEPEND="virtual/rust"
case ${EAPI} in
7)
# 1.37 added 'cargo vendor' subcommand and net.offline config knob
RUST_DEPEND=">=virtual/rust-1.37.0"
;;
8)
# 1.39 added --workspace
# 1.46 added --target dir
@ -38,7 +34,7 @@ case ${EAPI} in
;;
esac
inherit flag-o-matic multiprocessing toolchain-funcs
inherit flag-o-matic multiprocessing rust-toolchain toolchain-funcs
[[ ! ${CARGO_OPTIONAL} ]] && BDEPEND="${RUST_DEPEND}"
@ -52,7 +48,7 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
# @PRE_INHERIT
# @DESCRIPTION:
# Bash string containing all crates that are to be downloaded.
# It is used by cargo_crate_uris.
# It is used by cargo_crate_uris. Typically generated by app-portage/pycargoebuild.
#
# Ideally, crate names and versions should be separated by a `@`
# character. A legacy syntax using hyphen is also supported but it is
@ -323,46 +319,66 @@ _cargo_gen_git_config() {
fi
}
# @FUNCTION: cargo_target_dir
# @DESCRIPTION:
# Return the directory within target that contains the build, e.g.
# target/aarch64-unknown-linux-gnu/release.
cargo_target_dir() {
local abi
tc-is-cross-compiler && abi=/$(rust_abi)
echo "${CARGO_TARGET_DIR:-target}${abi}/$(usex debug debug release)"
}
# @FUNCTION: cargo_src_unpack
# @DESCRIPTION:
# Unpacks the package and the cargo registry.
cargo_src_unpack() {
debug-print-function ${FUNCNAME} "$@"
mkdir -p "${ECARGO_VENDOR}" || die
mkdir -p "${S}" || die
mkdir -p "${ECARGO_VENDOR}" "${S}" || die
local archive shasum pkg
local crates=()
for archive in ${A}; do
case "${archive}" in
*.crate)
# when called by pkgdiff-mg, do not unpack crates
[[ ${PKGBUMPING} == ${PVR} ]] && continue
ebegin "Loading ${archive} into Cargo registry"
tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_VENDOR}/" || die
# generate sha256sum of the crate itself as cargo needs this
shasum=$(sha256sum "${DISTDIR}"/${archive} | cut -d ' ' -f 1)
pkg=$(basename ${archive} .crate)
cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json
{
"package": "${shasum}",
"files": {}
}
EOF
# if this is our target package we need it in ${WORKDIR} too
# to make ${S} (and handle any revisions too)
if [[ ${P} == ${pkg}* ]]; then
tar -xf "${DISTDIR}"/${archive} -C "${WORKDIR}" || die
fi
eend $?
crates+=( "${archive}" )
;;
*)
unpack ${archive}
unpack "${archive}"
;;
esac
done
if [[ ${PKGBUMPING} != ${PVR} && ${crates[@]} ]]; then
pushd "${DISTDIR}" >/dev/null || die
ebegin "Unpacking crates"
printf '%s\0' "${crates[@]}" |
xargs -0 -P "$(makeopts_jobs)" -n 1 -t -- \
tar -x -C "${ECARGO_VENDOR}" -f
assert
eend $?
while read -d '' -r shasum archive; do
pkg=${archive%.crate}
cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json || die
{
"package": "${shasum}",
"files": {}
}
EOF
# if this is our target package we need it in ${WORKDIR} too
# to make ${S} (and handle any revisions too)
if [[ ${P} == ${pkg}* ]]; then
tar -xf "${archive}" -C "${WORKDIR}" || die
fi
done < <(sha256sum -z "${crates[@]}" || die)
popd >/dev/null || die
fi
cargo_gen_config
}
@ -519,6 +535,21 @@ cargo_src_compile() {
filter-lto
tc-export AR CC CXX PKG_CONFIG
if tc-is-cross-compiler; then
export CARGO_BUILD_TARGET=$(rust_abi)
local TRIPLE=${CARGO_BUILD_TARGET//-/_}
export CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC)
# Set vars for cc-rs crate.
tc-export_build_env
export \
HOST_AR=$(tc-getBUILD_AR)
HOST_CC=$(tc-getBUILD_CC)
HOST_CXX=$(tc-getBUILD_CXX)
HOST_CFLAGS=${BUILD_CFLAGS}
HOST_CXXFLAGS=${BUILD_CXXFLAGS}
fi
set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
einfo "${@}"
"${@}" || die "cargo build failed"
@ -546,17 +577,6 @@ cargo_src_install() {
rm -f "${ED}/usr/.crates.toml" || die
rm -f "${ED}/usr/.crates2.json" || die
# it turned out to be non-standard dir, so get rid of it future EAPI
# and only run for EAPI=7
# https://bugs.gentoo.org/715890
case ${EAPI:-0} in
7)
if [ -d "${S}/man" ]; then
doman "${S}/man" || return 0
fi
;;
esac
}
# @FUNCTION: cargo_src_test