mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 21:46:58 +02:00
cargo.eclass: Sync with Gentoo
Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
This commit is contained in:
parent
e90451ff2b
commit
2c2ecc997a
@ -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_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
|
FLATCAR_SDK_VERSION=4000.0.0+nightly-20240613-2100
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
# @AUTHOR:
|
# @AUTHOR:
|
||||||
# Doug Goldstein <cardoe@gentoo.org>
|
# Doug Goldstein <cardoe@gentoo.org>
|
||||||
# Georgy Yakovlev <gyakovlev@gentoo.org>
|
# Georgy Yakovlev <gyakovlev@gentoo.org>
|
||||||
# @SUPPORTED_EAPIS: 7 8
|
# @SUPPORTED_EAPIS: 8
|
||||||
# @BLURB: common functions and variables for cargo builds
|
# @BLURB: common functions and variables for cargo builds
|
||||||
|
|
||||||
case ${EAPI} in
|
case ${EAPI} in
|
||||||
7|8) ;;
|
8) ;;
|
||||||
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -23,10 +23,6 @@ _CARGO_ECLASS=1
|
|||||||
RUST_DEPEND="virtual/rust"
|
RUST_DEPEND="virtual/rust"
|
||||||
|
|
||||||
case ${EAPI} in
|
case ${EAPI} in
|
||||||
7)
|
|
||||||
# 1.37 added 'cargo vendor' subcommand and net.offline config knob
|
|
||||||
RUST_DEPEND=">=virtual/rust-1.37.0"
|
|
||||||
;;
|
|
||||||
8)
|
8)
|
||||||
# 1.39 added --workspace
|
# 1.39 added --workspace
|
||||||
# 1.46 added --target dir
|
# 1.46 added --target dir
|
||||||
@ -38,7 +34,7 @@ case ${EAPI} in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
inherit flag-o-matic multiprocessing toolchain-funcs
|
inherit flag-o-matic multiprocessing rust-toolchain toolchain-funcs
|
||||||
|
|
||||||
[[ ! ${CARGO_OPTIONAL} ]] && BDEPEND="${RUST_DEPEND}"
|
[[ ! ${CARGO_OPTIONAL} ]] && BDEPEND="${RUST_DEPEND}"
|
||||||
|
|
||||||
@ -52,7 +48,7 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
|
|||||||
# @PRE_INHERIT
|
# @PRE_INHERIT
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Bash string containing all crates that are to be downloaded.
|
# 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 `@`
|
# Ideally, crate names and versions should be separated by a `@`
|
||||||
# character. A legacy syntax using hyphen is also supported but it is
|
# character. A legacy syntax using hyphen is also supported but it is
|
||||||
@ -323,45 +319,65 @@ _cargo_gen_git_config() {
|
|||||||
fi
|
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
|
# @FUNCTION: cargo_src_unpack
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Unpacks the package and the cargo registry.
|
# Unpacks the package and the cargo registry.
|
||||||
cargo_src_unpack() {
|
cargo_src_unpack() {
|
||||||
debug-print-function ${FUNCNAME} "$@"
|
debug-print-function ${FUNCNAME} "$@"
|
||||||
|
|
||||||
mkdir -p "${ECARGO_VENDOR}" || die
|
mkdir -p "${ECARGO_VENDOR}" "${S}" || die
|
||||||
mkdir -p "${S}" || die
|
|
||||||
|
|
||||||
local archive shasum pkg
|
local archive shasum pkg
|
||||||
|
local crates=()
|
||||||
for archive in ${A}; do
|
for archive in ${A}; do
|
||||||
case "${archive}" in
|
case "${archive}" in
|
||||||
*.crate)
|
*.crate)
|
||||||
# when called by pkgdiff-mg, do not unpack crates
|
crates+=( "${archive}" )
|
||||||
[[ ${PKGBUMPING} == ${PVR} ]] && continue
|
;;
|
||||||
|
*)
|
||||||
|
unpack "${archive}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
ebegin "Loading ${archive} into Cargo registry"
|
if [[ ${PKGBUMPING} != ${PVR} && ${crates[@]} ]]; then
|
||||||
tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_VENDOR}/" || die
|
pushd "${DISTDIR}" >/dev/null || die
|
||||||
# generate sha256sum of the crate itself as cargo needs this
|
|
||||||
shasum=$(sha256sum "${DISTDIR}"/${archive} | cut -d ' ' -f 1)
|
ebegin "Unpacking crates"
|
||||||
pkg=$(basename ${archive} .crate)
|
printf '%s\0' "${crates[@]}" |
|
||||||
cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json
|
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}",
|
"package": "${shasum}",
|
||||||
"files": {}
|
"files": {}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# if this is our target package we need it in ${WORKDIR} too
|
# if this is our target package we need it in ${WORKDIR} too
|
||||||
# to make ${S} (and handle any revisions too)
|
# to make ${S} (and handle any revisions too)
|
||||||
if [[ ${P} == ${pkg}* ]]; then
|
if [[ ${P} == ${pkg}* ]]; then
|
||||||
tar -xf "${DISTDIR}"/${archive} -C "${WORKDIR}" || die
|
tar -xf "${archive}" -C "${WORKDIR}" || die
|
||||||
|
fi
|
||||||
|
done < <(sha256sum -z "${crates[@]}" || die)
|
||||||
|
|
||||||
|
popd >/dev/null || die
|
||||||
fi
|
fi
|
||||||
eend $?
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
unpack ${archive}
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
cargo_gen_config
|
cargo_gen_config
|
||||||
}
|
}
|
||||||
@ -519,6 +535,21 @@ cargo_src_compile() {
|
|||||||
filter-lto
|
filter-lto
|
||||||
tc-export AR CC CXX PKG_CONFIG
|
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[@]} "$@"
|
set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
|
||||||
einfo "${@}"
|
einfo "${@}"
|
||||||
"${@}" || die "cargo build failed"
|
"${@}" || die "cargo build failed"
|
||||||
@ -546,17 +577,6 @@ cargo_src_install() {
|
|||||||
|
|
||||||
rm -f "${ED}/usr/.crates.toml" || die
|
rm -f "${ED}/usr/.crates.toml" || die
|
||||||
rm -f "${ED}/usr/.crates2.json" || 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
|
# @FUNCTION: cargo_src_test
|
||||||
|
Loading…
Reference in New Issue
Block a user