Gentoo Archives: gentoo-commits

From: Quentin Retornaz <gentoo@××××××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/libressl:master commit in: dev-lang/rust/files/, dev-lang/rust/
Date: Thu, 29 Sep 2022 22:58:21
Message-Id: 1664492250.70ce859aa9f2509ab4775e0e6a3a2ca260c265ac.quentin@gentoo
1 commit: 70ce859aa9f2509ab4775e0e6a3a2ca260c265ac
2 Author: orbea <orbea <AT> riseup <DOT> net>
3 AuthorDate: Wed Sep 28 00:39:45 2022 +0000
4 Commit: Quentin Retornaz <gentoo <AT> retornaz <DOT> com>
5 CommitDate: Thu Sep 29 22:57:30 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/libressl.git/commit/?id=70ce859a
7
8 dev-lang/rust: Add 1.64.0-r1
9
10 Signed-off-by: orbea <orbea <AT> riseup.net>
11 Signed-off-by: Quentin Retornaz <gentoo <AT> retornaz.com>
12
13 ...64.0-vendor-rustix-sparc-has-no-SIGSTKFLT.patch | 60 ++
14 dev-lang/rust/rust-1.64.0-r1.ebuild | 764 +++++++++++++++++++++
15 2 files changed, 824 insertions(+)
16
17 diff --git a/dev-lang/rust/files/1.64.0-vendor-rustix-sparc-has-no-SIGSTKFLT.patch b/dev-lang/rust/files/1.64.0-vendor-rustix-sparc-has-no-SIGSTKFLT.patch
18 new file mode 100644
19 index 0000000..5d685ba
20 --- /dev/null
21 +++ b/dev-lang/rust/files/1.64.0-vendor-rustix-sparc-has-no-SIGSTKFLT.patch
22 @@ -0,0 +1,60 @@
23 +From 3fd653f3978e5ec2249c37eb08934bfe343e9198 Mon Sep 17 00:00:00 2001
24 +From: Georgy Yakovlev <gyakovlev@g.o>
25 +Date: Sat, 24 Sep 2022 23:09:38 -0700
26 +Subject: [PATCH] vendor/rustix: sparc has no SIGSTKFLT
27 +
28 +gyakovlev: removed checkum HUNK
29 +
30 +---
31 + vendor/rustix/.cargo-checksum.json | 2 +-
32 + vendor/rustix/src/imp/libc/process/types.rs | 4 ++++
33 + vendor/rustix/src/imp/linux_raw/process/types.rs | 4 ++--
34 + 3 files changed, 7 insertions(+), 3 deletions(-)
35 +
36 +diff --git a/vendor/rustix/src/imp/libc/process/types.rs b/vendor/rustix/src/imp/libc/process/types.rs
37 +index 60d629d..1278cee 100644
38 +--- a/vendor/rustix/src/imp/libc/process/types.rs
39 ++++ b/vendor/rustix/src/imp/libc/process/types.rs
40 +@@ -197,6 +197,8 @@ pub enum Signal {
41 + target_os = "macos",
42 + target_os = "netbsd",
43 + target_os = "openbsd",
44 ++ target_arch = "sparc",
45 ++ target_arch = "sparc64",
46 + all(
47 + any(target_os = "android", target_os = "linux"),
48 + any(target_arch = "mips", target_arch = "mips64"),
49 +@@ -274,6 +276,8 @@ impl Signal {
50 + target_os = "macos",
51 + target_os = "netbsd",
52 + target_os = "openbsd",
53 ++ target_arch = "sparc",
54 ++ target_arch = "sparc64",
55 + all(
56 + any(target_os = "android", target_os = "linux"),
57 + any(target_arch = "mips", target_arch = "mips64"),
58 +diff --git a/vendor/rustix/src/imp/linux_raw/process/types.rs b/vendor/rustix/src/imp/linux_raw/process/types.rs
59 +index 53e2c7d..859a108 100644
60 +--- a/vendor/rustix/src/imp/linux_raw/process/types.rs
61 ++++ b/vendor/rustix/src/imp/linux_raw/process/types.rs
62 +@@ -119,7 +119,7 @@ pub enum Signal {
63 + /// `SIGTERM`
64 + Term = linux_raw_sys::general::SIGTERM,
65 + /// `SIGSTKFLT`
66 +- #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
67 ++ #[cfg(not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc", target_arch = "sparc64")))]
68 + Stkflt = linux_raw_sys::general::SIGSTKFLT,
69 + /// `SIGCHLD`
70 + #[doc(alias = "Chld")]
71 +@@ -179,7 +179,7 @@ impl Signal {
72 + linux_raw_sys::general::SIGPIPE => Some(Self::Pipe),
73 + linux_raw_sys::general::SIGALRM => Some(Self::Alarm),
74 + linux_raw_sys::general::SIGTERM => Some(Self::Term),
75 +- #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
76 ++ #[cfg(not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc", target_arch = "sparc64")))]
77 + linux_raw_sys::general::SIGSTKFLT => Some(Self::Stkflt),
78 + linux_raw_sys::general::SIGCHLD => Some(Self::Child),
79 + linux_raw_sys::general::SIGCONT => Some(Self::Cont),
80 +--
81 +2.37.3
82 +
83
84 diff --git a/dev-lang/rust/rust-1.64.0-r1.ebuild b/dev-lang/rust/rust-1.64.0-r1.ebuild
85 new file mode 100644
86 index 0000000..b385ace
87 --- /dev/null
88 +++ b/dev-lang/rust/rust-1.64.0-r1.ebuild
89 @@ -0,0 +1,764 @@
90 +# Copyright 1999-2022 Gentoo Authors
91 +# Distributed under the terms of the GNU General Public License v2
92 +
93 +EAPI=8
94 +
95 +PYTHON_COMPAT=( python3_{8..11} )
96 +
97 +inherit bash-completion-r1 check-reqs estack flag-o-matic llvm multiprocessing \
98 + multilib multilib-build python-any-r1 rust-toolchain toolchain-funcs verify-sig
99 +
100 +if [[ ${PV} = *beta* ]]; then
101 + betaver=${PV//*beta}
102 + BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}"
103 + MY_P="rustc-beta"
104 + SLOT="beta/${PV}"
105 + SRC="${BETA_SNAPSHOT}/rustc-beta-src.tar.xz -> rustc-${PV}-src.tar.xz"
106 +else
107 + ABI_VER="$(ver_cut 1-2)"
108 + SLOT="stable/${ABI_VER}"
109 + MY_P="rustc-${PV}"
110 + SRC="${MY_P}-src.tar.xz"
111 + KEYWORDS="~amd64 ~arm ~arm64 ~mips ~ppc64 ~riscv ~sparc ~x86"
112 +fi
113 +
114 +RUST_STAGE0_VERSION="1.$(($(ver_cut 2) - 1)).0"
115 +
116 +DESCRIPTION="Systems programming language from Mozilla"
117 +HOMEPAGE="https://www.rust-lang.org/"
118 +
119 +SRC_URI="
120 + https://static.rust-lang.org/dist/${SRC}
121 + verify-sig? ( https://static.rust-lang.org/dist/${SRC}.asc )
122 + !system-bootstrap? ( $(rust_all_arch_uris rust-${RUST_STAGE0_VERSION}) )
123 +"
124 +
125 +# keep in sync with llvm ebuild of the same version as bundled one.
126 +ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM AVR BPF Hexagon Lanai Mips MSP430
127 + NVPTX PowerPC RISCV Sparc SystemZ WebAssembly X86 XCore )
128 +ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
129 +LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/(-)?}
130 +
131 +LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA"
132 +
133 +IUSE="clippy cpu_flags_x86_sse2 debug dist doc llvm-libunwind miri nightly parallel-compiler profiler rls rustfmt rust-analyzer rust-src system-bootstrap system-llvm test wasm ${ALL_LLVM_TARGETS[*]}"
134 +
135 +# Please keep the LLVM dependency block separate. Since LLVM is slotted,
136 +# we need to *really* make sure we're not pulling more than one slot
137 +# simultaneously.
138 +
139 +# How to use it:
140 +# List all the working slots in LLVM_VALID_SLOTS, newest first.
141 +LLVM_VALID_SLOTS=( 14 )
142 +LLVM_MAX_SLOT="${LLVM_VALID_SLOTS[0]}"
143 +
144 +# splitting usedeps needed to avoid CI/pkgcheck's UncheckableDep limitation
145 +# (-) usedep needed because we may build with older llvm without that target
146 +LLVM_DEPEND="|| ( "
147 +for _s in ${LLVM_VALID_SLOTS[@]}; do
148 + LLVM_DEPEND+=" ( "
149 + for _x in ${ALL_LLVM_TARGETS[@]}; do
150 + LLVM_DEPEND+="
151 + ${_x}? ( sys-devel/llvm:${_s}[${_x}(-)] )"
152 + done
153 + LLVM_DEPEND+=" )"
154 +done
155 +unset _s _x
156 +LLVM_DEPEND+=" )
157 + <sys-devel/llvm-$(( LLVM_MAX_SLOT + 1 )):=
158 + wasm? ( sys-devel/lld )
159 +"
160 +
161 +# to bootstrap we need at least exactly previous version, or same.
162 +# most of the time previous versions fail to bootstrap with newer
163 +# for example 1.47.x, requires at least 1.46.x, 1.47.x is ok,
164 +# but it fails to bootstrap with 1.48.x
165 +# https://github.com/rust-lang/rust/blob/${PV}/src/stage0.json
166 +RUST_DEP_PREV="$(ver_cut 1).$(($(ver_cut 2) - 1))*"
167 +RUST_DEP_CURR="$(ver_cut 1).$(ver_cut 2)*"
168 +BOOTSTRAP_DEPEND="||
169 + (
170 + =dev-lang/rust-"${RUST_DEP_PREV}"
171 + =dev-lang/rust-bin-"${RUST_DEP_PREV}"
172 + =dev-lang/rust-"${RUST_DEP_CURR}"
173 + =dev-lang/rust-bin-"${RUST_DEP_CURR}"
174 + )
175 +"
176 +
177 +BDEPEND="${PYTHON_DEPS}
178 + app-eselect/eselect-rust
179 + || (
180 + >=sys-devel/gcc-4.7
181 + >=sys-devel/clang-3.5
182 + )
183 + system-bootstrap? ( ${BOOTSTRAP_DEPEND} )
184 + !system-llvm? (
185 + >=dev-util/cmake-3.13.4
186 + dev-util/ninja
187 + )
188 + test? ( sys-devel/gdb )
189 + verify-sig? ( sec-keys/openpgp-keys-rust )
190 +"
191 +
192 +DEPEND="
193 + >=app-arch/xz-utils-5.2
194 + net-misc/curl:=[http2,ssl]
195 + sys-libs/zlib:=
196 + dev-libs/openssl:0=
197 + system-llvm? (
198 + ${LLVM_DEPEND}
199 + llvm-libunwind? ( sys-libs/llvm-libunwind:= )
200 + )
201 + !system-llvm? (
202 + !llvm-libunwind? (
203 + elibc_musl? ( sys-libs/libunwind:= )
204 + )
205 + )
206 +"
207 +
208 +RDEPEND="${DEPEND}
209 + app-eselect/eselect-rust
210 + sys-apps/lsb-release
211 +"
212 +
213 +REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} )
214 + miri? ( nightly )
215 + parallel-compiler? ( nightly )
216 + rls? ( rust-src )
217 + test? ( ${ALL_LLVM_TARGETS[*]} )
218 + wasm? ( llvm_targets_WebAssembly )
219 + x86? ( cpu_flags_x86_sse2 )
220 +"
221 +
222 +# we don't use cmake.eclass, but can get a warning
223 +CMAKE_WARN_UNUSED_CLI=no
224 +
225 +QA_FLAGS_IGNORED="
226 + usr/lib/${PN}/${PV}/bin/.*
227 + usr/lib/${PN}/${PV}/libexec/.*
228 + usr/lib/${PN}/${PV}/lib/lib.*.so
229 + usr/lib/${PN}/${PV}/lib/rustlib/.*/bin/.*
230 + usr/lib/${PN}/${PV}/lib/rustlib/.*/lib/lib.*.so
231 +"
232 +
233 +QA_SONAME="
234 + usr/lib/${PN}/${PV}/lib/lib.*.so.*
235 + usr/lib/${PN}/${PV}/lib/rustlib/.*/lib/lib.*.so
236 +"
237 +
238 +QA_PRESTRIPPED="
239 + usr/lib/${PN}/${PV}/lib/rustlib/.*/bin/rust-llvm-dwp
240 + usr/lib/${PN}/${PV}/lib/rustlib/.*/lib/self-contained/crtn.o
241 +"
242 +
243 +# An rmeta file is custom binary format that contains the metadata for the crate.
244 +# rmeta files do not support linking, since they do not contain compiled object files.
245 +# so we can safely silence the warning for this QA check.
246 +QA_EXECSTACK="usr/lib/${PN}/${PV}/lib/rustlib/*/lib*.rlib:lib.rmeta"
247 +
248 +# causes double bootstrap
249 +RESTRICT="test"
250 +
251 +VERIFY_SIG_OPENPGP_KEY_PATH=${BROOT}/usr/share/openpgp-keys/rust.asc
252 +
253 +PATCHES=(
254 + "${FILESDIR}"/1.62.0-libressl.patch
255 + "${FILESDIR}"/1.55.0-ignore-broken-and-non-applicable-tests.patch
256 + "${FILESDIR}"/1.62.1-musl-dynamic-linking.patch
257 + "${FILESDIR}"/${PV}-vendor-rustix-sparc-has-no-SIGSTKFLT.patch
258 +)
259 +
260 +S="${WORKDIR}/${MY_P}-src"
261 +
262 +toml_usex() {
263 + usex "${1}" true false
264 +}
265 +
266 +bootstrap_rust_version_check() {
267 + # never call from pkg_pretend. eselect-rust may be not installed yet.
268 + [[ ${MERGE_TYPE} == binary ]] && return
269 + local rustc_wanted="$(ver_cut 1).$(($(ver_cut 2) - 1))"
270 + local rustc_toonew="$(ver_cut 1).$(($(ver_cut 2) + 1))"
271 + local rustc_version=( $(eselect --brief rust show 2>/dev/null) )
272 + rustc_version=${rustc_version[0]#rust-bin-}
273 + rustc_version=${rustc_version#rust-}
274 +
275 + [[ -z "${rustc_version}" ]] && die "Failed to determine rust version, check 'eselect rust' output"
276 +
277 + if ver_test "${rustc_version}" -lt "${rustc_wanted}" ; then
278 + eerror "Rust >=${rustc_wanted} is required"
279 + eerror "please run 'eselect rust' and set correct rust version"
280 + die "selected rust version is too old"
281 + elif ver_test "${rustc_version}" -ge "${rustc_toonew}" ; then
282 + eerror "Rust <${rustc_toonew} is required"
283 + eerror "please run 'eselect rust' and set correct rust version"
284 + die "selected rust version is too new"
285 + else
286 + einfo "Using rust ${rustc_version} to build"
287 + fi
288 +}
289 +
290 +pre_build_checks() {
291 + local M=8192
292 + # multiply requirements by 1.3 if we are doing x86-multilib
293 + if use amd64; then
294 + M=$(( $(usex abi_x86_32 13 10) * ${M} / 10 ))
295 + fi
296 + M=$(( $(usex clippy 128 0) + ${M} ))
297 + M=$(( $(usex miri 128 0) + ${M} ))
298 + M=$(( $(usex rls 512 0) + ${M} ))
299 + M=$(( $(usex rustfmt 256 0) + ${M} ))
300 + # add 2G if we compile llvm and 256M per llvm_target
301 + if ! use system-llvm; then
302 + M=$(( 2048 + ${M} ))
303 + local ltarget
304 + for ltarget in ${ALL_LLVM_TARGETS[@]}; do
305 + M=$(( $(usex ${ltarget} 256 0) + ${M} ))
306 + done
307 + fi
308 + M=$(( $(usex wasm 256 0) + ${M} ))
309 + M=$(( $(usex debug 2 1) * ${M} ))
310 + eshopts_push -s extglob
311 + if is-flagq '-g?(gdb)?([1-9])'; then
312 + M=$(( 15 * ${M} / 10 ))
313 + fi
314 + eshopts_pop
315 + M=$(( $(usex system-bootstrap 0 1024) + ${M} ))
316 + M=$(( $(usex doc 256 0) + ${M} ))
317 + CHECKREQS_DISK_BUILD=${M}M check-reqs_pkg_${EBUILD_PHASE}
318 +}
319 +
320 +llvm_check_deps() {
321 + has_version -r "sys-devel/llvm:${LLVM_SLOT}[${LLVM_TARGET_USEDEPS// /,}]"
322 +}
323 +
324 +pkg_pretend() {
325 + pre_build_checks
326 +}
327 +
328 +pkg_setup() {
329 + pre_build_checks
330 + python-any-r1_pkg_setup
331 +
332 + export LIBGIT2_NO_PKG_CONFIG=1 #749381
333 +
334 + use system-bootstrap && bootstrap_rust_version_check
335 +
336 + if use system-llvm; then
337 + llvm_pkg_setup
338 +
339 + local llvm_config="$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config"
340 + export LLVM_LINK_SHARED=1
341 + export RUSTFLAGS="${RUSTFLAGS} -Lnative=$("${llvm_config}" --libdir)"
342 + fi
343 +}
344 +
345 +esetup_unwind_hack() {
346 + # https://bugs.gentoo.org/870280
347 + # this is a hack needed to bootstrap with libgcc_s linked tarball on llvm-libunwind system.
348 + # it should trigger for internal bootstrap or system-bootstrap with rust-bin.
349 + # the whole idea is for stage0 to bootstrap with fake libgcc_s.
350 + # final stage will receive -L${T}/lib but not -lgcc_s args, producing clean compiler.
351 + local fakelib="${T}/fakelib"
352 + mkdir -p "${fakelib}" || die
353 + # we need both symlinks, one for cargo runtime, other for linker.
354 + ln -s "${ESYSROOT}/usr/lib/libunwind.so" "${fakelib}/libgcc_s.so.1" || die
355 + ln -s "${ESYSROOT}/usr/lib/libunwind.so" "${fakelib}/libgcc_s.so" || die
356 + export LD_LIBRARY_PATH="${fakelib}"
357 + export RUSTFLAGS+=" -L${fakelib}"
358 + # this is a literally magic variable that gets through cargo cache, without it some
359 + # crates ignore RUSTFLAGS.
360 + # this variable can not contain leading space.
361 + export MAGIC_EXTRA_RUSTFLAGS+="${MAGIC_EXTRA_RUSTFLAGS:+ }-L${fakelib}"
362 +}
363 +
364 +src_prepare() {
365 + # this supidity is needed because patch is too large to be in filesdir
366 + # and if we move it to devspace - it lacks checksum for sig verification
367 + if [[ "${PV}" == 1.64.0 ]]; then
368 + sed -i \
369 + -e 's/516ba32a547b46a8e80ad20d4a17bf24a00bff0b69b74f56df119f770f3dfff6/fc7eb88c2f5104865379128b76767d36ce5b5fdb9f3483e683d150e514ebc3a3/' \
370 + -e 's/fba10dc8ca9eaf4d481cb82bd1540cf5c05620533c44f917c09a22ea55ef408c/9cc4d1b4511a1f0d91231eb0f11c67ae5e8e38e4becd0bf5eb9e26d043796056/' \
371 + vendor/rustix/.cargo-checksum.json || die
372 + else
373 + die "remove sed mr forgetful maintainer"
374 + fi
375 + if ! use system-bootstrap; then
376 + has_version sys-devel/gcc || esetup_unwind_hack
377 + local rust_stage0_root="${WORKDIR}"/rust-stage0
378 + local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi)"
379 +
380 + "${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig \
381 + --without=rust-docs --destdir="${rust_stage0_root}" --prefix=/ || die
382 + fi
383 +
384 + default
385 +}
386 +
387 +src_configure() {
388 + filter-flags '-flto*' # https://bugs.gentoo.org/862109 https://bugs.gentoo.org/866231
389 +
390 + local rust_target="" rust_targets="" arch_cflags use_libcxx="false"
391 +
392 + # Collect rust target names to compile standard libs for all ABIs.
393 + for v in $(multilib_get_enabled_abi_pairs); do
394 + rust_targets+=",\"$(rust_abi $(get_abi_CHOST ${v##*.}))\""
395 + done
396 + if use wasm; then
397 + rust_targets+=",\"wasm32-unknown-unknown\""
398 + if use system-llvm; then
399 + # un-hardcode rust-lld linker for this target
400 + # https://bugs.gentoo.org/715348
401 + sed -i '/linker:/ s/rust-lld/wasm-ld/' compiler/rustc_target/src/spec/wasm_base.rs || die
402 + fi
403 + fi
404 + rust_targets="${rust_targets#,}"
405 +
406 + local tools='"cargo"'
407 + use clippy && tools+=',"clippy"'
408 + use miri && tools+=',"miri"'
409 + use profiler && tools+=',"rust-demangler"'
410 + use rls && tools+=',"rls","analysis"'
411 + use rustfmt && tools+=',"rustfmt"'
412 + use rust-analyzer && tools+=',"rust-analyzer"'
413 + use rust-src && tools+=',"src"'
414 +
415 + local rust_stage0_root
416 + if use system-bootstrap; then
417 + local printsysroot
418 + printsysroot="$(rustc --print sysroot || die "Can't determine rust's sysroot")"
419 + rust_stage0_root="${printsysroot}"
420 + else
421 + rust_stage0_root="${WORKDIR}"/rust-stage0
422 + fi
423 + # in case of prefix it will be already prefixed, as --print sysroot returns full path
424 + [[ -d ${rust_stage0_root} ]] || die "${rust_stage0_root} is not a directory"
425 +
426 + rust_target="$(rust_abi)"
427 +
428 + # https://bugs.gentoo.org/732632
429 + if tc-is-clang; then
430 + local clang_slot="$(clang-major-version)"
431 + if { has_version "sys-devel/clang:${clang_slot}[default-libcxx]" || is-flagq -stdlib=libc++; }; then
432 + use_libcxx="true"
433 + fi
434 + fi
435 +
436 + local cm_btype="$(usex debug DEBUG RELEASE)"
437 + cat <<- _EOF_ > "${S}"/config.toml
438 + changelog-seen = 2
439 + [llvm]
440 + download-ci-llvm = false
441 + optimize = $(toml_usex !debug)
442 + release-debuginfo = $(toml_usex debug)
443 + assertions = $(toml_usex debug)
444 + ninja = true
445 + targets = "${LLVM_TARGETS// /;}"
446 + experimental-targets = ""
447 + link-shared = $(toml_usex system-llvm)
448 + $(if [[ ${use_libcxx} == true ]]; then
449 + echo "use-libcxx = true"
450 + echo "static-libstdcpp = false"
451 + fi)
452 + $(case "${rust_target}" in
453 + i586-*-linux-*)
454 + # https://github.com/rust-lang/rust/issues/93059
455 + echo 'cflags = "-fcf-protection=none"'
456 + echo 'cxxflags = "-fcf-protection=none"'
457 + echo 'ldflags = "-fcf-protection=none"'
458 + ;;
459 + *)
460 + ;;
461 + esac)
462 + [llvm.build-config]
463 + CMAKE_VERBOSE_MAKEFILE = "ON"
464 + CMAKE_C_FLAGS_${cm_btype} = "${CFLAGS}"
465 + CMAKE_CXX_FLAGS_${cm_btype} = "${CXXFLAGS}"
466 + CMAKE_EXE_LINKER_FLAGS_${cm_btype} = "${LDFLAGS}"
467 + CMAKE_MODULE_LINKER_FLAGS_${cm_btype} = "${LDFLAGS}"
468 + CMAKE_SHARED_LINKER_FLAGS_${cm_btype} = "${LDFLAGS}"
469 + CMAKE_STATIC_LINKER_FLAGS_${cm_btype} = "${ARFLAGS}"
470 + [build]
471 + build-stage = 2
472 + test-stage = 2
473 + doc-stage = 2
474 + build = "${rust_target}"
475 + host = ["${rust_target}"]
476 + target = [${rust_targets}]
477 + cargo = "${rust_stage0_root}/bin/cargo"
478 + rustc = "${rust_stage0_root}/bin/rustc"
479 + rustfmt = "${rust_stage0_root}/bin/rustfmt"
480 + docs = $(toml_usex doc)
481 + compiler-docs = false
482 + submodules = false
483 + python = "${EPYTHON}"
484 + locked-deps = true
485 + vendor = true
486 + extended = true
487 + tools = [${tools}]
488 + verbose = 2
489 + sanitizers = false
490 + profiler = $(toml_usex profiler)
491 + cargo-native-static = false
492 + [install]
493 + prefix = "${EPREFIX}/usr/lib/${PN}/${PV}"
494 + sysconfdir = "etc"
495 + docdir = "share/doc/rust"
496 + bindir = "bin"
497 + libdir = "lib"
498 + mandir = "share/man"
499 + [rust]
500 + # https://github.com/rust-lang/rust/issues/54872
501 + codegen-units-std = 1
502 + optimize = true
503 + debug = $(toml_usex debug)
504 + debug-assertions = $(toml_usex debug)
505 + debug-assertions-std = $(toml_usex debug)
506 + debuginfo-level = $(usex debug 2 0)
507 + debuginfo-level-rustc = $(usex debug 2 0)
508 + debuginfo-level-std = $(usex debug 2 0)
509 + debuginfo-level-tools = $(usex debug 2 0)
510 + debuginfo-level-tests = 0
511 + backtrace = true
512 + incremental = false
513 + default-linker = "$(tc-getCC)"
514 + parallel-compiler = $(toml_usex parallel-compiler)
515 + channel = "$(usex nightly nightly stable)"
516 + description = "gentoo"
517 + rpath = false
518 + verbose-tests = true
519 + optimize-tests = $(toml_usex !debug)
520 + codegen-tests = true
521 + dist-src = false
522 + remap-debuginfo = true
523 + lld = $(usex system-llvm false $(toml_usex wasm))
524 + # only deny warnings if doc+wasm are NOT requested, documenting stage0 wasm std fails without it
525 + # https://github.com/rust-lang/rust/issues/74976
526 + # https://github.com/rust-lang/rust/issues/76526
527 + deny-warnings = $(usex wasm $(usex doc false true) true)
528 + backtrace-on-ice = true
529 + jemalloc = false
530 + [dist]
531 + src-tarball = false
532 + compression-formats = ["xz"]
533 + _EOF_
534 +
535 + for v in $(multilib_get_enabled_abi_pairs); do
536 + rust_target=$(rust_abi $(get_abi_CHOST ${v##*.}))
537 + arch_cflags="$(get_abi_CFLAGS ${v##*.})"
538 +
539 + export CFLAGS_${rust_target//-/_}="${arch_cflags}"
540 +
541 + cat <<- _EOF_ >> "${S}"/config.toml
542 + [target.${rust_target}]
543 + ar = "$(tc-getAR)"
544 + cc = "$(tc-getCC)"
545 + cxx = "$(tc-getCXX)"
546 + linker = "$(tc-getCC)"
547 + ranlib = "$(tc-getRANLIB)"
548 + llvm-libunwind = "$(usex llvm-libunwind $(usex system-llvm system in-tree) no)"
549 + _EOF_
550 + if use system-llvm; then
551 + cat <<- _EOF_ >> "${S}"/config.toml
552 + llvm-config = "$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config"
553 + _EOF_
554 + fi
555 + # by default librustc_target/spec/linux_musl_base.rs sets base.crt_static_default = true;
556 + # but we patch it and set to false here as well
557 + if use elibc_musl; then
558 + cat <<- _EOF_ >> "${S}"/config.toml
559 + crt-static = false
560 + _EOF_
561 + fi
562 + done
563 + if use wasm; then
564 + cat <<- _EOF_ >> "${S}"/config.toml
565 + [target.wasm32-unknown-unknown]
566 + linker = "$(usex system-llvm lld rust-lld)"
567 + # wasm target does not have profiler_builtins https://bugs.gentoo.org/848483
568 + profiler = false
569 + _EOF_
570 + fi
571 +
572 + if [[ -n ${I_KNOW_WHAT_I_AM_DOING_CROSS} ]]; then # whitespace intentionally shifted below
573 + # experimental cross support
574 + # discussion: https://bugs.gentoo.org/679878
575 + # TODO: c*flags, clang, system-llvm, cargo.eclass target support
576 + # it would be much better if we could split out stdlib
577 + # complilation to separate ebuild and abuse CATEGORY to
578 + # just install to /usr/lib/rustlib/<target>
579 +
580 + # extra targets defined as a bash array
581 + # spec format: <LLVM target>:<rust-target>:<CTARGET>
582 + # best place would be /etc/portage/env/dev-lang/rust
583 + # Example:
584 + # RUST_CROSS_TARGETS=(
585 + # "AArch64:aarch64-unknown-linux-gnu:aarch64-unknown-linux-gnu"
586 + # )
587 + # no extra hand holding is done, no target transformations, all
588 + # values are passed as-is with just basic checks, so it's up to user to supply correct values
589 + # valid rust targets can be obtained with
590 + # rustc --print target-list
591 + # matching cross toolchain has to be installed
592 + # matching LLVM_TARGET has to be enabled for both rust and llvm (if using system one)
593 + # only gcc toolchains installed with crossdev are checked for now.
594 +
595 + # BUG: we can't pass host flags to cross compiler, so just filter for now
596 + # BUG: this should be more fine-grained.
597 + filter-flags '-mcpu=*' '-march=*' '-mtune=*'
598 +
599 + local cross_target_spec
600 + for cross_target_spec in "${RUST_CROSS_TARGETS[@]}";do
601 + # extracts first element form <LLVM target>:<rust-target>:<CTARGET>
602 + local cross_llvm_target="${cross_target_spec%%:*}"
603 + # extracts toolchain triples, <rust-target>:<CTARGET>
604 + local cross_triples="${cross_target_spec#*:}"
605 + # extracts first element after before : separator
606 + local cross_rust_target="${cross_triples%%:*}"
607 + # extracts last element after : separator
608 + local cross_toolchain="${cross_triples##*:}"
609 + use llvm_targets_${cross_llvm_target} || die "need llvm_targets_${cross_llvm_target} target enabled"
610 + command -v ${cross_toolchain}-gcc > /dev/null 2>&1 || die "need ${cross_toolchain} cross toolchain"
611 +
612 + cat <<- _EOF_ >> "${S}"/config.toml
613 + [target.${cross_rust_target}]
614 + ar = "${cross_toolchain}-ar"
615 + cc = "${cross_toolchain}-gcc"
616 + cxx = "${cross_toolchain}-g++"
617 + linker = "${cross_toolchain}-gcc"
618 + ranlib = "${cross_toolchain}-ranlib"
619 + _EOF_
620 + if use system-llvm; then
621 + cat <<- _EOF_ >> "${S}"/config.toml
622 + llvm-config = "$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config"
623 + _EOF_
624 + fi
625 + if [[ "${cross_toolchain}" == *-musl* ]]; then
626 + cat <<- _EOF_ >> "${S}"/config.toml
627 + musl-root = "$(${cross_toolchain}-gcc -print-sysroot)/usr"
628 + _EOF_
629 + fi
630 +
631 + # append cross target to "normal" target list
632 + # example 'target = ["powerpc64le-unknown-linux-gnu"]'
633 + # becomes 'target = ["powerpc64le-unknown-linux-gnu","aarch64-unknown-linux-gnu"]'
634 +
635 + rust_targets="${rust_targets},\"${cross_rust_target}\""
636 + sed -i "/^target = \[/ s#\[.*\]#\[${rust_targets}\]#" config.toml || die
637 +
638 + ewarn
639 + ewarn "Enabled ${cross_rust_target} rust target"
640 + ewarn "Using ${cross_toolchain} cross toolchain"
641 + ewarn
642 + if ! has_version -b 'sys-devel/binutils[multitarget]' ; then
643 + ewarn "'sys-devel/binutils[multitarget]' is not installed"
644 + ewarn "'strip' will be unable to strip cross libraries"
645 + ewarn "cross targets will be installed with full debug information"
646 + ewarn "enable 'multitarget' USE flag for binutils to be able to strip object files"
647 + ewarn
648 + ewarn "Alternatively llvm-strip can be used, it supports stripping any target"
649 + ewarn "define STRIP=\"llvm-strip\" to use it (experimental)"
650 + ewarn
651 + fi
652 + done
653 + fi # I_KNOW_WHAT_I_AM_DOING_CROSS
654 +
655 + einfo "Rust configured with the following flags:"
656 + echo
657 + echo RUSTFLAGS="\"${RUSTFLAGS}\""
658 + echo RUSTFLAGS_BOOTSTRAP="\"${RUSTFLAGS_BOOTSTRAP}\""
659 + echo RUSTFLAGS_NOT_BOOTSTRAP="\"${RUSTFLAGS_NOT_BOOTSTRAP}\""
660 + echo MAGIC_EXTRA_RUSTFLAGS="\"${MAGIC_EXTRA_RUSTFLAGS}\""
661 + env | grep "CARGO_TARGET_.*_RUSTFLAGS="
662 + env | grep "CFLAGS_.*"
663 + echo
664 + einfo "config.toml contents:"
665 + cat "${S}"/config.toml || die
666 + echo
667 +}
668 +
669 +src_compile() {
670 + RUST_BACKTRACE=1 "${EPYTHON}" ./x.py build -vv --config="${S}"/config.toml -j$(makeopts_jobs) || die
671 +}
672 +
673 +src_test() {
674 + # https://rustc-dev-guide.rust-lang.org/tests/intro.html
675 +
676 + # those are basic and codegen tests.
677 + local tests=(
678 + codegen
679 + codegen-units
680 + compile-fail
681 + incremental
682 + mir-opt
683 + pretty
684 + run-make
685 + )
686 +
687 + # fails if llvm is not built with ALL targets.
688 + # and known to fail with system llvm sometimes.
689 + use system-llvm || tests+=( assembly )
690 +
691 + # fragile/expensive/less important tests
692 + # or tests that require extra builds
693 + # TODO: instead of skipping, just make some nonfatal.
694 + if [[ ${ERUST_RUN_EXTRA_TESTS:-no} != no ]]; then
695 + tests+=(
696 + rustdoc
697 + rustdoc-js
698 + rustdoc-js-std
699 + rustdoc-ui
700 + run-make-fulldeps
701 + ui
702 + ui-fulldeps
703 + )
704 + fi
705 +
706 + local i failed=()
707 + einfo "rust_src_test: enabled tests ${tests[@]/#/src/test/}"
708 + for i in "${tests[@]}"; do
709 + local t="src/test/${i}"
710 + einfo "rust_src_test: running ${t}"
711 + if ! (
712 + IFS=$'\n'
713 + env $(cat "${S}"/config.env) RUST_BACKTRACE=1 \
714 + "${EPYTHON}" ./x.py test -vv --config="${S}"/config.toml \
715 + -j$(makeopts_jobs) --no-doc --no-fail-fast "${t}"
716 + )
717 + then
718 + failed+=( "${t}" )
719 + eerror "rust_src_test: ${t} failed"
720 + fi
721 + done
722 +
723 + if [[ ${#failed[@]} -ne 0 ]]; then
724 + eerror "rust_src_test: failure summary: ${failed[@]}"
725 + die "aborting due to test failures"
726 + fi
727 +}
728 +
729 +src_install() {
730 + (
731 + IFS=$'\n'
732 + env $(cat "${S}"/config.env) DESTDIR="${D}" \
733 + "${EPYTHON}" ./x.py install -vv --config="${S}"/config.toml -j$(makeopts_jobs) || die
734 + )
735 +
736 + # bug #689562, #689160
737 + rm -v "${ED}/usr/lib/${PN}/${PV}/etc/bash_completion.d/cargo" || die
738 + rmdir -v "${ED}/usr/lib/${PN}/${PV}"/etc{/bash_completion.d,} || die
739 + newbashcomp src/tools/cargo/src/etc/cargo.bashcomp.sh cargo
740 +
741 + local symlinks=(
742 + cargo
743 + rustc
744 + rustdoc
745 + rust-gdb
746 + rust-gdbgui
747 + rust-lldb
748 + )
749 +
750 + use clippy && symlinks+=( clippy-driver cargo-clippy )
751 + use miri && symlinks+=( miri cargo-miri )
752 + use profiler && symlinks+=( rust-demangler )
753 + use rls && symlinks+=( rls )
754 + use rustfmt && symlinks+=( rustfmt cargo-fmt )
755 + use rust-analyzer && symlinks+=( rust-analyzer )
756 +
757 + einfo "installing eselect-rust symlinks and paths: ${symlinks[@]}"
758 + local i
759 + for i in "${symlinks[@]}"; do
760 + # we need realpath on /usr/bin/* symlink return version-appended binary path.
761 + # so /usr/bin/rustc should point to /usr/lib/rust/<ver>/bin/rustc-<ver>
762 + # need to fix eselect-rust to remove this hack.
763 + local ver_i="${i}-${PV}"
764 + if [[ -f "${ED}/usr/lib/${PN}/${PV}/bin/${i}" ]]; then
765 + einfo "Installing ${i} symlink"
766 + ln -v "${ED}/usr/lib/${PN}/${PV}/bin/${i}" "${ED}/usr/lib/${PN}/${PV}/bin/${ver_i}" || die
767 + else
768 + ewarn "${i} symlink requested, but source file not found"
769 + ewarn "please report this"
770 + fi
771 + dosym "../lib/${PN}/${PV}/bin/${ver_i}" "/usr/bin/${ver_i}"
772 + done
773 +
774 + # symlinks to switch components to active rust in eselect
775 + dosym "${PV}/lib" "/usr/lib/${PN}/lib-${PV}"
776 + dosym "${PV}/libexec" "/usr/lib/${PN}/libexec-${PV}"
777 + dosym "${PV}/share/man" "/usr/lib/${PN}/man-${PV}"
778 + dosym "rust/${PV}/lib/rustlib" "/usr/lib/rustlib-${PV}"
779 + dosym "../../lib/${PN}/${PV}/share/doc/rust" "/usr/share/doc/${P}"
780 +
781 + newenvd - "50${P}" <<-_EOF_
782 + LDPATH="${EPREFIX}/usr/lib/rust/lib"
783 + MANPATH="${EPREFIX}/usr/lib/rust/man"
784 + _EOF_
785 +
786 + rm -rf "${ED}/usr/lib/${PN}/${PV}"/*.old || die
787 + rm -rf "${ED}/usr/lib/${PN}/${PV}/doc"/*.old || die
788 +
789 + # note: eselect-rust adds EROOT to all paths below
790 + cat <<-_EOF_ > "${T}/provider-${P}"
791 + /usr/bin/cargo
792 + /usr/bin/rustdoc
793 + /usr/bin/rust-gdb
794 + /usr/bin/rust-gdbgui
795 + /usr/bin/rust-lldb
796 + /usr/lib/rustlib
797 + /usr/lib/rust/lib
798 + /usr/lib/rust/libexec
799 + /usr/lib/rust/man
800 + /usr/share/doc/rust
801 + _EOF_
802 +
803 + if use clippy; then
804 + echo /usr/bin/clippy-driver >> "${T}/provider-${P}"
805 + echo /usr/bin/cargo-clippy >> "${T}/provider-${P}"
806 + fi
807 + if use miri; then
808 + echo /usr/bin/miri >> "${T}/provider-${P}"
809 + echo /usr/bin/cargo-miri >> "${T}/provider-${P}"
810 + fi
811 + if use profiler; then
812 + echo /usr/bin/rust-demangler >> "${T}/provider-${P}"
813 + fi
814 + if use rls; then
815 + echo /usr/bin/rls >> "${T}/provider-${P}"
816 + fi
817 + if use rustfmt; then
818 + echo /usr/bin/rustfmt >> "${T}/provider-${P}"
819 + echo /usr/bin/cargo-fmt >> "${T}/provider-${P}"
820 + fi
821 + if use rust-analyzer; then
822 + echo /usr/bin/rust-analyzer >> "${T}/provider-${P}"
823 + fi
824 +
825 + insinto /etc/env.d/rust
826 + doins "${T}/provider-${P}"
827 +
828 + if use dist; then
829 + insinto "/usr/lib/${PN}/${PV}/dist"
830 + doins -r "${S}/build/dist/."
831 + fi
832 +}
833 +
834 +pkg_postinst() {
835 + eselect rust update
836 +
837 + if has_version sys-devel/gdb || has_version dev-util/lldb; then
838 + elog "Rust installs a helper script for calling GDB and LLDB,"
839 + elog "for your convenience it is installed under /usr/bin/rust-{gdb,lldb}-${PV}."
840 + fi
841 +
842 + if has_version app-editors/emacs; then
843 + elog "install app-emacs/rust-mode to get emacs support for rust."
844 + fi
845 +
846 + if has_version app-editors/gvim || has_version app-editors/vim; then
847 + elog "install app-vim/rust-vim to get vim support for rust."
848 + fi
849 +}
850 +
851 +pkg_postrm() {
852 + eselect rust cleanup
853 +}