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