From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E963B158042 for ; Wed, 6 Nov 2024 11:26:50 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 97112E09AE; Wed, 6 Nov 2024 11:26:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 60F21E09A8 for ; Wed, 6 Nov 2024 11:26:20 +0000 (UTC) From: kangie@gentoo.org To: gentoo-dev@lists.gentoo.org Cc: Matt Jolly Subject: [gentoo-dev] [PATCH 02/10] cargo: update for rust eclass Date: Wed, 6 Nov 2024 21:25:02 +1000 Message-ID: <20241106112510.1518157-3-kangie@gentoo.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106112510.1518157-1-kangie@gentoo.org> References: <20241106112510.1518157-1-kangie@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 5503d3a7-a3fa-40d6-871e-8c7b474f7af0 X-Archives-Hash: 6280f7e2bbc3a6f6117dc9706b77536a From: Matt Jolly Inherit the rust eclass and take advantage of eclass features like `RUST_MIN_VER`. Also replace calls to `cargo` with the rust eclass exported ${CARGO}. If used without llvm-r1 (typical usage) an || dependency on Rust slots (between `RUST_M{AX,IN}_VER` if set) will be added. If intending to use with llvm-r1 for a tight dependency, set `RUST_NEEDS_LLVM` to automatically add a `llvm_slot_X` USE gated Rust dependency for each slot in LLVM_COMPAT to BDEPEND. This respects `RUST_M{AX,IN}_VER`. Signed-off-by: Matt Jolly --- eclass/cargo.eclass | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 499fe5498c96..c74c2b29045c 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -8,6 +8,7 @@ # Doug Goldstein # Georgy Yakovlev # @SUPPORTED_EAPIS: 8 +# @PROVIDES: rust # @BLURB: common functions and variables for cargo builds case ${EAPI} in @@ -18,23 +19,39 @@ esac if [[ -z ${_CARGO_ECLASS} ]]; then _CARGO_ECLASS=1 -# check and document RUST_DEPEND and options we need below in case conditions. +if [[ -n ${RUST_NEEDS_LLVM} ]]; then + if [[ -z ${_LLVM_R1_ECLASS} ]]; then + die "Please inherit llvm-r1.eclass before cargo.eclass when using RUST_NEEDS_LLVM" + fi +fi + +# Either the lowest slot supported by rust.eclass _or_ +# reference the changelog for a particular feature requirement # https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md -RUST_DEPEND="virtual/rust" +_CARGO_ECLASS_RUST_MIN_VER="1.71.1" case ${EAPI} in 8) - # 1.39 added --workspace - # 1.46 added --target dir - # 1.48 added term.progress config option - # 1.51 added split-debuginfo profile option - # 1.52 may need setting RUSTC_BOOTSTRAP envvar for some crates - # 1.53 added cargo update --offline, can be used to update vulnerable crates from pre-fetched registry without editing toml - RUST_DEPEND=">=virtual/rust-1.53" + if [[ -n ${RUST_MIN_VER} ]]; then + # This is _very_ unlikely given that we leverage the rust eclass but just in case cargo requires a newer version + # than the oldest in-tree in future. + if ver_test "${RUST_MIN_VER}" -lt "${_CARGO_ECLASS_RUST_MIN_VER}"; then + die "RUST_MIN_VERSION must be at least ${_CARGO_ECLASS_RUST_MIN_VER}" + fi + else + RUST_MIN_VER=${_CARGO_ECLASS_RUST_MIN_VER} + fi ;; esac -inherit flag-o-matic multiprocessing rust-toolchain toolchain-funcs +inherit flag-o-matic multiprocessing rust rust-toolchain toolchain-funcs + +if [[ -n ${RUST_NEEDS_LLVM} ]]; then + # Generate llvm_slot_x USE-gated deps for each slot in LLVM_COMPAT + RUST_DEPEND="${RUST_LLVM_DEPEND}" +else + RUST_DEPEND="$(rust_gen_dep)" +fi [[ ! ${CARGO_OPTIONAL} ]] && BDEPEND="${RUST_DEPEND}" @@ -531,6 +548,9 @@ cargo_src_configure() { # take affect due to Cargo limitations, so add these to your ebuild's RUSTFLAGS # if they seem important. cargo_env() { + + debug-print-function ${FUNCNAME} "$@" + [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" @@ -604,7 +624,7 @@ cargo_env() { cargo_src_compile() { debug-print-function ${FUNCNAME} "$@" - set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" + set -- ${CARGO} build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" cargo_env "${@}" || die "cargo build failed" } @@ -618,7 +638,7 @@ cargo_src_compile() { cargo_src_install() { debug-print-function ${FUNCNAME} "$@" - set -- cargo install $(has --path ${@} || echo --path ./) \ + set -- ${CARGO} install $(has --path ${@} || echo --path ./) \ --root "${ED}/usr" \ ${GIT_CRATES[@]:+--frozen} \ $(usex debug --debug "") \ @@ -636,7 +656,7 @@ cargo_src_install() { cargo_src_test() { debug-print-function ${FUNCNAME} "$@" - set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" + set -- ${CARGO} test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" cargo_env "${@}" || die "cargo test failed" } -- 2.47.0