1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 python3_{6,7} )
8 inherit check-reqs estack flag-o-matic llvm multiprocessing multilib-build python-any-r1 rust-toolchain toolchain-funcs
10 if [[ ${PV} = *beta* ]]; then
12 BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}"
15 SRC="${BETA_SNAPSHOT}/rustc-beta-src.tar.xz"
17 ABI_VER="$(ver_cut 1-2)"
18 SLOT="stable/${ABI_VER}"
20 SRC="${MY_P}-src.tar.xz"
21 KEYWORDS="amd64 arm64 ppc64 x86"
24 RUST_STAGE0_VERSION="1.$(($(ver_cut 2) - 1)).0"
26 DESCRIPTION="Systems programming language from Mozilla"
27 HOMEPAGE="https://www.rust-lang.org/"
29 SRC_URI="https://static.rust-lang.org/dist/${SRC} -> rustc-${PV}-src.tar.xz
30 $(rust_all_arch_uris rust-${RUST_STAGE0_VERSION})"
32 ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
33 NVPTX PowerPC Sparc SystemZ WebAssembly X86 XCore )
34 ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
35 LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
37 LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA"
39 IUSE="clippy cpu_flags_x86_sse2 debug doc libressl rls rustfmt system-llvm wasm ${ALL_LLVM_TARGETS[*]}"
41 # Please keep the LLVM dependency block separate. Since LLVM is slotted,
42 # we need to *really* make sure we're not pulling one than more slot
46 # 1. List all the working slots (with min versions) in ||, newest first.
47 # 2. Update the := to specify *max* version, e.g. < 9.
48 # 3. Specify LLVM_MAX_SLOT, e.g. 8.
51 sys-devel/llvm:8[llvm_targets_WebAssembly?]
52 wasm? ( =sys-devel/lld-8* )
60 !libressl? ( dev-libs/openssl:0= )
61 libressl? ( dev-libs/libressl:0= )
63 net-libs/http-parser:=
70 DEPEND="${COMMON_DEPEND}
79 RDEPEND="${COMMON_DEPEND}
80 >=app-eselect/eselect-rust-20190311
82 rustfmt? ( !dev-util/rustfmt )
85 REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} )
86 wasm? ( llvm_targets_WebAssembly )
87 x86? ( cpu_flags_x86_sse2 )
91 "${FILESDIR}"/0001-llvm-cmake-Add-additional-headers-only-if-they-exist.patch
92 "${FILESDIR}"/1.34.2-fix-custom-libdir.patch
93 "${FILESDIR}"/1.35.0-revert-commits-triggering-multiple-llvm-rebuilds.patch
94 "${FILESDIR}"/1.36.0-libressl.patch
97 S="${WORKDIR}/${MY_P}-src"
104 CHECKREQS_DISK_BUILD="7G"
105 eshopts_push -s extglob
106 if is-flagq '-g?(gdb)?([1-9])'; then
107 CHECKREQS_DISK_BUILD="10G"
119 python-any-r1_pkg_setup
120 use system-llvm && llvm_pkg_setup
124 local rust_stage0_root="${WORKDIR}"/rust-stage0
126 local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi)"
128 "${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig --destdir="${rust_stage0_root}" --prefix=/ || die
134 local rust_target="" rust_targets="" arch_cflags
136 # Collect rust target names to compile standard libs for all ABIs.
137 for v in $(multilib_get_enabled_abi_pairs); do
138 rust_targets="${rust_targets},\"$(rust_abi $(get_abi_CHOST ${v##*.}))\""
141 rust_targets="${rust_targets},\"wasm32-unknown-unknown\""
143 rust_targets="${rust_targets#,}"
145 local extended="true" tools="\"cargo\","
147 tools="\"clippy\",$tools"
150 tools="\"rls\",\"analysis\",\"src\",$tools"
153 tools="\"rustfmt\",$tools"
156 local rust_stage0_root="${WORKDIR}"/rust-stage0
158 rust_target="$(rust_abi)"
160 cat <<- EOF > "${S}"/config.toml
162 optimize = $(toml_usex !debug)
163 release-debuginfo = $(toml_usex debug)
164 assertions = $(toml_usex debug)
165 targets = "${LLVM_TARGETS// /;}"
166 experimental-targets = ""
167 link-shared = $(toml_usex system-llvm)
169 build = "${rust_target}"
170 host = ["${rust_target}"]
171 target = [${rust_targets}]
172 cargo = "${rust_stage0_root}/bin/cargo"
173 rustc = "${rust_stage0_root}/bin/rustc"
174 docs = $(toml_usex doc)
176 python = "${EPYTHON}"
179 extended = ${extended}
183 prefix = "${EPREFIX}/usr"
184 libdir = "$(get_libdir)/${P}"
185 docdir = "share/doc/${P}"
186 mandir = "share/${P}/man"
188 optimize = $(toml_usex !debug)
189 debug = $(toml_usex debug)
190 debug-assertions = $(toml_usex debug)
191 default-linker = "$(tc-getCC)"
194 lld = $(usex system-llvm false $(toml_usex wasm))
197 for v in $(multilib_get_enabled_abi_pairs); do
198 rust_target=$(rust_abi $(get_abi_CHOST ${v##*.}))
199 arch_cflags="$(get_abi_CFLAGS ${v##*.})"
201 cat <<- EOF >> "${S}"/config.env
202 CFLAGS_${rust_target}=${arch_cflags}
205 cat <<- EOF >> "${S}"/config.toml
206 [target.${rust_target}]
207 cc = "$(tc-getBUILD_CC)"
208 cxx = "$(tc-getBUILD_CXX)"
209 linker = "$(tc-getCC)"
212 if use system-llvm; then
213 cat <<- EOF >> "${S}"/config.toml
214 llvm-config = "$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config"
220 cat <<- EOF >> "${S}"/config.toml
221 [target.wasm32-unknown-unknown]
222 linker = "$(usex system-llvm lld rust-lld)"
228 env $(cat "${S}"/config.env)\
229 "${EPYTHON}" ./x.py build -vv --config="${S}"/config.toml -j$(makeopts_jobs) \
230 --exclude src/tools/miri || die # https://github.com/rust-lang/rust/issues/52305
234 local rust_target abi_libdir
236 env DESTDIR="${D}" "${EPYTHON}" ./x.py install -vv --config="${S}"/config.toml \
237 --exclude src/tools/miri || die
239 mv "${ED}/usr/bin/rustc" "${ED}/usr/bin/rustc-${PV}" || die
240 mv "${ED}/usr/bin/rustdoc" "${ED}/usr/bin/rustdoc-${PV}" || die
241 mv "${ED}/usr/bin/rust-gdb" "${ED}/usr/bin/rust-gdb-${PV}" || die
242 mv "${ED}/usr/bin/rust-gdbgui" "${ED}/usr/bin/rust-gdbgui-${PV}" || die
243 mv "${ED}/usr/bin/rust-lldb" "${ED}/usr/bin/rust-lldb-${PV}" || die
244 mv "${ED}/usr/bin/cargo" "${ED}/usr/bin/cargo-${PV}" || die
246 mv "${ED}/usr/bin/clippy-driver" "${ED}/usr/bin/clippy-driver-${PV}" || die
247 mv "${ED}/usr/bin/cargo-clippy" "${ED}/usr/bin/cargo-clippy-${PV}" || die
250 mv "${ED}/usr/bin/rls" "${ED}/usr/bin/rls-${PV}" || die
253 mv "${ED}/usr/bin/rustfmt" "${ED}/usr/bin/rustfmt-${PV}" || die
254 mv "${ED}/usr/bin/cargo-fmt" "${ED}/usr/bin/cargo-fmt-${PV}" || die
257 # Copy shared library versions of standard libraries for all targets
258 # into the system's abi-dependent lib directories because the rust
259 # installer only does so for the native ABI.
260 for v in $(multilib_get_enabled_abi_pairs); do
261 if [ ${v##*.} = ${DEFAULT_ABI} ]; then
264 abi_libdir=$(get_abi_LIBDIR ${v##*.})
265 rust_target=$(rust_abi $(get_abi_CHOST ${v##*.}))
266 mkdir -p "${ED}/usr/${abi_libdir}/${P}"
267 cp "${ED}/usr/$(get_libdir)/${P}/rustlib/${rust_target}/lib"/*.so \
268 "${ED}/usr/${abi_libdir}/${P}" || die
274 # Really not sure if that env is needed, specailly LDPATH
275 cat <<-EOF > "${T}"/50${P}
276 LDPATH="${EPREFIX}/usr/$(get_libdir)/${P}"
277 MANPATH="${EPREFIX}/usr/share/${P}/man"
281 # note: eselect-rust adds EROOT to all paths below
282 cat <<-EOF > "${T}/provider-${P}"
288 echo /usr/bin/cargo >> "${T}/provider-${P}"
290 echo /usr/bin/clippy-driver >> "${T}/provider-${P}"
291 echo /usr/bin/cargo-clippy >> "${T}/provider-${P}"
294 echo /usr/bin/rls >> "${T}/provider-${P}"
297 echo /usr/bin/rustfmt >> "${T}/provider-${P}"
298 echo /usr/bin/cargo-fmt >> "${T}/provider-${P}"
300 dodir /etc/env.d/rust
301 insinto /etc/env.d/rust
302 doins "${T}/provider-${P}"
306 eselect rust update --if-unset
308 elog "Rust installs a helper script for calling GDB and LLDB,"
309 elog "for your convenience it is installed under /usr/bin/rust-{gdb,lldb}-${PV}."
311 ewarn "cargo is now installed from dev-lang/rust{,-bin} instead of dev-util/cargo."
312 ewarn "This might have resulted in a dangling symlink for /usr/bin/cargo on some"
313 ewarn "systems. This can be resolved by calling 'sudo eselect rust set ${P}'."
315 if has_version app-editors/emacs; then
316 elog "install app-emacs/rust-mode to get emacs support for rust."
319 if has_version app-editors/gvim || has_version app-editors/vim; then
320 elog "install app-vim/rust-vim to get vim support for rust."