From 625574f70212d097e82a1cfcc34ee09ca467306e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 5 Aug 2024 15:57:53 +0200 Subject: [PATCH 01/15] toolchain-funcs.eclass: Fix tc-is-lto not to leave stray files in T MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix tc-is-lto function to remove the temporary file after testing. Besides being cleaner, this fixes a permission problem when using Paludis and tc-is-lto is used both in pkg_setup() (which creates the temporary file owned by root) and src_*() phase (which attempts to rewrite it as a regular user). Thanks to negril for the report! Signed-off-by: Michał Górny --- eclass/toolchain-funcs.eclass | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index cde84e6f34c8a..e73af9772938f 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -1234,6 +1234,7 @@ tc-get-build-ptr-size() { # @RETURN: Shell true if we are using LTO, shell false otherwise tc-is-lto() { local f="${T}/test-lto.o" + local ret=1 case $(tc-get-compiler-type) in clang) @@ -1241,14 +1242,15 @@ tc-is-lto() { # If LTO is used, clang will output bytecode and llvm-bcanalyzer # will run successfully. Otherwise, it will output plain object # file and llvm-bcanalyzer will exit with error. - llvm-bcanalyzer "${f}" &>/dev/null && return 0 + llvm-bcanalyzer "${f}" &>/dev/null && ret=0 ;; gcc) $(tc-getCC) ${CFLAGS} -c -o "${f}" -x c - <<<"" || die - [[ $($(tc-getREADELF) -S "${f}") == *.gnu.lto* ]] && return 0 + [[ $($(tc-getREADELF) -S "${f}") == *.gnu.lto* ]] && ret=0 ;; esac - return 1 + rm -f "${f}" || die + return "${ret}" } fi From f14c9139aac5679ad4827e4b69d8bc6a5e3042cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 5 Aug 2024 16:06:43 +0200 Subject: [PATCH 02/15] eclass/tests/toolchain-funcs.sh: Cover tc-is-lto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny Closes: https://github.com/gentoo/gentoo/pull/37976 Signed-off-by: Michał Górny --- eclass/tests/toolchain-funcs.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index ee10ddf50c1ec..6bfb00ff6bcb9 100755 --- a/eclass/tests/toolchain-funcs.sh +++ b/eclass/tests/toolchain-funcs.sh @@ -210,6 +210,16 @@ if type -P gcc &>/dev/null; then tbegin "tc-get-c-rtlib (gcc)" [[ $(CC=gcc tc-get-c-rtlib) == libgcc ]] tend $? + + tbegin "tc-is-lto (gcc, -fno-lto)" + CC=gcc CFLAGS=-fno-lto tc-is-lto + [[ $? -eq 1 ]] + tend $? + + tbegin "tc-is-lto (gcc, -flto)" + CC=gcc CFLAGS=-flto tc-is-lto + [[ $? -eq 0 ]] + tend $? fi if type -P clang &>/dev/null; then @@ -232,6 +242,16 @@ if type -P clang &>/dev/null; then [[ $(CC=clang CFLAGS="--rtlib=${rtlib}" tc-get-c-rtlib) == ${rtlib} ]] tend $? done + + tbegin "tc-is-lto (clang, -fno-lto)" + CC=clang CFLAGS=-fno-lto tc-is-lto + [[ $? -eq 1 ]] + tend $? + + tbegin "tc-is-lto (clang, -flto)" + CC=clang CFLAGS=-flto tc-is-lto + [[ $? -eq 0 ]] + tend $? fi texit From 9c0708dcae5ef0792e2273968f6f6ff45d90b11f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 13 Jun 2024 17:17:07 +0200 Subject: [PATCH 03/15] toolchain-funcs.eclass: Add tc-has-64bit-time_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a helper function to check whether time_t is 64-bit. This could be used e.g. to deselect tests that rely on timestamps exceeding Y2k38. It is meant to be more future-proof than hardcoding a list of 32-bit architectures, given the necessity of switching to 64-bit time_t in the future. Signed-off-by: Michał Górny --- eclass/toolchain-funcs.eclass | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index e73af9772938f..9f0953c079e3f 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -1,4 +1,4 @@ -# Copyright 2002-2023 Gentoo Authors +# Copyright 2002-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: toolchain-funcs.eclass @@ -1253,4 +1253,14 @@ tc-is-lto() { return "${ret}" } +# @FUNCTION: tc-has-64bit-time_t +# @RETURN: Shell true if time_t is at least 64 bits long, false otherwise +tc-has-64bit-time_t() { + $(tc-getCC) ${CFLAGS} ${CPPFLAGS} -c -x c - -o /dev/null <<-EOF &>/dev/null + #include + int test[sizeof(time_t) >= 8 ? 1 : -1]; + EOF + return $? +} + fi From 69190f6268a2a6942e5a266a45e2b353cf617569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 6 Aug 2024 08:27:14 +0200 Subject: [PATCH 04/15] eclass/tests/toolchain-funcs.sh: Cover tc-has-64bit-time_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny Closes: https://github.com/gentoo/gentoo/pull/37142 Signed-off-by: Michał Górny --- eclass/tests/toolchain-funcs.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index 6bfb00ff6bcb9..0d6745862148e 100755 --- a/eclass/tests/toolchain-funcs.sh +++ b/eclass/tests/toolchain-funcs.sh @@ -220,6 +220,26 @@ if type -P gcc &>/dev/null; then CC=gcc CFLAGS=-flto tc-is-lto [[ $? -eq 0 ]] tend $? + + case $(gcc -dumpmachine) in + i*86*-gnu*|arm*-gnu*|powerpc-*-gnu) + tbegin "tc-has-64bit-time_t (_TIME_BITS=32)" + CC=gcc CFLAGS="-U_TIME_BITS -D_TIME_BITS=32" tc-has-64bit-time_t + [[ $? -eq 1 ]] + tend $? + + tbegin "tc-has-64bit-time_t (_TIME_BITS=64)" + CC=gcc CFLAGS="-U_FILE_OFFSET_BITS -U_TIME_BITS -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" tc-has-64bit-time_t + [[ $? -eq 0 ]] + tend $? + ;; + *) + tbegin "tc-has-64bit-time_t" + CC=gcc tc-has-64bit-time_t + [[ $? -eq 0 ]] + tend $? + ;; + esac fi if type -P clang &>/dev/null; then From 9411d6eddbc9e1375542fd0058ee7dc9007d48ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 24 Jul 2024 20:35:54 +0200 Subject: [PATCH 05/15] distutils-r1.eclass: Fix disabling DISTUTILS_ALLOW_WHEEL_REUSE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the declaration of DISTUTILS_ALLOW_WHEEL_REUSE to allow disabling it via setting the variable to an empty value in the environment. Signed-off-by: Michał Górny --- eclass/distutils-r1.eclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index fa8edb5cdfb77..4afee3d45b1cf 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -204,7 +204,7 @@ esac # This is an optimization that can avoid the overhead of calling into # the build system in pure Python packages and packages using the stable # Python ABI. -DISTUTILS_ALLOW_WHEEL_REUSE=1 +: ${DISTUTILS_ALLOW_WHEEL_REUSE=1} # @ECLASS_VARIABLE: BUILD_DIR # @OUTPUT_VARIABLE From 9b1ccc14f4a6e9b6c614a4c5f5d6ec15f6339d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 31 Jul 2024 09:46:21 +0200 Subject: [PATCH 06/15] python-utils-r1.eclass: Add a sanity check for PYTHONPATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a sanity check that ensures that PYTHONPATH does not contain any relative paths. While at it, also explicitly warn about PYTHONPATH being set, so we know about it in build logs. Signed-off-by: Michał Górny --- eclass/distutils-r1.eclass | 1 + eclass/python-any-r1.eclass | 3 ++- eclass/python-r1.eclass | 2 ++ eclass/python-single-r1.eclass | 3 ++- eclass/python-utils-r1.eclass | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index 4afee3d45b1cf..5d9f97474b294 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -936,6 +936,7 @@ _distutils-r1_print_package_versions() { # distutils patches and/or quirks. distutils-r1_python_prepare_all() { debug-print-function ${FUNCNAME} "${@}" + _python_sanity_checks _distutils-r1_check_all_phase_mismatch if [[ ! ${DISTUTILS_OPTIONAL} ]]; then diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass index a21df8e89498f..c1f27cfbac0d8 100644 --- a/eclass/python-any-r1.eclass +++ b/eclass/python-any-r1.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2023 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: python-any-r1.eclass @@ -272,6 +272,7 @@ python_gen_any_dep() { # This function will call python_check_deps() if defined. python_setup() { debug-print-function ${FUNCNAME} "${@}" + _python_sanity_checks # support developer override if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass index c5fa6770558f2..adf87c2c52f76 100644 --- a/eclass/python-r1.eclass +++ b/eclass/python-r1.eclass @@ -617,6 +617,7 @@ _python_multibuild_wrapper() { # locally, and the former two are exported to the command environment. python_foreach_impl() { debug-print-function ${FUNCNAME} "${@}" + _python_sanity_checks if [[ ${_DISTUTILS_R1_ECLASS} ]]; then if has "${EBUILD_PHASE}" prepare configure compile test install && @@ -708,6 +709,7 @@ python_foreach_impl() { # @CODE python_setup() { debug-print-function ${FUNCNAME} "${@}" + _python_sanity_checks local has_check_deps declare -f python_check_deps >/dev/null && has_check_deps=1 diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass index 4d61f08c06f00..481b6cf91ba07 100644 --- a/eclass/python-single-r1.eclass +++ b/eclass/python-single-r1.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2022 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: python-single-r1.eclass @@ -393,6 +393,7 @@ python_gen_impl_dep() { # the Python build environment up for it. python_setup() { debug-print-function ${FUNCNAME} "${@}" + _python_sanity_checks unset EPYTHON diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index c47565fa1db2a..cc33a1c1bffdd 100644 --- a/eclass/python-utils-r1.eclass +++ b/eclass/python-utils-r1.eclass @@ -1544,4 +1544,38 @@ python_has_version() { return 0 } +# @FUNCTION: _python_sanity_checks +# @INTERNAL +# @DESCRIPTION: +# Perform additional environment sanity checks. +_python_sanity_checks() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${_PYTHON_SANITY_CHECKED} ]] && return + + if [[ -v PYTHONPATH ]]; then + local x paths=() + mapfile -d ':' -t paths <<<${PYTHONPATH} + + for x in "${paths[@]}"; do + if [[ ${x} != /* ]]; then + eerror "Relative path found in PYTHONPATH:" + eerror + eerror " PYTHONPATH=${PYTHONPATH@Q}" + eerror + eerror "This is guaranteed to cause random breakage. Please make sure that" + eerror "your PYTHONPATH contains absolute paths only (and only if necessary)." + eerror "Note that empty values (including ':' at either end and an empty" + eerror "PYTHONPATH) count as the current directory. If no PYTHONPATH" + eerror "is intended, it needs to be unset instead." + die "Relative paths in PYTHONPATH are forbidden: ${x@Q}" + fi + done + + elog "PYTHONPATH=${PYTHONPATH@Q}" + fi + + _PYTHON_SANITY_CHECKED=1 +} + fi From d57601effef63b266afe7df5c8cb7dae52fa44ac Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 25 Jul 2024 18:34:45 +0100 Subject: [PATCH 07/15] cargo.eclass: Use newer Cargo config file name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "config" is deprecated and "config.toml" has been valid for ages. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/cargo.eclass | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 7db34efb4e174..aab28dbbac167 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -248,7 +248,7 @@ cargo_crate_uris() { # @FUNCTION: cargo_gen_config # @DESCRIPTION: -# Generate the $CARGO_HOME/config necessary to use our local registry and settings. +# Generate the $CARGO_HOME/config.toml necessary to use our local registry and settings. # Cargo can also be configured through environment variables in addition to the TOML syntax below. # For each configuration key below of the form foo.bar the environment variable CARGO_FOO_BAR # can also be used to define the value. @@ -261,7 +261,7 @@ cargo_gen_config() { mkdir -p "${ECARGO_HOME}" || die - cat > "${ECARGO_HOME}/config" <<- _EOF_ || die "Failed to create cargo config" + cat > "${ECARGO_HOME}/config.toml" <<- _EOF_ || die "Failed to create cargo config" [source.gentoo] directory = "${ECARGO_VENDOR}" From 11e91de6642a4b329566bb21b3a58a083994745f Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 24 Jul 2024 15:26:34 +0100 Subject: [PATCH 08/15] cargo.eclass: Add cargo_env helper and use it in compile, test, install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust packages have a tendency to rebuild parts during test and install. It is not clear whether this can be addressed. We were therefore relying on some environment variables set during the compile phase for cross-compiling to work in the later phases. This is not ideal, especially if you need to build for multiple targets. These environment variables can also be useful in other contexts, such as the build runner in app-misc/anki. This change moves the setting of these variables into a separate helper that is now used in all these phases and can be used by ebuilds too. The variables are now kept local to each invocation of this helper, preventing leakage. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/cargo.eclass | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index aab28dbbac167..de4a012354eef 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -523,6 +523,33 @@ cargo_src_configure() { [[ ${ECARGO_ARGS[@]} ]] && einfo "Configured with: ${ECARGO_ARGS[@]}" } +# @FUNCTION: cargo_env +# @USAGE: Command with its arguments +# @DESCRIPTION: +# Run the given command under an environment needed for performing tasks with +# Cargo such as building. +cargo_env() { + filter-lto + tc-export AR CC CXX PKG_CONFIG + + if tc-is-cross-compiler; then + local -x CARGO_BUILD_TARGET=$(rust_abi) + local TRIPLE=${CARGO_BUILD_TARGET//-/_} + local -x CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC) + + # Set vars for cc-rs crate. + tc-export_build_env + local -x \ + HOST_AR=$(tc-getBUILD_AR) + HOST_CC=$(tc-getBUILD_CC) + HOST_CXX=$(tc-getBUILD_CXX) + HOST_CFLAGS=${BUILD_CFLAGS} + HOST_CXXFLAGS=${BUILD_CXXFLAGS} + fi + + "${@}" +} + # @FUNCTION: cargo_src_compile # @DESCRIPTION: # Build the package using cargo build. @@ -532,27 +559,9 @@ cargo_src_compile() { [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" - 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" + cargo_env "${@}" || die "cargo build failed" } # @FUNCTION: cargo_src_install @@ -573,7 +582,7 @@ cargo_src_install() { $(usex debug --debug "") \ ${ECARGO_ARGS[@]} "$@" einfo "${@}" - "${@}" || die "cargo install failed" + cargo_env "${@}" || die "cargo install failed" rm -f "${ED}/usr/.crates.toml" || die rm -f "${ED}/usr/.crates2.json" || die @@ -590,7 +599,7 @@ cargo_src_test() { set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" - "${@}" || die "cargo test failed" + cargo_env "${@}" || die "cargo test failed" } fi From 9e9c222fe930f6369f2192e4de0175afc21e1e7f Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 24 Jul 2024 18:19:30 +0100 Subject: [PATCH 09/15] cargo.eclass: Handle LDFLAGS and RUSTFLAGS better MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LDFLAGS are not currently honoured by Cargo builds at all. It would be particularly advantageous to honour -fuse-ld because alternative linkers like mold are known to be significantly faster at handling Rust. As things stand, the eclass sets the linker to CC when cross-compiling, but it does so erroneously due to a shell quoting issue. If CC includes arguments, an error occurs when setting the CARGO_TARGET_*_LINKER variable. Even with the right quoting, Cargo still fails because this variable is not allowed to include arguments. They have to be specified via RUSTFLAGS instead. The build host linker is frequently invoked due to the use of build scripts by some crates. We would therefore also like to configure the build host linker properly when cross-compiling, but unfortunately there is currently no way to do this without using a Rust nightly feature. The build host linker is now configured in the cargo_gen_config function because this configuration is static. Conversely, the target host linker is configured with environment variables in the cargo_env function because the target may change. Some ebuilds already set RUSTFLAGS, so some consideration was given to how to handle these. When set, Cargo prioritises RUSTFLAGS and similar over specific configuration for the build and target hosts, so these must be unset. We can still include their contents in that configuration for convenience though. BUILD_RUSTFLAGS can be used by ebuilds to set flags only for the build host. It should not be necessary for ebuilds to figure out which Rust ABI is applicable in order to set flags only for the target host, so the helper reads from a simple TARGET_RUSTFLAGS variable without the triple for convenience. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/cargo.eclass | 63 +++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index de4a012354eef..ef927aac50cdf 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -109,7 +109,7 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" # # If you enable CARGO_OPTIONAL, you have to set BDEPEND on virtual/rust # for your package and call at least cargo_gen_config manually before using -# other src_functions of this eclass. +# other src_functions or cargo_env of this eclass. # Note that cargo_gen_config is automatically called by cargo_src_unpack. # @ECLASS_VARIABLE: myfeatures @@ -259,6 +259,19 @@ cargo_crate_uris() { cargo_gen_config() { debug-print-function ${FUNCNAME} "$@" + # The default linker is "cc" so override by setting linker to CC in the + # RUSTFLAGS. The given linker cannot include any arguments, so split these + # into link-args along with LDFLAGS. Also include external RUSTFLAGS. + # Note that as of Rust 1.80, the build host RUSTFLAGS are ignored when + # cross-compiling unless you use the unstable host-config feature available + # with USE=nightly. There is no simple way around this. + tc-export_build_env + local LD_A=( $(tc-getBUILD_CC) ${BUILD_LDFLAGS} ) + local MY_BUILD_RUSTFLAGS="-C linker=${LD_A[0]}" + [[ ${#LD_A[@]} -gt 1 ]] && MY_BUILD_RUSTFLAGS+="$(printf -- ' -C link-arg=%s' "${LD_A[@]:1}")" + MY_BUILD_RUSTFLAGS+=" ${RUSTFLAGS} ${BUILD_RUSTFLAGS}" + tc-is-cross-compiler || MY_BUILD_RUSTFLAGS+=" ${TARGET_RUSTFLAGS}" + mkdir -p "${ECARGO_HOME}" || die cat > "${ECARGO_HOME}/config.toml" <<- _EOF_ || die "Failed to create cargo config" @@ -273,6 +286,7 @@ cargo_gen_config() { offline = true [build] + rustflags = "${MY_BUILD_RUSTFLAGS}" jobs = $(makeopts_jobs) incremental = false @@ -527,27 +541,41 @@ cargo_src_configure() { # @USAGE: Command with its arguments # @DESCRIPTION: # Run the given command under an environment needed for performing tasks with -# Cargo such as building. +# Cargo such as building. RUSTFLAGS is used for both the build and target host. +# BUILD_RUSTFLAGS and TARGET_RUSTFLAGS are used for just the build host and +# target host respectively. Ensure these are set consistently between Cargo +# invocations, otherwise rebuilds will occur. cargo_env() { + [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ + die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" + filter-lto tc-export AR CC CXX PKG_CONFIG + # Set vars for cc-rs crate. + local -x \ + HOST_AR=$(tc-getBUILD_AR) + HOST_CC=$(tc-getBUILD_CC) + HOST_CXX=$(tc-getBUILD_CXX) + HOST_CFLAGS=${BUILD_CFLAGS} + HOST_CXXFLAGS=${BUILD_CXXFLAGS} + if tc-is-cross-compiler; then local -x CARGO_BUILD_TARGET=$(rust_abi) local TRIPLE=${CARGO_BUILD_TARGET//-/_} - local -x CARGO_TARGET_"${TRIPLE^^}"_LINKER=$(tc-getCC) - - # Set vars for cc-rs crate. - tc-export_build_env - local -x \ - HOST_AR=$(tc-getBUILD_AR) - HOST_CC=$(tc-getBUILD_CC) - HOST_CXX=$(tc-getBUILD_CXX) - HOST_CFLAGS=${BUILD_CFLAGS} - HOST_CXXFLAGS=${BUILD_CXXFLAGS} + local TRIPLE=${TRIPLE^^} LD_A=( $(tc-getCC) ${LDFLAGS} ) + local -x CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS="-C linker=${LD_A[0]}" + [[ ${#LD_A[@]} -gt 1 ]] && local CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+="$(printf -- ' -C link-arg=%s' "${LD_A[@]:1}")" + local CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+=" ${RUSTFLAGS} ${TARGET_RUSTFLAGS}" fi - "${@}" + ( + # These variables will override the above, even if empty, so unset them + # locally. Do this in a subshell so that they remain set afterwards. + unset CARGO_BUILD_RUSTFLAGS CARGO_ENCODED_RUSTFLAGS RUSTFLAGS + + "${@}" + ) } # @FUNCTION: cargo_src_compile @@ -556,9 +584,6 @@ cargo_env() { cargo_src_compile() { debug-print-function ${FUNCNAME} "$@" - [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ - die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" - set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" cargo_env "${@}" || die "cargo build failed" @@ -573,9 +598,6 @@ cargo_src_compile() { cargo_src_install() { debug-print-function ${FUNCNAME} "$@" - [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ - die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" - set -- cargo install $(has --path ${@} || echo --path ./) \ --root "${ED}/usr" \ ${GIT_CRATES[@]:+--frozen} \ @@ -594,9 +616,6 @@ cargo_src_install() { cargo_src_test() { debug-print-function ${FUNCNAME} "$@" - [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ - die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" - set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" einfo "${@}" cargo_env "${@}" || die "cargo test failed" From 7d7c5168294a4d90681c8d3ab6ac985c4eba1643 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 24 Jul 2024 22:59:16 +0100 Subject: [PATCH 10/15] cargo.eclass: Explicitly tell rustc not to strip binaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most projects don't strip binaries in release mode by default, but there are exceptions like app-misc/broot. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/cargo.eclass | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index ef927aac50cdf..99a7959b22e23 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -267,7 +267,7 @@ cargo_gen_config() { # with USE=nightly. There is no simple way around this. tc-export_build_env local LD_A=( $(tc-getBUILD_CC) ${BUILD_LDFLAGS} ) - local MY_BUILD_RUSTFLAGS="-C linker=${LD_A[0]}" + local MY_BUILD_RUSTFLAGS="-C strip=none -C linker=${LD_A[0]}" [[ ${#LD_A[@]} -gt 1 ]] && MY_BUILD_RUSTFLAGS+="$(printf -- ' -C link-arg=%s' "${LD_A[@]:1}")" MY_BUILD_RUSTFLAGS+=" ${RUSTFLAGS} ${BUILD_RUSTFLAGS}" tc-is-cross-compiler || MY_BUILD_RUSTFLAGS+=" ${TARGET_RUSTFLAGS}" @@ -564,7 +564,7 @@ cargo_env() { local -x CARGO_BUILD_TARGET=$(rust_abi) local TRIPLE=${CARGO_BUILD_TARGET//-/_} local TRIPLE=${TRIPLE^^} LD_A=( $(tc-getCC) ${LDFLAGS} ) - local -x CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS="-C linker=${LD_A[0]}" + local -x CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS="-C strip=none -C linker=${LD_A[0]}" [[ ${#LD_A[@]} -gt 1 ]] && local CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+="$(printf -- ' -C link-arg=%s' "${LD_A[@]:1}")" local CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+=" ${RUSTFLAGS} ${TARGET_RUSTFLAGS}" fi From 1792d3396dad606e254910619c13b8509998e7e5 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 25 Jul 2024 12:08:52 +0100 Subject: [PATCH 11/15] cargo.eclass: Shadow flag variables so that LTO filtering remains local MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is currently done for Cargo by distutils-r1.eclass. The next commit will remove that code, leaving cargo_env responsible for it. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/cargo.eclass | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 99a7959b22e23..c360c2a6c4192 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -549,7 +549,16 @@ cargo_env() { [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \ die "FATAL: please call cargo_gen_config before using ${FUNCNAME}" + # Shadow flag variables so that filtering below remains local. + local flag + for flag in $(all-flag-vars); do + local -x "${flag}=${!flag}" + done + + # Rust extensions are incompatible with C/C++ LTO compiler see e.g. + # https://bugs.gentoo.org/910220 filter-lto + tc-export AR CC CXX PKG_CONFIG # Set vars for cc-rs crate. From 9b2def86a9c7fd8821a5b83df7d250fc4c73540f Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 25 Jul 2024 12:09:21 +0100 Subject: [PATCH 12/15] distutils-r1.eclass: Use cargo_env when appropriate for flag handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cargo_env handles linker flags and enables cross-compiling. It also handles LTO filtering, so we can remove that from this eclass. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/distutils-r1.eclass | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index 5d9f97474b294..129ba21ab0d45 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -1252,7 +1252,9 @@ distutils_pep517_install() { die "mydistutilsargs are banned in PEP517 mode (use DISTUTILS_ARGS)" fi - local config_settings= + local cmd=() config_settings= + has cargo ${INHERITED} && cmd+=( cargo_env ) + case ${DISTUTILS_USE_PEP517} in maturin) # `maturin pep517 build-wheel --help` for options @@ -1391,7 +1393,7 @@ distutils_pep517_install() { local build_backend=$(_distutils-r1_get_backend) einfo " Building the wheel for ${PWD#${WORKDIR}/} via ${build_backend}" - local cmd=( + cmd+=( "${EPYTHON}" -m gpep517 build-wheel --prefix="${EPREFIX}/usr" --backend "${build_backend}" @@ -1793,16 +1795,6 @@ distutils-r1_run_phase() { # bug fixes from Cython (this works only when setup.py is using # cythonize() but it's better than nothing) local -x CYTHON_FORCE_REGEN=1 - - # Rust extensions are incompatible with C/C++ LTO compiler - # see e.g. https://bugs.gentoo.org/910220 - if has cargo ${INHERITED}; then - local x - for x in $(all-flag-vars); do - local -x "${x}=${!x}" - done - filter-lto - fi fi # silence warnings when pydevd is loaded on Python 3.11+ From 068fd56ff572b83925acf159e4afcfd01f98f1c8 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 25 Jul 2024 22:18:03 +0100 Subject: [PATCH 13/15] python-utils-r1.eclass: Add python_get_stdlib helper function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is just like python_get_sitedir, but it returns the stdlib directory such as /usr/lib/python3.12. This is useful for locating the sysconfigdata file. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny --- eclass/python-utils-r1.eclass | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index cc33a1c1bffdd..45d3da6bb98c1 100644 --- a/eclass/python-utils-r1.eclass +++ b/eclass/python-utils-r1.eclass @@ -332,6 +332,17 @@ _python_export() { export PYTHON=${BROOT-${EPREFIX}}/usr/bin/${impl} debug-print "${FUNCNAME}: PYTHON = ${PYTHON}" ;; + PYTHON_STDLIB) + [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it" + PYTHON_STDLIB=$( + "${PYTHON}" - "${EPREFIX}/usr" <<-EOF || die + import sys, sysconfig + print(sysconfig.get_path("stdlib", vars={"installed_base": sys.argv[1]})) + EOF + ) + export PYTHON_STDLIB + debug-print "${FUNCNAME}: PYTHON_STDLIB = ${PYTHON_STDLIB}" + ;; PYTHON_SITEDIR) [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it" PYTHON_SITEDIR=$( @@ -466,6 +477,18 @@ _python_export() { done } +# @FUNCTION: python_get_stdlib +# @USAGE: [] +# @DESCRIPTION: +# Obtain and print the 'stdlib' path for the given implementation. If no +# implementation is provided, ${EPYTHON} will be used. +python_get_stdlib() { + debug-print-function ${FUNCNAME} "${@}" + + _python_export "${@}" PYTHON_STDLIB + echo "${PYTHON_STDLIB}" +} + # @FUNCTION: python_get_sitedir # @USAGE: [] # @DESCRIPTION: From 83739e9677a6835c9fa49c0c98e9d7bc1e331413 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 25 Jul 2024 22:20:02 +0100 Subject: [PATCH 14/15] distutils-r1.eclass: Support cross-compiling with PyO3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only one variable needs to be set. For details, see https://pyo3.rs/latest/building-and-distribution.html#cross-compiling. Signed-off-by: James Le Cuirot Signed-off-by: Michał Górny Closes: https://github.com/gentoo/gentoo/pull/37708 Signed-off-by: Michał Górny --- eclass/distutils-r1.eclass | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass index 129ba21ab0d45..0f9dc8d14d5e5 100644 --- a/eclass/distutils-r1.eclass +++ b/eclass/distutils-r1.eclass @@ -1391,6 +1391,11 @@ distutils_pep517_install() { ;; esac + # https://pyo3.rs/latest/building-and-distribution.html#cross-compiling + if tc-is-cross-compiler; then + local -x PYO3_CROSS_LIB_DIR=${SYSROOT}/$(python_get_stdlib) + fi + local build_backend=$(_distutils-r1_get_backend) einfo " Building the wheel for ${PWD#${WORKDIR}/} via ${build_backend}" cmd+=( From 7f2c27de086450446969df29d89b6e9e9f133801 Mon Sep 17 00:00:00 2001 From: "Volkmar W. Pogatzki" Date: Mon, 5 Aug 2024 06:05:42 +0200 Subject: [PATCH 15/15] dev-java/java-service-wrapper: drop 3.5.50-r1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Volkmar W. Pogatzki Closes: https://github.com/gentoo/gentoo/pull/37963 Signed-off-by: Miroslav Šulc --- .../java-service-wrapper-3.5.50-r1.ebuild | 94 ------------------- 1 file changed, 94 deletions(-) delete mode 100644 dev-java/java-service-wrapper/java-service-wrapper-3.5.50-r1.ebuild diff --git a/dev-java/java-service-wrapper/java-service-wrapper-3.5.50-r1.ebuild b/dev-java/java-service-wrapper/java-service-wrapper-3.5.50-r1.ebuild deleted file mode 100644 index 8fdfe9ac2063f..0000000000000 --- a/dev-java/java-service-wrapper/java-service-wrapper-3.5.50-r1.ebuild +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 1999-2023 Gentoo Authors -# Distributed under the terms of the GNU General Public License v2 - -EAPI=8 - -JAVA_PKG_IUSE="doc source test" -inherit java-pkg-2 java-pkg-simple toolchain-funcs java-ant-2 -JAVA_TESTING_FRAMEWORKS="junit-4" - -DESCRIPTION="A wrapper that makes it possible to install a Java Application as daemon" -HOMEPAGE="https://wrapper.tanukisoftware.com" -SRC_URI="https://download.tanukisoftware.com/wrapper/${PV}/wrapper_${PV}_src.tar.gz" - -LICENSE="tanuki-community" -SLOT="0" -KEYWORDS="amd64 ~arm ~arm64 x86" -RESTRICT="!test? ( test )" - -RDEPEND=">=virtual/jre-1.8:*" -DEPEND=" - >=virtual/jdk-1.8:* - test? ( - dev-java/junit:4 - dev-util/cunit - ) -" -BDEPEND="virtual/jdk" - -S="${WORKDIR}/wrapper_${PV}_src" - -JAVA_SRC_DIR="src/java/" -JAVA_JAR_FILENAME="wrapper.jar" -JAVA_TEST_SRC_DIR="src/test" -JAVA_TEST_GENTOO_CLASSPATH="junit-4" - -PATCHES=( - "${FILESDIR}"/java-service-wrapper-3.5.25-gentoo-wrapper-defaults.patch -) - -src_prepare() { - default - - # replaces as-needed.patch - sed -i \ - -e 's/gcc -O3/$(CC)/g' \ - -e 's/ -pthread/ $(CFLAGS) $(LDFLAGS) -pthread/g' \ - -e 's/ -shared/ $(LDFLAGS) -shared/g' \ - -e 's/$(TEST)\/testsuite/testsuite/g' \ - src/c/Makefile-*.make || die - - cp "${S}/src/c/Makefile-linux-armel-32.make" "${S}/src/c/Makefile-linux-arm-32.make" - java-pkg-2_src_prepare - - # disable tests by default (they are only enabled by default on amd64) - sed -e "s/\(all: init wrapper libwrapper.so\) testsuite/\1/g" \ - -i src/c/Makefile-linux-x86-64.make || die - - # re-enable tests on all platforms if requested - if use test; then - grep "testsuite_SOURCE" "src/c/Makefile-linux-x86-64.make" | tee -a src/c/Makefile-*.make - assert - echo 'all: testsuite' | tee -a src/c/Makefile-*.make - assert - fi -} - -src_compile() { - tc-export CC - - pushd "${T}" || die - echo 'public class GetArchDataModel{public static void main(String[] args){System.out.println(System.getProperty("sun.arch.data.model"));}}' \ - > GetArchDataModel.java || die - ejavac GetArchDataModel.java - local BITS - BITS="$(java GetArchDataModel)" || die "Failed to identify sun.arch.data.model property" - popd || die - eant -Dbits="${BITS}" compile-c - - java-pkg-simple_src_compile -} - -src_test() { - src/c/testsuite --basic || die - java-pkg-simple_src_test -} - -src_install() { - java-pkg-simple_src_install - java-pkg_doso lib/libwrapper.so - - dobin bin/wrapper - dodoc README*.txt - dodoc doc/revisions.txt -}