diff options
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/Manifest.gz | bin | 39044 -> 39039 bytes | |||
-rw-r--r-- | eclass/cargo.eclass | 110 | ||||
-rw-r--r-- | eclass/rust.eclass | 2 | ||||
-rw-r--r-- | eclass/toolchain.eclass | 8 |
4 files changed, 114 insertions, 6 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz Binary files differindex cbd57797ff61..9ea669df974c 100644 --- a/eclass/Manifest.gz +++ b/eclass/Manifest.gz diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 95ff317e1f21..02b048732f7f 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -7,6 +7,7 @@ # @AUTHOR: # Doug Goldstein <cardoe@gentoo.org> # Georgy Yakovlev <gyakovlev@gentoo.org> +# Matt Jolly <kangie@gentoo.org> # @SUPPORTED_EAPIS: 8 # @PROVIDES: rust # @BLURB: common functions and variables for cargo builds @@ -30,6 +31,9 @@ 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 +# For reference the actual minimum version of cargo that can be used +# is 1.53.0 for `cargo update --offline`; updated to 1.71.1 with rust eclass. +# No need to enable usage of legacy rust versions in ebuilds; keep it as-is. _CARGO_ECLASS_RUST_MIN_VER="1.71.1" case ${EAPI} in @@ -37,8 +41,10 @@ case ${EAPI} in 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}" + if [[ -z ${CARGO_BOOTSTRAP} ]]; then + 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 fi else RUST_MIN_VER="${_CARGO_ECLASS_RUST_MIN_VER}" @@ -46,6 +52,10 @@ case ${EAPI} in ;; esac +if [[ -n ${CRATE_PATHS_OVERRIDE} ]]; then + CRATES="${CRATES} ${CRATE_PATHS_OVERRIDE}" +fi + inherit flag-o-matic multiprocessing rust rust-toolchain toolchain-funcs IUSE="${IUSE} debug" @@ -76,6 +86,41 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" # SRC_URI="${CARGO_CRATE_URIS}" # @CODE +# @ECLASS_VARIABLE: CRATE_PATHS_OVERRIDE +# @DEFAULT_UNSET +# @PRE_INHERIT +# @DESCRIPTION: +# Bash string containing crates that will be used to override +# dependencies via generated `paths = ['/path/to/crate']` configuration. +# This is not "smart", _all crates_ which match the `Cargo.toml` +# for a given crate/path will be overridden, ignoring lockfiles, +# version constraints, etc. +# +# This should be used as a last resort where (e.g.) you are +# bootstrapping Rust and need to override a vendored crate +# with a newer version, and all versions in use are compatible. +# +# Crate names and versions must be separated by a `@`; +# multiple crates are separated by a space or newline. +# Crates in CRATE_PATHS_OVERRIDE are implicitly added to CRATES; +# they do not need to be listed. +# +# Example: +# @CODE +# CRATES=" +# foo@1.2.3 +# " +# +# CRATE_PATHS_OVERRIDE=" +# openssl@0.10.35 +# openssl-sys@0.9.65 +# " +# +# inherit cargo +# ... +# SRC_URI="${CARGO_CRATE_URIS}" +# @CODE + # @ECLASS_VARIABLE: GIT_CRATES # @DEFAULT_UNSET # @PRE_INHERIT @@ -109,6 +154,13 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" # ) # @CODE +# @ECLASS_VARIABLE: CARGO_BOOTSTRAP +# @DEFAULT_UNSET +# @PRE_INHERIT +# @DESCRIPTION: +# Ignore `_CARGO_ECLASS_RUST_MIN_VER` checks. +# If you aren't bootstrapping Rust you probably don't need this. + # @ECLASS_VARIABLE: CARGO_OPTIONAL # @DEFAULT_UNSET # @PRE_INHERIT @@ -265,6 +317,26 @@ cargo_crate_uris() { echo "${CARGO_CRATE_URIS}" } +# @FUNCTION: _cargo_gen_override_paths_config +# @INTERNAL +# @DESCRIPTION: +# Generate the TOML content for overriding crates globally using the package manager. +# This is called from within cargo_gen_config to insert the appropriate snippet +# into the generated config.toml. Does not support git crates. +_cargo_gen_override_paths_config() { + if [[ ! ${#CRATE_PATHS_OVERRIDE[@]} -gt 0 ]]; then + return + fi + local content override path + content=( 'paths = [' ) + for override in ${CRATE_PATHS_OVERRIDE}; do + local path="${ECARGO_VENDOR}/${override//@/-}" + content+=( "'${path}'," ) + done + content+=( ']' ) + printf "%s\n" "${content[@]}" +} + # @FUNCTION: cargo_gen_config # @DESCRIPTION: # Generate the $CARGO_HOME/config.toml necessary to use our local registry and settings. @@ -281,6 +353,8 @@ cargo_gen_config() { mkdir -p "${ECARGO_HOME}" || die cat > "${ECARGO_HOME}/config.toml" <<- _EOF_ || die "Failed to create cargo config" + $(_cargo_gen_override_paths_config) + [source.gentoo] directory = "${ECARGO_VENDOR}" @@ -299,6 +373,7 @@ cargo_gen_config() { verbose = true $([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'") $(_cargo_gen_git_config) + _EOF_ export CARGO_HOME="${ECARGO_HOME}" @@ -346,6 +421,37 @@ cargo_target_dir() { echo "${CARGO_TARGET_DIR:-target}/$(rust_abi)/$(usex debug debug release)" } +# @FUNCTION: cargo_update_crates +# @USAGE: +# @DESCRIPTION: +# Helper function to call `cargo update --offline` with the given Cargo.toml. +# This will update Cargo.{toml,lock}. This should provide a straightforward +# approach to updating vulnerable crates in a package. +# +# To use: replace any vulnerable crates in ${CRATES} with updated (and compatible) +# versions, then call `cargo_update_crates` in src_prepare. If Cargo.toml is not +# in the root of ${S}, pass the path to the Cargo.toml as the first argument. +# It is up to the ebuild to ensure that the updated crates are compatible with the +# package and that no unexpected breakage occurs. +cargo_update_crates () { + debug-print-function ${FUNCNAME} "$@" + + if [[ -z ${CARGO} ]]; then + die "CARGO is not set; was rust_pkg_setup run?" + fi + + local path=${1:-"${S}/Cargo.toml"} + if [[ $# -gt 1 ]]; then + die "Usage: cargo_update_crates [path_to_Cargo.toml]" + fi + [[ -f ${path} ]] || die "${path} does not exist" + + set -- "${CARGO}" update --offline --manifest-path "${path}" + einfo "${@}" + # This is overkill (we're not using rustflags (etc) here) but it's safe. + cargo_env "${@}" || die "Failed to update crates" +} + # @FUNCTION: cargo_src_unpack # @DESCRIPTION: # Unpacks the package and the cargo registry. diff --git a/eclass/rust.eclass b/eclass/rust.eclass index 68983f688e42..71cbb4b24f8c 100644 --- a/eclass/rust.eclass +++ b/eclass/rust.eclass @@ -76,6 +76,7 @@ declare -A -g -r _RUST_LLVM_MAP=( ["1.75.0"]=17 ["1.74.1"]=17 ["1.71.1"]=16 + ["1.54.0"]=12 ) # @ECLASS_VARIABLE: _RUST_SLOTS_ORDERED @@ -94,6 +95,7 @@ declare -a -g -r _RUST_SLOTS_ORDERED=( "1.75.0" "1.74.1" "1.71.1" + "1.54.0" ) # == control variables == diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass index 114a008b700f..be8bfcddfafd 100644 --- a/eclass/toolchain.eclass +++ b/eclass/toolchain.eclass @@ -338,7 +338,7 @@ if [[ ${PN} != kgcc64 && ${PN} != gcc-* ]] ; then # it was disabled in 13. tc_version_is_at_least 14.0.0_pre20230423 ${PV} && IUSE+=" rust" TC_FEATURES+=( rust ) tc_version_is_at_least 14.2.1_p20241026 ${PV} && IUSE+=" time64" - tc_version_is_at_least 15.0.0_pre20241124 ${PV} && IUSE+=" libdiagnostics" + tc_version_is_at_least 15.0.0_pre20241124 ${PV} && IUSE+=" libgdiagnostics" fi if tc_version_is_at_least 10; then @@ -1836,8 +1836,8 @@ toolchain_src_configure() { gcc_shell="${BROOT}"/bin/sh fi - if is_jit || _tc_use_if_iuse libdiagnostics ; then - einfo "Configuring shared gcc for JIT/libdiagnostics" + if is_jit || _tc_use_if_iuse libgdiagnostics ; then + einfo "Configuring shared gcc for JIT/libgdiagnostics" local confgcc_jit=( "${confgcc[@]}" @@ -1874,7 +1874,7 @@ toolchain_src_configure() { ) if tc_version_is_at_least 15.0.0_pre20241124 ${PV} ; then - confgcc_jit+=( $(use_enable libdiagnostics) ) + confgcc_jit+=( $(use_enable libgdiagnostics) ) fi if tc_version_is_at_least 13.1 ; then |