1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 python3_{5,6,7} pypy )
8 inherit bash-completion-r1 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 ~arm ~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/"
30 https://static.rust-lang.org/dist/${SRC} -> rustc-${PV}-src.tar.xz
31 !system-bootstrap? ( $(rust_all_arch_uris rust-${RUST_STAGE0_VERSION}) )
34 ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
35 NVPTX PowerPC RISCV Sparc SystemZ WebAssembly X86 XCore )
36 ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
37 LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
39 LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA"
41 IUSE="clippy cpu_flags_x86_sse2 debug doc libressl nightly parallel-compiler rls rustfmt system-bootstrap system-llvm wasm ${ALL_LLVM_TARGETS[*]}"
43 # Please keep the LLVM dependency block separate. Since LLVM is slotted,
44 # we need to *really* make sure we're not pulling more than one slot
48 # 1. List all the working slots (with min versions) in ||, newest first.
49 # 2. Update the := to specify *max* version, e.g. < 10.
50 # 3. Specify LLVM_MAX_SLOT, e.g. 9.
53 sys-devel/llvm:9[llvm_targets_WebAssembly?]
54 wasm? ( =sys-devel/lld-9* )
61 # this should be '>=virtual/rust-1.$(($(ver_cut 2) - 1))', but we can't do it yet
62 # as the first gentoo-built rust that can bootstap new compiler is 1.40.0-r1
63 BOOTSTRAP_DEPEND="|| ( =dev-lang/rust-${PVR} =dev-lang/rust-bin-${PV}* )"
67 !libressl? ( dev-libs/openssl:0= )
68 libressl? ( dev-libs/libressl:0= )
70 net-libs/http-parser:=
77 DEPEND="${COMMON_DEPEND}
83 system-bootstrap? ( ${BOOTSTRAP_DEPEND} )
90 RDEPEND="${COMMON_DEPEND}
91 >=app-eselect/eselect-rust-20190311
94 REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} )
95 parallel-compiler? ( nightly )
96 wasm? ( llvm_targets_WebAssembly )
97 x86? ( cpu_flags_x86_sse2 )
103 usr/lib/rustlib/*/codegen-backends/librustc_codegen_llvm-llvm.so
104 usr/lib/rustlib/*/lib/lib*.so
107 QA_SONAME="usr/lib.*/librustc_macros.*.so"
110 "${FILESDIR}"/1.36.0-libressl.patch
111 "${FILESDIR}"/1.40.0-add-soname.patch
114 S="${WORKDIR}/${MY_P}-src"
121 CHECKREQS_DISK_BUILD="9G"
122 eshopts_push -s extglob
123 if is-flagq '-g?(gdb)?([1-9])'; then
124 CHECKREQS_DISK_BUILD="14G"
136 python-any-r1_pkg_setup
137 use system-llvm && llvm_pkg_setup
141 if ! use system-bootstrap; then
142 local rust_stage0_root="${WORKDIR}"/rust-stage0
143 local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi)"
145 "${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig \
146 --destdir="${rust_stage0_root}" --prefix=/ || die
153 local rust_target="" rust_targets="" arch_cflags
155 # Collect rust target names to compile standard libs for all ABIs.
156 for v in $(multilib_get_enabled_abi_pairs); do
157 rust_targets="${rust_targets},\"$(rust_abi $(get_abi_CHOST ${v##*.}))\""
160 rust_targets="${rust_targets},\"wasm32-unknown-unknown\""
162 rust_targets="${rust_targets#,}"
164 local extended="true" tools="\"cargo\","
166 tools="\"clippy\",$tools"
169 tools="\"rls\",\"analysis\",\"src\",$tools"
172 tools="\"rustfmt\",$tools"
175 local rust_stage0_root
176 if use system-bootstrap; then
177 rust_stage0_root="$(rustc --print sysroot)"
179 rust_stage0_root="${WORKDIR}"/rust-stage0
182 rust_target="$(rust_abi)"
184 cat <<- EOF > "${S}"/config.toml
186 optimize = $(toml_usex !debug)
187 release-debuginfo = $(toml_usex debug)
188 assertions = $(toml_usex debug)
189 targets = "${LLVM_TARGETS// /;}"
190 experimental-targets = ""
191 link-shared = $(toml_usex system-llvm)
193 build = "${rust_target}"
194 host = ["${rust_target}"]
195 target = [${rust_targets}]
196 cargo = "${rust_stage0_root}/bin/cargo"
197 rustc = "${rust_stage0_root}/bin/rustc"
198 docs = $(toml_usex doc)
199 compiler-docs = $(toml_usex doc)
201 python = "${EPYTHON}"
204 extended = ${extended}
208 prefix = "${EPREFIX}/usr"
210 docdir = "share/doc/${PF}"
213 optimize = $(toml_usex !debug)
214 debug = $(toml_usex debug)
215 debug-assertions = $(toml_usex debug)
216 default-linker = "$(tc-getCC)"
217 parallel-compiler = $(toml_usex parallel-compiler)
218 channel = "$(usex nightly nightly stable)"
220 lld = $(usex system-llvm false $(toml_usex wasm))
225 for v in $(multilib_get_enabled_abi_pairs); do
226 rust_target=$(rust_abi $(get_abi_CHOST ${v##*.}))
227 arch_cflags="$(get_abi_CFLAGS ${v##*.})"
229 cat <<- EOF >> "${S}"/config.env
230 CFLAGS_${rust_target}=${arch_cflags}
233 cat <<- EOF >> "${S}"/config.toml
234 [target.${rust_target}]
235 cc = "$(tc-getBUILD_CC)"
236 cxx = "$(tc-getBUILD_CXX)"
237 linker = "$(tc-getCC)"
240 if use system-llvm; then
241 cat <<- EOF >> "${S}"/config.toml
242 llvm-config = "$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config"
248 cat <<- EOF >> "${S}"/config.toml
249 [target.wasm32-unknown-unknown]
250 linker = "$(usex system-llvm lld rust-lld)"
256 env $(cat "${S}"/config.env)\
257 "${EPYTHON}" ./x.py build -vv --config="${S}"/config.toml -j$(makeopts_jobs) \
258 --exclude src/tools/miri || die # https://github.com/rust-lang/rust/issues/52305
262 env DESTDIR="${D}" "${EPYTHON}" ./x.py install -vv --config="${S}"/config.toml \
263 --exclude src/tools/miri || die
265 # bug #689562, #689160
266 rm "${D}/etc/bash_completion.d/cargo" || die
267 rmdir "${D}"/etc{/bash_completion.d,} || die
268 dobashcomp build/tmp/dist/cargo-image/etc/bash_completion.d/cargo
270 mv "${ED}/usr/bin/rustc" "${ED}/usr/bin/rustc-${PV}" || die
271 mv "${ED}/usr/bin/rustdoc" "${ED}/usr/bin/rustdoc-${PV}" || die
272 mv "${ED}/usr/bin/rust-gdb" "${ED}/usr/bin/rust-gdb-${PV}" || die
273 mv "${ED}/usr/bin/rust-gdbgui" "${ED}/usr/bin/rust-gdbgui-${PV}" || die
274 mv "${ED}/usr/bin/rust-lldb" "${ED}/usr/bin/rust-lldb-${PV}" || die
275 mv "${ED}/usr/bin/cargo" "${ED}/usr/bin/cargo-${PV}" || die
277 mv "${ED}/usr/bin/clippy-driver" "${ED}/usr/bin/clippy-driver-${PV}" || die
278 mv "${ED}/usr/bin/cargo-clippy" "${ED}/usr/bin/cargo-clippy-${PV}" || die
281 mv "${ED}/usr/bin/rls" "${ED}/usr/bin/rls-${PV}" || die
284 mv "${ED}/usr/bin/rustfmt" "${ED}/usr/bin/rustfmt-${PV}" || die
285 mv "${ED}/usr/bin/cargo-fmt" "${ED}/usr/bin/cargo-fmt-${PV}" || die
288 # Move public shared libs to abi specific libdir
289 # Private and target specific libs MUST stay in /usr/lib/rustlib/${rust_target}/lib
290 if [[ $(get_libdir) != lib ]]; then
291 dodir /usr/$(get_libdir)
292 mv "${ED}/usr/lib"/*.so "${ED}/usr/$(get_libdir)/" || die
297 # note: eselect-rust adds EROOT to all paths below
298 cat <<-EOF > "${T}/provider-${P}"
304 echo /usr/bin/cargo >> "${T}/provider-${P}"
306 echo /usr/bin/clippy-driver >> "${T}/provider-${P}"
307 echo /usr/bin/cargo-clippy >> "${T}/provider-${P}"
310 echo /usr/bin/rls >> "${T}/provider-${P}"
313 echo /usr/bin/rustfmt >> "${T}/provider-${P}"
314 echo /usr/bin/cargo-fmt >> "${T}/provider-${P}"
316 dodir /etc/env.d/rust
317 insinto /etc/env.d/rust
318 doins "${T}/provider-${P}"
322 eselect rust update --if-unset
324 elog "Rust installs a helper script for calling GDB and LLDB,"
325 elog "for your convenience it is installed under /usr/bin/rust-{gdb,lldb}-${PV}."
327 ewarn "cargo is now installed from dev-lang/rust{,-bin} instead of dev-util/cargo."
328 ewarn "This might have resulted in a dangling symlink for /usr/bin/cargo on some"
329 ewarn "systems. This can be resolved by calling 'sudo eselect rust set ${P}'."
331 if has_version app-editors/emacs; then
332 elog "install app-emacs/rust-mode to get emacs support for rust."
335 if has_version app-editors/gvim || has_version app-editors/vim; then
336 elog "install app-vim/rust-vim to get vim support for rust."