public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: kangie@gentoo.org
To: gentoo-dev@lists.gentoo.org
Cc: Matt Jolly <kangie@gentoo.org>
Subject: [gentoo-dev] [PATCH 02/10] cargo: update for rust eclass
Date: Wed,  6 Nov 2024 21:25:02 +1000	[thread overview]
Message-ID: <20241106112510.1518157-3-kangie@gentoo.org> (raw)
In-Reply-To: <20241106112510.1518157-1-kangie@gentoo.org>

From: Matt Jolly <kangie@gentoo.org>

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 <kangie@gentoo.org>
---
 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 <cardoe@gentoo.org>
 # Georgy Yakovlev <gyakovlev@gentoo.org>
 # @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



  parent reply	other threads:[~2024-11-06 11:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06 11:25 [gentoo-dev] [PATCH 00/10] new eclass: rust; slotting dev-lang/rust{-bin} kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 01/10] rust.eclass: Introduce new eclass for slotted Rust kangie
2024-11-07 17:56   ` Joonas Niilola
2024-11-06 11:25 ` kangie [this message]
2024-11-06 11:25 ` [gentoo-dev] [PATCH 03/10] dev-lang/rust: port to llvm-r1 and slot (-r100) kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 04/10] profiles/arch/mips: use.mask system-llvm on rust-1.71.1-r100 kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 05/10] dev-lang/rust-bin: llvm-r1 and slot (-r100) kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 06/10] dev-lang/rust{,-bin}: -r100: Drop the `profiler` USE kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 07/10] www-client/chromium: example chromium with slotted rust kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 08/10] www-client/firefox: add 132.0-r1 - rust and llvm-r1 eclasses kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 09/10] gnome-base/librsvg: rust eclass kangie
2024-11-06 11:25 ` [gentoo-dev] [PATCH 10/10] net-libs/rustls-ffi: rust slot kangie
2024-11-07 16:49 ` [gentoo-dev] [PATCH 00/10] new eclass: rust; slotting dev-lang/rust{-bin} Sam James

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241106112510.1518157-3-kangie@gentoo.org \
    --to=kangie@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox