Diff rust-1.90.0-r1 with a rust-1.92.0_p1-r1

/usr/portage/dev-lang/rust/rust-1.92.0_p1-r1.ebuild 2026-11-16 17:41:27.932399752 +0300
3 3

  
4 4
EAPI=8
5 5

  
6
LLVM_COMPAT=( 20 )
6
# Bump notes: https://wiki.gentoo.org/wiki/Project:Rust/Rust_bump
7

  
8
LLVM_COMPAT=( 21 )
7 9
PYTHON_COMPAT=( python3_{12..14} )
8 10

  
9
MRUSTC_VERSION="0.12.0"
10
MRUSTC_RUST_VERSION="1.90.0"
11
RUST_OPTIONAL=1
12

  
13
# We bumped the rust-patches tag without bumping the revision for
14
# https://bugs.gentoo.org/963657, given that ithe patch affects only a
15
# specific use case (bootstrap with Rust 1.90.0).
16
RUST_PATCH_VER=${PV}_p1
11
# Patches are kept in rust-patches.git, see its README.rst for the versioning
12
# scheme.
13
#
14
# We use _pN from the ebuild version for the patchset but it can be overridden
15
# in the ebuild for changes that don't require a revbump.
16
#
17
# Uncomment this line when the ebuild needs a patchset update but no revbump.
18
#RUST_PATCH_VER=${PV}-1
17 19

  
18 20
RUST_MAX_VER=${PV%%_*}
21
RUST_PV=${PV%%_p*}
22
RUST_P=${PN}-${RUST_PV}
23
[[ -z ${RUST_PATCH_VER} ]] && RUST_PATCH_VER=${PV}
24

  
19 25
if [[ ${PV} == *9999* ]]; then
20
	RUST_MIN_VER="1.88.0" # Update this as new `beta` releases come out.
26
	# Update this as new `beta` releases come out.
27
	RUST_MIN_VER="1.88.0"
21 28
elif [[ ${PV} == *beta* ]]; then
22 29
	RUST_MAX_VER="$(ver_cut 1).$(ver_cut 2).0"
23 30
	RUST_MIN_VER="$(ver_cut 1).$(($(ver_cut 2) - 1)).0"
......
28 35
# Bump vendored crates for openssl-4 support, bug #977001
29 36
# Upstream Issue: https://github.com/rust-lang/rust/issues/155397
30 37
CRATE_PATHS_OVERRIDE="
31
	curl@0.4.48
32
	curl-sys@0.4.77+curl-8.10.1
38
	curl@0.4.50
39
	curl-sys@0.4.89+curl-8.20.0
33 40
	openssl@0.10.81
34 41
	openssl-sys@0.9.117
35 42
"
36 43

  
37
inherit cargo check-reqs estack edo flag-o-matic llvm-r2 multiprocessing optfeature
44
inherit cargo check-reqs estack flag-o-matic llvm-r2 multiprocessing optfeature
38 45
inherit multilib multilib-build python-any-r1 rust-toolchain toolchain-funcs verify-sig
39 46

  
40 47
if [[ ${PV} = *9999* ]]; then
......
45 52
	betaver=${PV//*beta}
46 53
	BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}"
47 54
	MY_P="rustc-beta"
48
	SRC_URI="https://static.rust-lang.org/dist/${BETA_SNAPSHOT}/rustc-beta-src.tar.xz -> rustc-${PV}-src.tar.xz
55
	SRC_URI="
56
		https://static.rust-lang.org/dist/${BETA_SNAPSHOT}/rustc-beta-src.tar.xz -> rustc-${RUST_PV}-src.tar.xz
49 57
		https://gitweb.gentoo.org/proj/rust-patches.git/snapshot/rust-patches-${RUST_PATCH_VER}.tar.bz2
50
		verify-sig? ( https://static.rust-lang.org/dist/${BETA_SNAPSHOT}/rustc-beta-src.tar.xz.asc
51
			-> rustc-${PV}-src.tar.xz.asc )
58
		verify-sig? (
59
			https://static.rust-lang.org/dist/${BETA_SNAPSHOT}/rustc-beta-src.tar.xz.asc
60
				-> rustc-${RUST_PV}-src.tar.xz.asc
61
		)
52 62
	"
53 63
	S="${WORKDIR}/${MY_P}-src"
54 64
else
55
	MY_P="rustc-${PV}"
56
	SRC_URI="https://static.rust-lang.org/dist/${MY_P}-src.tar.xz
65
	MY_P="rustc-${RUST_PV}"
66
	SRC_URI="
67
		https://static.rust-lang.org/dist/${MY_P}-src.tar.xz
57 68
		https://gitweb.gentoo.org/proj/rust-patches.git/snapshot/rust-patches-${RUST_PATCH_VER}.tar.bz2
58 69
		verify-sig? ( https://static.rust-lang.org/dist/${MY_P}-src.tar.xz.asc )
59 70
	"
60 71
	S="${WORKDIR}/${MY_P}-src"
72

  
61 73
	KEYWORDS="amd64 arm arm64 ~loong ~mips ppc ppc64 ~riscv ~sparc x86"
62 74
fi
63 75

  
......
69 81
HOMEPAGE="https://www.rust-lang.org/"
70 82

  
71 83
# keep in sync with llvm ebuild of the same version as bundled one.
72
ALL_LLVM_TARGETS=( AArch64 AMDGPU ARC ARM AVR BPF CSKY DirectX Hexagon Lanai
73
	LoongArch M68k Mips MSP430 NVPTX PowerPC RISCV Sparc SPIRV SystemZ VE
74
	WebAssembly X86 XCore Xtensa )
84
ALL_LLVM_TARGETS=( AArch64 AMDGPU ARC ARM AVR BPF CSKY DirectX Hexagon Lanai )
85
ALL_LLVM_TARGETS+=( LoongArch M68k Mips MSP430 NVPTX PowerPC RISCV Sparc SPIRV )
86
ALL_LLVM_TARGETS+=( SystemZ VE WebAssembly X86 XCore Xtensa )
75 87
ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
76 88
LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/(-)?}
77 89

  
......
90 102
LICENSE="|| ( MIT Apache-2.0 ) BSD BSD-1 BSD-2 BSD-4"
91 103
SLOT="${PV%%_*}" # Beta releases get to share the same SLOT as the eventual stable
92 104

  
93
IUSE="big-endian clippy cpu_flags_x86_sse2 debug dist doc llvm-libunwind lto mrustc-bootstrap"
94
IUSE+=" rustfmt rust-analyzer rust-src +system-llvm test ${ALL_LLVM_TARGETS[*]} ${ALL_RUST_SYSROOTS[*]}"
105
IUSE="big-endian clippy cpu_flags_x86_sse2 debug dist doc llvm-libunwind lto"
106
IUSE+=" rustfmt rust-analyzer rust-src +system-llvm test"
107
IUSE+=" ${ALL_LLVM_TARGETS[*]} ${ALL_RUST_SYSROOTS[*]}"
95 108

  
96 109
if [[ ${PV} = *9999* ]]; then
97 110
	# These USE flags require nightly rust
......
110 123
LLVM_DEPEND+=( "	$(llvm_gen_dep 'llvm-core/llvm:${LLVM_SLOT}')" )
111 124

  
112 125
# dev-libs/oniguruma is used for documentation
113
BDEPEND="${PYTHON_DEPS}
126
BDEPEND="
127
	${PYTHON_DEPS}
114 128
	app-eselect/eselect-rust
115 129
	dev-libs/oniguruma
116 130
	|| (
......
123 137
			sys-devel/mold
124 138
		)
125 139
	) )
140
	rust_sysroots_wasm? ( llvm-core/clang )
126 141
	!system-llvm? (
127 142
		>=dev-build/cmake-3.13.4
128 143
		app-alternatives/ninja
129 144
	)
130 145
	test? ( dev-debug/gdb )
131 146
	verify-sig? ( sec-keys/openpgp-keys-rust )
132
	mrustc-bootstrap? (
133
		amd64? ( ~dev-lang/mrustc-${MRUSTC_VERSION} )
134
		arm64? ( ~dev-lang/mrustc-0.12.0_p20261018 )
135
		dev-build/cmake
136
		sys-devel/gcc:*
137
	)
138
	!mrustc-bootstrap? ( ${RUST_DEPEND} )
139 147
"
140 148

  
141 149
DEPEND="
......
154 162
	)
155 163
"
156 164

  
157
RDEPEND="${DEPEND}
165
RDEPEND="
166
	${DEPEND}
158 167
	app-eselect/eselect-rust
159 168
	dev-lang/rust-common
160 169
	sys-apps/lsb-release
......
162 171
	!dev-lang/rust-bin:stable
163 172
"
164 173

  
165
REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} )
174
REQUIRED_USE="
175
	|| ( ${ALL_LLVM_TARGETS[*]} )
166 176
	rust-analyzer? ( rust-src )
167 177
	test? ( ${ALL_LLVM_TARGETS[*]} )
168 178
	rust_sysroots_bpf? ( llvm_targets_BPF )
......
271 281
			die "Must enable LLVM_TARGETS=${cross_llvm_target} matching CBUILD=${CBUILD} when cross-compiling"
272 282
	fi
273 283

  
274
	if use mrustc-bootstrap; then
275
		if ! tc-is-gcc; then
276
			# USE="mrustc-bootstrap" reqires that the build environment use GCC
277
			export CC=${CHOST}-gcc
278
			export CXX=${CHOST}-g++
279
			tc-is-gcc || die "tc-is-gcc failed in spite of CC=${CC}"
280
		fi
281
	else
282
		rust_pkg_setup
283
	fi
284
	rust_pkg_setup
284 285

  
285 286
	if use system-llvm; then
286 287
		llvm-r2_pkg_setup
......
351 352
		_EOF_
352 353
	elif use verify-sig ; then
353 354
		# Patch tarballs are not signed (but we trust Gentoo infra)
354
		verify-sig_verify_detached "${DISTDIR}"/rustc-${PV}-src.tar.xz{,.asc}
355
		verify-sig_verify_detached "${DISTDIR}"/rustc-${RUST_PV}-src.tar.xz{,.asc}
355 356
		cargo_src_unpack
356 357
		ln -s "${ECARGO_VENDOR}"/* "${S}/vendor/"
357 358
	else
......
361 362
}
362 363

  
363 364
src_prepare() {
364
	if [[ ${PV} = *9999* ]]; then
365
		# We need to update / generate lockfiles for the workspace
366
		${CARGO} generate-lockfile --offline || die "Failed to generate lockfiles"
367
	fi
368

  
369 365
	# Commit patches to the appropriate branch in proj/rust-patches.git
370 366
	# then cut a new tag / tarball. Don't add patches to ${FILESDIR}
371 367
	PATCHES=(
372 368
		"${WORKDIR}/rust-patches-${RUST_PATCH_VER}/"
373 369
	)
374
	# Apply patches for bootstrapping with a particular Rust version (RUST_SLOT).
375
	if [[ -n ${RUST_SLOT} ]]; then # Not set set if using mrustc-bootstrap
376
		local bootstrap_patchdir="${WORKDIR}/rust-patches-${RUST_PATCH_VER}/${RUST_SLOT}"
377
		if [[ -d "${bootstrap_patchdir}" ]]; then
378
			PATCHES+=(
379
				"${bootstrap_patchdir}"
380
			)
381
		fi
382
	fi
383 370

  
384 371
	if use lto && tc-is-clang && ! tc-ld-is-lld && ! tc-ld-is-mold; then
385 372
		export RUSTFLAGS+=" -C link-arg=-fuse-ld=lld"
386 373
	fi
387 374

  
388 375
	default
389

  
390
	if use mrustc-bootstrap; then
391
		pushd "${S}" 2>/dev/null || die
392
		einfo "Applying patches to enable bootstrap with mrustc ${MRUSTC_VERSION}"
393
		patch -p0 < "${BROOT}"/usr/share/mrustc-${MRUSTC_VERSION}/patches/rustc-${MRUSTC_RUST_VERSION}-src.patch ||
394
			die "Failed to patch sources to enable bootstrap with mrustc"
395
		popd 2>/dev/null || die
396
	fi
397 376
}
398 377

  
399 378
src_configure() {
......
442 421
		use miri && tools+=',"miri"'
443 422
	fi
444 423

  
445
	if use mrustc-bootstrap; then
446
		local rust_stage0_root="${WORKDIR}/bootstrap/rust-${PV}"
447
	else
448
		local rust_stage0_root="$(${RUSTC} --print sysroot || die "Can't determine rust's sysroot")"
449
		# in case of prefix it will be already prefixed, as --print sysroot returns full path
450
		[[ -d ${rust_stage0_root} ]] || die "${rust_stage0_root} is not a directory"
451
	fi
424
	local rust_stage0_root="$(${RUSTC} --print sysroot || die "Can't determine rust's sysroot")"
425
	# in case of prefix it will be already prefixed, as --print sysroot returns full path
426
	[[ -d ${rust_stage0_root} ]] || die "${rust_stage0_root} is not a directory"
452 427

  
453 428
	rust_target="$(rust_abi)"
454 429
	rust_build="$(rust_abi "${CBUILD}")"
......
476 451
			build_channel="stable"
477 452
			;;
478 453
	esac
454

  
455
	# TODO: Add optimized-compiler-builtins for system-llvm to avoid
456
	# building bundled compiler-rt.
479 457
	cat <<- _EOF_ > "${S}"/bootstrap.toml
480 458
		# Suppresses a warning about tracking changes which we don't care about.
481 459
		change-id = "ignore"
......
624 602
	done
625 603
	if use rust_sysroots_wasm; then
626 604
		wasm_target="wasm32-unknown-unknown"
627
		export CFLAGS_${wasm_target//-/_}="$(filter-flags '-mcpu*' '-march*' '-mtune*'; echo "$CFLAGS")"
605
		if tc-is-clang; then
606
			local wasm_cc=$(tc-getCC)
607
			local wasm_cxx=$(tc-getCXX)
608
		else
609
			local wasm_cc=${CHOST}-clang
610
			local wasm_cxx=${CHOST}-clang++
611
		fi
612
		export CFLAGS_${wasm_target//-/_}="$(
613
			CC="${wasm_cc} --target=wasm32-unknown-unknown"
614
			filter-flags '-mcpu*' '-march*' '-mtune*'
615
			strip-unsupported-flags
616
			echo "${CFLAGS}"
617
		)"
628 618
		cat <<- _EOF_ >> "${S}"/bootstrap.toml
629 619
			[target.wasm32-unknown-unknown]
620
			cc = "${wasm_cc}"
621
			cxx = "${wasm_cxx}"
630 622
			linker = "$(usex system-llvm lld rust-lld)"
631 623
			# wasm target does not have profiler_builtins https://bugs.gentoo.org/848483
632 624
			profiler = false
......
736 728
	echo
737 729
}
738 730

  
739
llvm_bootstrap() {
740
	# Reference ${P}/src/bootstrap/native.rs for these values
741
	local llvm_cmake_opts=(
742
		"-G Ninja"
743
		"-DLLVM_TARGET_ARCH=${CFG_COMPILER_HOST_TRIPLE%%-*}"
744
		"-DLLVM_DEFAULT_TARGET_TRIPLE=${CFG_COMPILER_HOST_TRIPLE}"
745
		#;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX
746
		"-DLLVM_TARGETS_TO_BUILD=${BOOTSTRAP_LLVM_TARGETS:=X86;ARM;AArch64}"
747
		"-DLLVM_ENABLE_ASSERTIONS=OFF"
748
		"-DLLVM_INCLUDE_EXAMPLES=OFF"
749
		"-DLLVM_INCLUDE_TESTS=OFF"
750
		"-DLLVM_INCLUDE_DOCS=OFF"
751
		"-DLLVM_INCLUDE_BENCHMARKS=OFF"
752
		"-DLLVM_ENABLE_ZLIB=OFF"
753
		"-DLLVM_ENABLE_TERMINFO=OFF"
754
		"-DLLVM_ENABLE_LIBEDIT=OFF"
755
		"-DCMAKE_CXX_COMPILER=$(tc-getCXX)"
756
		"-DCMAKE_C_COMPILER=$(tc-getCC)"
757
		"-DCMAKE_BUILD_TYPE=Release"
758
	)
759

  
760
	if [[ -z "${LLVM_CMAKE_OPTS_EXTRA}" ]]; then
761
		llvm_cmake_opts+=( "${LLVM_CMAKE_OPTS_EXTRA}")
762
	fi
763

  
764
	elog "Building bootstrap llvm ..."
765

  
766
	mkdir -p "${WORKDIR}/bootstrap/llvm" || die
767
	pushd "${WORKDIR}/bootstrap/llvm" 2>/dev/null || die
768
		edo cmake ${llvm_cmake_opts[*]} "${S}/src/llvm-project/llvm"
769
		eninja || die "Failed to build bootstrap llvm"
770
	popd 2>/dev/null || die
771
}
772

  
773
# High level steps:
774
# Our system mrustc package has built stdlib for our current platform.
775
# - Step 1: Use system-installed mrustc, (m)rust(c) stdlib, and minicargo to
776
#	bootstrap a `cargo` and `rustc` (mrustc-stage0)
777
# - Step 2: Use minicargo and the built `rustc` to build a working `sysroot`
778
#			(includes `std`, `panic_unwind``, `test`, etc.) (mrustc-stage0)
779
# - Step 3: Build build libs again (this time using `cargo` and `rustc`) (mrustc-stage1)
780
# - Step 4: Build a `rustc` using those libs (mrustc-stage1)
781
#  - Done so there's an optimised rustc around (mrustc is bad at codegen)
782
# - Step 5: Build `libstd` with this `rustc` (mrustc-stage2)
783
#  - Needed to match ABIs
784
# Stages:
785
# - mrustc-stage0: mrustc-built cargo and rustc
786
# - mrustc-stage1: rustc and sysroot built with mrustc-stage0
787
# - mrustc-stage2: rustc from stage1 with sysroot built with stage0
788
# See:
789
# - https://github.com/thepowersgang/mrustc/blob/master/run_rustc/Makefile
790
# - https://github.com/thepowersgang/mrustc/blob/master/TestRustcBootstrap.sh
791
# - Upstream Windows .cmd files are also a good reference for early bootstrap
792
mrustc_bootstrap() {
793
	export RUSTC_BOOTSTRAP=1 # Possibly the only intended use of this variable in ::gentoo
794
	# export these variables now and unset them at the end of the function so they don't leak
795
	# into the rest of the build.
796
	export CFG_COMPILER_HOST_TRIPLE="$(rust_abi)"
797
	export CFG_RELEASE="${MRUSTC_RUST_VERSION}"	# Let's pretend we're 1.90.0
798
	export CFG_RELEASE_CHANNEL="stable"
799
	export CFG_VERSION="${MRUSTC_RUST_VERSION}-stable-mrustc"
800
	export CFG_PREFIX="mrustc"
801
	export CFG_LIBDIR_RELATIVE="lib"
802
	# We actually patch our executable, but this suppresses a warning on every invocation of the bootstrap compiler.
803
	export MRUSTC_TARGET_VER="${MRUSTC_RUST_VERSION%.*}"
804
	export RUSTC_INSTALL_BINDIR="bin"
805
	export REAL_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
806
	export STD_ENV_ARCH="${CFG_COMPILER_HOST_TRIPLE%%-*}"
807

  
808
	# These flags are used in every invocation of our bootstrap `cargo`.
809
	local cargo_flags="--target ${CFG_COMPILER_HOST_TRIPLE} -j $(makeopts_jobs) --release --verbose"
810

  
811
	# for bootstrap, let's using the built-in stdlib of compiler (could be the bundled one)
812
	filter-flags '-stdlib=*'
813

  
814
	# mrustc requires gcc, so disable libcxx to avoid linker failure on w/o '-lstdc++'
815
	[[ "${LLVM_USE_LIBCXX}" == "1" ]] && unset LLVM_USE_LIBCXX
816

  
817
	local llvm_config_wrapper_cxxflags=0
818

  
819
	if use system-llvm; then
820
		export LLVM_CONFIG="$(get_llvm_prefix)/bin/llvm-config"
821

  
822
		local llvm_config_cxxflags=$(${LLVM_CONFIG} --cxxflags)
823
		elog "Checking llvm-config --cxxflags: '${llvm_config_cxxflags}'"
824
		[[ "${llvm_config_cxxflags}" =~ (^|[[:space:]])-stdlib=libc\+\+([[:space:]]|$) ]] && {
825
			elog "Found LLVM CXXFLAGS has \"--stdlib=libc++\""
826
			llvm_config_wrapper_cxxflags=1
827
		}
828
	else
829
		llvm_bootstrap
830
		export LLVM_CONFIG="${WORKDIR}/bootstrap/llvm/bin/llvm-config"
831
	fi
832

  
833
	elog "LLVM_CONFIG before wrappers: ${LLVM_CONFIG}"
834

  
835
	# workaround for gcc bug 122409 on musl by wrapping llvm-config
836
	# to append libc++ header if has "-stdlib=libc++"
837
	elog "Preparing wrapper of llvm-config (${WORKDIR}/llvm-config)"
838
	cat > ${WORKDIR}/llvm-config <<-EOF || die
839
	#!/bin/bash
840

  
841
	RULES=()
842
	for flag in "\$@"; do
843
	    case "\${flag}" in
844
	$([[ "${llvm_config_wrapper_cxxflags}" == 1 ]] && {
845
		echo "        --cxxflags) RULES+=( \"-E\" \"s@(^|[[:space:]]+)(-stdlib=libc\\+\\+)(\\$|[[:space:]])@\\1-I${EPREFIX}/usr/include/c++/v1 \\2\\3@g\" ) ;;"
846
	})
847
	        *)
848
	            ;;
849
	    esac
850
	done
851

  
852
	[[ -z "\${RULES}" ]] && {
853
	    ${LLVM_CONFIG} "\$@"
854
	} || {
855
	    ${LLVM_CONFIG} "\$@" | \\
856
	        tee -a ${T}/llvm-config.0.log | \\
857
	        sed "\${RULES[@]}" | \\
858
	        tee -a ${T}/llvm-config.1.log
859
	    exit \${PIPESTATUS[0]}
860
	}
861
	EOF
862
	export LLVM_CONFIG="${WORKDIR}/llvm-config"
863
	chmod +x ${WORKDIR}/llvm-config || die
864

  
865
	einfo "llvm-config wrapper contents:"
866
	cat "${LLVM_CONFIG}" || die
867
	echo
868

  
869
	# define the mrustc sysroot and common minicargo arguments.
870
	local mrustc_sysroot="${BROOT}/usr/lib/rust/mrustc-${MRUSTC_VERSION}/lib/rustlib/${CFG_COMPILER_HOST_TRIPLE}/lib"
871
	local minicargo_common_args=(
872
		"-L" "${mrustc_sysroot}"
873
		"-j" "$(makeopts_jobs)"
874
		"--vendor-dir" "${S}/vendor"
875
		"--manifest-overrides"
876
		"${BROOT}/usr/share/mrustc-${MRUSTC_VERSION}/patches/rustc-${MRUSTC_RUST_VERSION}-overrides.toml"
877
	)
878
	# There's a very good chance that minicargo and mrustc are not in the PATH.
879
	if ! command -v minicargo &> /dev/null; then
880
		export PATH="${BROOT}/usr/lib/rust/mrustc-${MRUSTC_VERSION}/bin:${PATH}"
881
	fi
882
	# Sanity check our bootstrap compiler & stdlib.
883
	elog "Sanity checking mrustc and stdlib ..."
884
	edo mrustc "${S}/tests/ui/parallel-rustc/hello_world.rs" -L "${mrustc_sysroot}" -o "${T}"/hello -g
885
	"${T}"/hello || die "Failed to run hello_world"
886
	# Seems fine, let's build some tools!
887

  
888
	# Step 1: Build a `cargo` and `rustc` using system-installed mrustc
889
	# Anything we produce is going to be terribly unoptimised; mrustc does not do fantastic codegen.
890
	# It's good enough to bootstrap the "real" rustc though.
891
	elog "Building bootstrap cargo and rustc using mrustc and minicargo (mrustc-stage0) ..."
892
	local stage0="${WORKDIR}/bootstrap/mrustc-stage0"
893
	mkdir -p "${stage0}" || die
894
	edo minicargo "${S}"/src/tools/cargo --output-dir "${stage0}"/cargo-build ${minicargo_common_args[*]}
895
	"${stage0}"/cargo-build/cargo --version || die "Bootstrap cargo failed basic sanity check"
896
	edo minicargo "${S}"/compiler/rustc --output-dir "${stage0}"/rustc-build ${minicargo_common_args[*]} \
897
		--features llvm
898
	"${stage0}"/rustc-build/rustc_main --version || die "Bootstrap rustc failed basic sanity check"
899
	# minicargo has special-casing for `rustc` so we need to rename it.
900
	mv "${stage0}"/rustc-build/rustc_main "${stage0}"/rustc-build/rustc || die "Failed to rename rustc_main to rustc"
901
	# rustc wants these here
902
	mkdir -p "${stage0}"/codegen-backends || die
903
	mv "${stage0}"/rustc-build/librustc_codegen_llvm.* "${stage0}"/codegen-backends || die
904

  
905
	# Step 2: use the bootstrapped rustc to build sysroot; we need to use `minicargo` for this -
906
	# mrustc does not accept all of the arguments that rustc does, even with the rustc_proxy wrapper.
907
	# `--script-overrides`:  If the overrides are available, build scripts (and build-deps) are not built
908
	# which is good since we don't have a working compiler yet, and can't build them.
909

  
910
	local stage0_sysroot_lib="${stage0}/lib/rustlib/${CFG_COMPILER_HOST_TRIPLE}/lib"
911
	# minicargo <= 0.12.0 doesn't create this directory and silently fails, besides it's better to be explicit, right?
912
	mkdir -p "${stage0_sysroot_lib}" || die "Failed to create stage0 directory"
913

  
914
	elog "Building 'sysroot' using bootstrap rustc (mrustc-stage0) ..."
915
	local o_dir="${BROOT}/usr/share/mrustc-${MRUSTC_VERSION}/script-overrides/stable-${MRUSTC_RUST_VERSION}-linux/"
916
	edo env MRUSTC_PATH="${stage0}/rustc-build/rustc" minicargo -j $(makeopts_jobs) --vendor-dir "${S}"/vendor \
917
		--script-overrides  "${o_dir}" \
918
		--output-dir "${stage0_sysroot_lib}" "${S}"/library/sysroot ||
919
			die "Failed to build sysroot with bootstrap rust (mrustc-stage0)"
920

  
921
	elog "Sanity checking sysroot and rustc ..."
922
	mkdir -p "${T}"/stage0-hello || die
923
	edo "${stage0}"/rustc-build/rustc -L "${stage0_sysroot_lib}" -g "${S}/tests/ui/parallel-rustc/hello_world.rs" \
924
		-o "${T}"/stage0-hello/hello
925
	"${T}"/stage0-hello/hello || die "Failed to run hello_world built with bootstrap rust stage0"
926

  
927
	elog "mrustc bootstrap stage0 complete!"
928

  
929
	# Step 3: Build a "proper" libstd, including dynamic libs using our bootstrap cargo and rustc.
930
	elog "Building 'sysroot' with the stage0 rustc (mrustc-stage1) ..."
931
	local stage1="${WORKDIR}/bootstrap/mrustc-stage1"
932
	local stage1_sysroot_lib="${stage1}/lib/rustlib/${CFG_COMPILER_HOST_TRIPLE}/lib"
933
	mkdir -p "${stage1_sysroot_lib}" || die "Failed to create stage1 directory"
934
	mkdir -p "${stage1}/bin" || die
935

  
936
	# Simplified to avoid calling rustc_proxy; We don't need stage1 rustc until after this is built...
937
	edo env RUSTFLAGS="-Z force-unstable-if-unmarked" CARGO_TARGET_DIR="${stage1}/sysroot-build" \
938
		RUSTC="${stage0}/rustc-build/rustc" "${stage0}"/cargo-build/cargo build ${cargo_flags} \
939
		--manifest-path "${S}/library/sysroot/Cargo.toml" --features panic-unwind
940

  
941
	# Move the built libs into the sysroot libdir.
942
	mv "${stage1}/sysroot-build/${CFG_COMPILER_HOST_TRIPLE}/release/deps"/*.{rlib,rmeta,so} \
943
		"${stage1_sysroot_lib}" || die "Failed to move stage1 libs to stage1 sysroot"
944

  
945
	# We need to copy the stage0 rustc to the stage1 sysroot; this "updates" the sysroot location and enables
946
	# resolution of stage1 libs. (run `rustc --print sysroot` on stage0 and stage1 rustc to verify)
947
	cp "${stage0}/rustc-build/rustc" "${stage1}/bin/rustc" || die "Failed to copy rustc to stage1 sysroot"
948

  
949
	# Step 4: Build `rustc` with itself, so we have a rustc with the right ABI.
950
	# This will be our final `rustc` for the bootstrap process.
951
	elog "Building rustc with stage1 libs (mrustc-stage1) ..."
952
	mkdir -p "${stage1}/rustc-build" || die
953
	edo env RUSTFLAGS="-Z force-unstable-if-unmarked -C link_args=-Wl,-rpath,\$ORIGIN/../lib" \
954
		LD_LIBRARY_PATH="${stage2_sysroot_lib}" CARGO_TARGET_DIR="${stage1}/rustc-build" \
955
		RUSTC="${stage1}/bin/rustc" TMPDIR="${T}" "${stage0}"/cargo-build/cargo build ${cargo_flags} \
956
		--manifest-path "${S}/compiler/rustc/Cargo.toml"  --features llvm
957

  
958
	# Step 5: Build `sysroot` with this `rustc` - Needed to match ABI
959
	# We need to use the previous sysroot; we could reuse that dir but it's easier to just copy it.
960
	elog "Building final 'sysroot' with the final rustc (mrustc-stage2) ..."
961
	local stage2="${WORKDIR}/bootstrap/mrustc-stage2"
962
	local stage2_sysroot_lib="${stage2}/lib/rustlib/${CFG_COMPILER_HOST_TRIPLE}/lib"
963
	mkdir -p "${stage2_sysroot_lib}" || die "Failed to create stage2 directory"
964
	mkdir -p "${stage2}/bin" || die
965

  
966
	# Copy required files from stage1 to stage2 sysroot
967
	cp "${stage1}/rustc-build/${CFG_COMPILER_HOST_TRIPLE}"/release/rustc-main "${stage2}/bin/rustc_binary" ||
968
		die "Failed to copy final rustc to stage2 sysroot"
969
	cp "${stage1}/rustc-build/${CFG_COMPILER_HOST_TRIPLE}"/release/librustc_driver.so "${stage2}/lib" ||
970
		die "Failed to copy librustc_driver to sysroot"
971
	cp "${stage1}/rustc-build/${CFG_COMPILER_HOST_TRIPLE}"/release/deps/*.{rlib,so} "${stage2_sysroot_lib}" ||
972
		die "Failed to copy final rustc libs to stage2 sysroot"
973
	cp "${stage1_sysroot_lib}"/* "${stage2_sysroot_lib}" || die "Failed to copy stage1 so files to stage2 sysroot"
974

  
975
	# There's a magic script used in place of rustc so that libs can be found
976
	cat <<- EOF > "${stage2}/bin/rustc" || die "Failed to create rustc wrapper"
977
		#!/bin/sh
978
		LD_LIBRARY_PATH="${stage2}/lib:${stage2_sysroot_lib}" ${stage2}/bin/rustc_binary "\$@"
979
	EOF
980
	chmod +x "${stage2}/bin/rustc" || die "Failed to make rustc wrapper executable"
981

  
982
	# Use rustc to build 'sysroot'; this is the final step in the bootstrap process.
983
	# rpath probably isn't needed here, but it doesn't hurt.
984
	edo env RUSTFLAGS="-Z force-unstable-if-unmarked -C link_args=-Wl,-rpath,\$ORIGIN/../lib" \
985
		CARGO_TARGET_DIR="${stage2}/stdlib-build" RUSTC="${stage2}/bin/rustc" \
986
		"${stage0}"/cargo-build/cargo build ${cargo_flags} --manifest-path "${S}/library/sysroot/Cargo.toml" \
987
		--features panic-unwind
988

  
989
	# Build our final output sysroot
990
	local output="${WORKDIR}/bootstrap/rust-${PV}"
991
	local output_sysroot_lib="${output}/lib/rustlib/${CFG_COMPILER_HOST_TRIPLE}/lib"
992
	mkdir -p "${output_sysroot_lib}" || die "Failed to create output directory"
993
	mkdir -p "${output}/bin" || die "Failed to create output directory"
994

  
995
	# Copy our various output files into the output sysroot
996
	# rustc
997
	cp "${stage1}/rustc-build/${CFG_COMPILER_HOST_TRIPLE}"/release/rustc-main "${output}/bin/rustc_binary" ||
998
		die "Failed to copy final rustc to output"
999
	cp "${stage1}/rustc-build/${CFG_COMPILER_HOST_TRIPLE}"/release/librustc_driver.so "${output}/lib" ||
1000
		die "Failed to copy librustc_driver to output"
1001
	cp "${stage1}/rustc-build/${CFG_COMPILER_HOST_TRIPLE}"/release/deps/*.{rlib,so} "${output_sysroot_lib}" ||
1002
		die "Failed to copy final rustc libs to output"
1003
	# cargo; no need to build an optimised cargo if we're using this to build a complelety new Rust.
1004
	cp "${stage0}/cargo-build/cargo" "${output}/bin/cargo" || die "Failed to copy cargo to output"
1005
	# libs
1006
	mv "${stage2}/stdlib-build/${CFG_COMPILER_HOST_TRIPLE}/release/deps"/*.{rlib,rmeta,so} "${output_sysroot_lib}" ||
1007
		die "Failed to copy stage2 libs to output"
1008
	# Our trusty rustc wrapper
1009
	cat <<- EOF > "${output}/bin/rustc" || die "Failed to create rustc wrapper"
1010
		#!/bin/sh
1011
		LD_LIBRARY_PATH="${output}/lib:${output_sysroot_lib}" ${output}/bin/rustc_binary "\$@"
1012
	EOF
1013
	chmod +x "${output}/bin/rustc" || die "Failed to make rustc wrapper executable"
1014

  
1015
	# Perform a sanity check on the final Rust.
1016
	mkdir -p "${T}"/output-hello || die
1017
	edo "${output}/bin/rustc" -L "${output_sysroot_lib}" -g "${S}/tests/ui/parallel-rustc/hello_world.rs" \
1018
		-o "${T}"/output-hello/hello
1019
	"${T}"/output-hello/hello || die "Failed to run hello_world built with bootstrapped Rust"
1020

  
1021
	elog "Successfully bootstrapped Rust using mrustc!"
1022

  
1023
	# Note: The Rust sysroot that we've produced is pretty close to what we'd expect from a normal Rust build.
1024
	# If someone was so inclined they could build an optimised cargo using the stage2 rustc and sysroot,
1025
	# and install the output directly. This is untested, as I'm sure there's more to it than that.
1026
	# I'm satisfied with being able to build Rust normally at this point.
1027

  
1028
	# Tidy up the Rust sources; revert mrustc changes so Rust can be built normally.
1029
	pushd "${S}" 2>/dev/null || die
1030
		patch -R -p0 < "${BROOT}"/usr/share/mrustc-${MRUSTC_VERSION}/patches/rustc-${MRUSTC_RUST_VERSION}-src.patch ||
1031
			die "Failed to revert mrustc patches"
1032
	popd 2>/dev/null || die
1033

  
1034
	# Tidy up any environment variables we've set in the bootstrap process.
1035
	unset CFG_COMPILER_HOST_TRIPLE CFG_RELEASE CFG_RELEASE_CHANNEL CFG_PREFIX CFG_VERSION CFG_LIBDIR_RELATIVE
1036
	unset LLVM_CONFIG MRUSTC_TARGET_VER REAL_LIBRARY_PATH_VAR RUSTFLAGS RUSTC_BOOTSTRAP RUSTC_INSTALL_BINDIR
1037
}
1038

  
1039 731
src_compile() {
1040
	use mrustc-bootstrap && mrustc_bootstrap
1041 732
	# -v will show invocations, -vv "very verbose" is overkill, -vvv "very very verbose" is insane
1042 733
	RUST_BACKTRACE=1 "${EPYTHON}" ./x.py build -v --config="${S}"/bootstrap.toml -j$(makeopts_jobs) || die
1043 734
}
......
1099 790

  
1100 791
	docompress /usr/lib/${PN}/${SLOT}/share/man/
1101 792

  
1102
	# bug #689562, #689160
793
	# bash-completion files are installed by dev-lang/rust-common instead
794
	# bug #689562, #689160.
1103 795
	rm -v "${ED}/usr/lib/${PN}/${SLOT}/etc/bash_completion.d/cargo" || die
1104
	rmdir -v "${ED}/usr/lib/${PN}/${SLOT}"/etc{/bash_completion.d,} || die
796
	rmdir -v "${ED}/usr/lib/${PN}/${SLOT}/etc/bash_completion.d" || die
1105 797

  
1106 798
	local symlinks=(
1107 799
		cargo
......
1125 817
		# we need realpath on /usr/bin/* symlink return version-appended binary path.
1126 818
		# so /usr/bin/rustc should point to /usr/lib/rust/<ver>/bin/rustc-<ver>
1127 819
		# need to fix eselect-rust to remove this hack.
1128
		local ver_i="${i}-${PV%%_*}"
820
		local ver_i="${i}-${RUST_PV%%_*}"
1129 821
		if [[ -f "${ED}/usr/lib/${PN}/${SLOT}/bin/${i}" ]]; then
1130 822
			einfo "Installing ${i} symlink"
1131 823
			ln -v "${ED}/usr/lib/${PN}/${SLOT}/bin/${i}" "${ED}/usr/lib/${PN}/${SLOT}/bin/${ver_i}" || die
......
1141 833
	use rust-analyzer && dosym "${SLOT}/libexec" "/usr/lib/${PN}/libexec-${SLOT}"
1142 834
	dosym "${SLOT}/share/man" "/usr/lib/${PN}/man-${SLOT}"
1143 835
	dosym "rust/${SLOT}/lib/rustlib" "/usr/lib/rustlib-${SLOT}"
1144
	dosym "../../lib/${PN}/${SLOT}/share/doc/rust" "/usr/share/doc/${P}"
836
	dosym "../../lib/${PN}/${SLOT}/share/doc/rust" "/usr/share/doc/${RUST_P}"
1145 837

  
1146
	newenvd - "50${P}" <<-_EOF_
838
	newenvd - "50${RUST_P}" <<-_EOF_
1147 839
		MANPATH="${EPREFIX}/usr/lib/rust/man-${SLOT}"
1148 840
	_EOF_
1149 841

  
......
1165 857
	_EOF_
1166 858

  
1167 859
	if use clippy; then
1168
		echo /usr/bin/clippy-driver >> "${T}/provider-${P}"
1169
		echo /usr/bin/cargo-clippy >> "${T}/provider-${P}"
860
		echo /usr/bin/clippy-driver >> "${T}/provider-${RUST_P}"
861
		echo /usr/bin/cargo-clippy >> "${T}/provider-${RUST_P}"
1170 862
	fi
1171 863
	if [[ ${SLOT} == *9999* ]] && use miri; then
1172
		echo /usr/bin/miri >> "${T}/provider-${P}"
1173
		echo /usr/bin/cargo-miri >> "${T}/provider-${P}"
864
		echo /usr/bin/miri >> "${T}/provider-${RUST_P}"
865
		echo /usr/bin/cargo-miri >> "${T}/provider-${RUST_P}"
1174 866
	fi
1175 867
	if use rustfmt; then
1176
		echo /usr/bin/rustfmt >> "${T}/provider-${P}"
1177
		echo /usr/bin/cargo-fmt >> "${T}/provider-${P}"
868
		echo /usr/bin/rustfmt >> "${T}/provider-${RUST_P}"
869
		echo /usr/bin/cargo-fmt >> "${T}/provider-${RUST_P}"
1178 870
	fi
1179 871
	if use rust-analyzer; then
1180
		echo /usr/lib/rust/libexec >> "${T}/provider-${P}"
1181
		echo /usr/bin/rust-analyzer >> "${T}/provider-${P}"
872
		echo /usr/lib/rust/libexec >> "${T}/provider-${RUST_P}"
873
		echo /usr/bin/rust-analyzer >> "${T}/provider-${RUST_P}"
1182 874
	fi
1183 875

  
1184 876
	insinto /etc/env.d/rust
......
1192 884
}
1193 885

  
1194 886
pkg_postinst() {
1195

  
1196 887
	eselect rust update
1197 888

  
1198 889
	if has_version dev-debug/gdb || has_version llvm-core/lldb; then
1199 890
		elog "Rust installs helper scripts for calling GDB and LLDB,"
1200
		elog "for convenience they are installed under /usr/bin/rust-{gdb,lldb}-${PV}."
891
		elog "for convenience they are installed under /usr/bin/rust-{gdb,lldb}-${RUST_PV}."
1201 892
	fi
1202 893

  
1203 894
	if has_version app-editors/emacs; then
Thank you!