Gentoo Archives: gentoo-commits

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