dev-lang/rust: fix QA_SONAME regex
[gentoo.git] / dev-lang / rust / rust-1.40.0-r1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python2_7 python3_{5,6,7} pypy )
7
8 inherit bash-completion-r1 check-reqs estack flag-o-matic llvm multiprocessing multilib-build python-any-r1 rust-toolchain toolchain-funcs
9
10 if [[ ${PV} = *beta* ]]; then
11         betaver=${PV//*beta}
12         BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}"
13         MY_P="rustc-beta"
14         SLOT="beta/${PV}"
15         SRC="${BETA_SNAPSHOT}/rustc-beta-src.tar.xz"
16 else
17         ABI_VER="$(ver_cut 1-2)"
18         SLOT="stable/${ABI_VER}"
19         MY_P="rustc-${PV}"
20         SRC="${MY_P}-src.tar.xz"
21         KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~x86"
22 fi
23
24 RUST_STAGE0_VERSION="1.$(($(ver_cut 2) - 1)).0"
25
26 DESCRIPTION="Systems programming language from Mozilla"
27 HOMEPAGE="https://www.rust-lang.org/"
28
29 SRC_URI="
30         https://static.rust-lang.org/dist/${SRC} -> rustc-${PV}-src.tar.xz
31         !system-bootstrap? ( $(rust_all_arch_uris rust-${RUST_STAGE0_VERSION}) )
32 "
33
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[@]/%/?}
38
39 LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA"
40
41 IUSE="clippy cpu_flags_x86_sse2 debug doc libressl nightly parallel-compiler rls rustfmt system-bootstrap system-llvm wasm ${ALL_LLVM_TARGETS[*]}"
42
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
45 # simultaneously.
46
47 # How to use it:
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.
51 LLVM_DEPEND="
52         || (
53                 sys-devel/llvm:9[llvm_targets_WebAssembly?]
54                 wasm? ( =sys-devel/lld-9* )
55         )
56         <sys-devel/llvm-10:=
57 "
58 LLVM_MAX_SLOT=9
59
60 # FIXME:
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}* )"
64
65 COMMON_DEPEND="
66         sys-libs/zlib
67         !libressl? ( dev-libs/openssl:0= )
68         libressl? ( dev-libs/libressl:0= )
69         net-libs/libssh2
70         net-libs/http-parser:=
71         net-misc/curl[ssl]
72         system-llvm? (
73                 ${LLVM_DEPEND}
74         )
75 "
76
77 DEPEND="${COMMON_DEPEND}
78         ${PYTHON_DEPS}
79         || (
80                 >=sys-devel/gcc-4.7
81                 >=sys-devel/clang-3.5
82         )
83         system-bootstrap? ( ${BOOTSTRAP_DEPEND} )
84         system-llvm? (
85                 dev-util/cmake
86                 dev-util/ninja
87         )
88 "
89
90 RDEPEND="${COMMON_DEPEND}
91         >=app-eselect/eselect-rust-20190311
92 "
93
94 REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} )
95         parallel-compiler? ( nightly )
96         wasm? ( llvm_targets_WebAssembly )
97         x86? ( cpu_flags_x86_sse2 )
98 "
99
100 QA_FLAGS_IGNORED="
101         usr/bin/*-${PV}
102         usr/lib*/lib*.so
103         usr/lib/rustlib/*/codegen-backends/librustc_codegen_llvm-llvm.so
104         usr/lib/rustlib/*/lib/lib*.so
105 "
106
107 QA_SONAME="usr/lib.*/librustc_macros.*.so"
108
109 PATCHES=(
110         "${FILESDIR}"/1.36.0-libressl.patch
111         "${FILESDIR}"/1.40.0-add-soname.patch
112 )
113
114 S="${WORKDIR}/${MY_P}-src"
115
116 toml_usex() {
117         usex "$1" true false
118 }
119
120 pre_build_checks() {
121         CHECKREQS_DISK_BUILD="9G"
122         eshopts_push -s extglob
123         if is-flagq '-g?(gdb)?([1-9])'; then
124                 CHECKREQS_DISK_BUILD="14G"
125         fi
126         eshopts_pop
127         check-reqs_pkg_setup
128 }
129
130 pkg_pretend() {
131         pre_build_checks
132 }
133
134 pkg_setup() {
135         pre_build_checks
136         python-any-r1_pkg_setup
137         use system-llvm && llvm_pkg_setup
138 }
139
140 src_prepare() {
141         if ! use system-bootstrap; then
142                 local rust_stage0_root="${WORKDIR}"/rust-stage0
143                 local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi)"
144
145                 "${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig \
146                         --destdir="${rust_stage0_root}" --prefix=/ || die
147         fi
148
149         default
150 }
151
152 src_configure() {
153         local rust_target="" rust_targets="" arch_cflags
154
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##*.}))\""
158         done
159         if use wasm; then
160                 rust_targets="${rust_targets},\"wasm32-unknown-unknown\""
161         fi
162         rust_targets="${rust_targets#,}"
163
164         local extended="true" tools="\"cargo\","
165         if use clippy; then
166                 tools="\"clippy\",$tools"
167         fi
168         if use rls; then
169                 tools="\"rls\",\"analysis\",\"src\",$tools"
170         fi
171         if use rustfmt; then
172                 tools="\"rustfmt\",$tools"
173         fi
174
175         local rust_stage0_root
176         if use system-bootstrap; then
177                 rust_stage0_root="$(rustc --print sysroot)"
178         else
179                 rust_stage0_root="${WORKDIR}"/rust-stage0
180         fi
181
182         rust_target="$(rust_abi)"
183
184         cat <<- EOF > "${S}"/config.toml
185                 [llvm]
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)
192                 [build]
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)
200                 submodules = false
201                 python = "${EPYTHON}"
202                 locked-deps = true
203                 vendor = true
204                 extended = ${extended}
205                 tools = [${tools}]
206                 verbose = 2
207                 [install]
208                 prefix = "${EPREFIX}/usr"
209                 libdir = "lib"
210                 docdir = "share/doc/${PF}"
211                 mandir = "share/man"
212                 [rust]
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)"
219                 rpath = false
220                 lld = $(usex system-llvm false $(toml_usex wasm))
221                 [dist]
222                 src-tarball = false
223         EOF
224
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##*.})"
228
229                 cat <<- EOF >> "${S}"/config.env
230                         CFLAGS_${rust_target}=${arch_cflags}
231                 EOF
232
233                 cat <<- EOF >> "${S}"/config.toml
234                         [target.${rust_target}]
235                         cc = "$(tc-getBUILD_CC)"
236                         cxx = "$(tc-getBUILD_CXX)"
237                         linker = "$(tc-getCC)"
238                         ar = "$(tc-getAR)"
239                 EOF
240                 if use system-llvm; then
241                         cat <<- EOF >> "${S}"/config.toml
242                                 llvm-config = "$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config"
243                         EOF
244                 fi
245         done
246
247         if use wasm; then
248                 cat <<- EOF >> "${S}"/config.toml
249                         [target.wasm32-unknown-unknown]
250                         linker = "$(usex system-llvm lld rust-lld)"
251                 EOF
252         fi
253 }
254
255 src_compile() {
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
259 }
260
261 src_install() {
262         env DESTDIR="${D}" "${EPYTHON}" ./x.py install -vv --config="${S}"/config.toml \
263         --exclude src/tools/miri || die
264
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
269
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
276         if use clippy; then
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
279         fi
280         if use rls; then
281                 mv "${ED}/usr/bin/rls" "${ED}/usr/bin/rls-${PV}" || die
282         fi
283         if use rustfmt; then
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
286         fi
287
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
293         fi
294
295         dodoc COPYRIGHT
296
297         # note: eselect-rust adds EROOT to all paths below
298         cat <<-EOF > "${T}/provider-${P}"
299                 /usr/bin/rustdoc
300                 /usr/bin/rust-gdb
301                 /usr/bin/rust-gdbgui
302                 /usr/bin/rust-lldb
303         EOF
304         echo /usr/bin/cargo >> "${T}/provider-${P}"
305         if use clippy; then
306                 echo /usr/bin/clippy-driver >> "${T}/provider-${P}"
307                 echo /usr/bin/cargo-clippy >> "${T}/provider-${P}"
308         fi
309         if use rls; then
310                 echo /usr/bin/rls >> "${T}/provider-${P}"
311         fi
312         if use rustfmt; then
313                 echo /usr/bin/rustfmt >> "${T}/provider-${P}"
314                 echo /usr/bin/cargo-fmt >> "${T}/provider-${P}"
315         fi
316         dodir /etc/env.d/rust
317         insinto /etc/env.d/rust
318         doins "${T}/provider-${P}"
319 }
320
321 pkg_postinst() {
322         eselect rust update --if-unset
323
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}."
326
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}'."
330
331         if has_version app-editors/emacs; then
332                 elog "install app-emacs/rust-mode to get emacs support for rust."
333         fi
334
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."
337         fi
338 }
339
340 pkg_postrm() {
341         eselect rust cleanup
342 }