|
| 1 | +# Copyright 1999-2017 Gentoo Foundation |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=6 |
| 5 | + |
| 6 | +PYTHON_COMPAT=( python2_7 ) |
| 7 | + |
| 8 | +LLVM_MAX_SLOT=4 |
| 9 | + |
| 10 | +inherit python-any-r1 versionator toolchain-funcs llvm |
| 11 | + |
| 12 | +if [[ ${PV} = *beta* ]]; then |
| 13 | + betaver=${PV//*beta} |
| 14 | + BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}" |
| 15 | + MY_P="rustc-beta" |
| 16 | + SLOT="beta/${PV}" |
| 17 | + SRC="${BETA_SNAPSHOT}/rustc-beta-src.tar.gz" |
| 18 | + KEYWORDS="" |
| 19 | +else |
| 20 | + ABI_VER="$(get_version_component_range 1-2)" |
| 21 | + SLOT="stable/${ABI_VER}" |
| 22 | + MY_P="rustc-${PV}" |
| 23 | + SRC="${MY_P}-src.tar.gz" |
| 24 | + KEYWORDS="~amd64 ~x86" |
| 25 | +fi |
| 26 | + |
| 27 | +CHOST_amd64=x86_64-unknown-linux-gnu |
| 28 | +CHOST_x86=i686-unknown-linux-gnu |
| 29 | + |
| 30 | +RUST_STAGE0_VERSION="1.$(($(get_version_component_range 2) - 1)).0" |
| 31 | +RUST_STAGE0_amd64="rust-${RUST_STAGE0_VERSION}-${CHOST_amd64}" |
| 32 | +RUST_STAGE0_x86="rust-${RUST_STAGE0_VERSION}-${CHOST_x86}" |
| 33 | + |
| 34 | +CARGO_DEPEND_VERSION="0.$(($(get_version_component_range 2) + 1)).0" |
| 35 | + |
| 36 | +DESCRIPTION="Systems programming language from Mozilla" |
| 37 | +HOMEPAGE="http://www.rust-lang.org/" |
| 38 | + |
| 39 | +SRC_URI="https://static.rust-lang.org/dist/${SRC} -> rustc-${PV}-src.tar.gz |
| 40 | + amd64? ( https://static.rust-lang.org/dist/${RUST_STAGE0_amd64}.tar.gz ) |
| 41 | + x86? ( https://static.rust-lang.org/dist/${RUST_STAGE0_x86}.tar.gz ) |
| 42 | +" |
| 43 | + |
| 44 | +LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA" |
| 45 | + |
| 46 | +IUSE="clang debug doc jemalloc llvm" |
| 47 | +REQUIRED_USE="clang? ( llvm )" |
| 48 | + |
| 49 | +RDEPEND="" |
| 50 | +DEPEND="${RDEPEND} |
| 51 | + ${PYTHON_DEPS} |
| 52 | + clang? ( |
| 53 | + <sys-devel/clang-6_pre:= |
| 54 | + || ( |
| 55 | + sys-devel/clang:4 |
| 56 | + >=sys-devel/clang-3:0 |
| 57 | + ) |
| 58 | + ) |
| 59 | + !clang? ( >=sys-devel/gcc-4.7 ) |
| 60 | + dev-util/cmake |
| 61 | +" |
| 62 | +PDEPEND=">=app-eselect/eselect-rust-0.3_pre20150425 |
| 63 | + >=dev-util/cargo-${CARGO_DEPEND_VERSION}" |
| 64 | + |
| 65 | +PATCHES=( |
| 66 | + "${FILESDIR}/${P}"-bootstrap-output-name-of-failed-config.patch |
| 67 | + "${FILESDIR}/${P}"-bootstrap-verbose.patch |
| 68 | +) |
| 69 | + |
| 70 | +S="${WORKDIR}/${MY_P}-src" |
| 71 | + |
| 72 | +toml_usex() { |
| 73 | + usex "$1" true false |
| 74 | +} |
| 75 | + |
| 76 | +pkg_setup() { |
| 77 | + python-any-r1_pkg_setup |
| 78 | + llvm_pkg_setup |
| 79 | +} |
| 80 | + |
| 81 | +src_prepare() { |
| 82 | + local rust_stage0_root="${WORKDIR}"/rust-stage0 |
| 83 | + |
| 84 | + local rust_stage0_name="RUST_STAGE0_${ARCH}" |
| 85 | + local rust_stage0="${!rust_stage0_name}" |
| 86 | + |
| 87 | + "${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig --destdir="${rust_stage0_root}" --prefix=/ || die |
| 88 | + |
| 89 | + default |
| 90 | +} |
| 91 | + |
| 92 | +src_configure() { |
| 93 | + local rust_stage0_root="${WORKDIR}"/rust-stage0 |
| 94 | + |
| 95 | + local rust_target_name="CHOST_${ARCH}" |
| 96 | + local rust_target="${!rust_target_name}" |
| 97 | + |
| 98 | + local archiver="$(tc-getAR)" |
| 99 | + local linker="$(tc-getCC)" |
| 100 | + if use llvm ; then |
| 101 | + # Gentoo currently lacks CHOST prefixed binaries for sys-devel/llvm |
| 102 | + # https://bugs.gentoo.org/show_bug.cgi?id=617776 |
| 103 | + #archiver="${CHOST}"-llvm-ar |
| 104 | + #linker="${CHOST}"-llvm-link |
| 105 | + archiver=llvm-ar |
| 106 | + linker=llvm-link |
| 107 | + fi |
| 108 | + |
| 109 | + local llvm_config="$(get_llvm_prefix)/bin/${CBUILD}-llvm-config" |
| 110 | + local c_compiler="$(tc-getBUILD_CC)" |
| 111 | + local cxx_compiler="$(tc-getBUILD_CXX)" |
| 112 | + if use clang ; then |
| 113 | + c_compiler="${CBUILD}-clang" |
| 114 | + cxx_compiler="${CBUILD}-clang++" |
| 115 | + fi |
| 116 | + |
| 117 | + cat <<- EOF > "${S}"/config.toml |
| 118 | + [llvm] |
| 119 | + optimize = $(toml_usex !debug) |
| 120 | + release-debuginfo = $(toml_usex debug) |
| 121 | + assertions = $(toml_usex debug) |
| 122 | + [build] |
| 123 | + build = "${rust_target}" |
| 124 | + host = ["${rust_target}"] |
| 125 | + target = ["${rust_target}"] |
| 126 | + cargo = "${rust_stage0_root}/bin/cargo" |
| 127 | + rustc = "${rust_stage0_root}/bin/rustc" |
| 128 | + docs = $(toml_usex doc) |
| 129 | + submodules = false |
| 130 | + python = "${EPYTHON}" |
| 131 | + locked-deps = true |
| 132 | + vendor = true |
| 133 | + verbose = 2 |
| 134 | + [install] |
| 135 | + prefix = "${EPREFIX}/usr" |
| 136 | + libdir = "$(get_libdir)/${P}" |
| 137 | + docdir = "share/doc/${P}" |
| 138 | + mandir = "share/${P}/man" |
| 139 | + [rust] |
| 140 | + optimize = $(toml_usex !debug) |
| 141 | + debuginfo = $(toml_usex debug) |
| 142 | + debug-assertions = $(toml_usex debug) |
| 143 | + use-jemalloc = $(toml_usex jemalloc) |
| 144 | + default-linker = "${linker}" |
| 145 | + default-ar = "${archiver}" |
| 146 | + rpath = false |
| 147 | + [target.${rust_target}] |
| 148 | + cc = "${c_compiler}" |
| 149 | + cxx = "${cxx_compiler}" |
| 150 | + llvm-config = "${llvm_config}" |
| 151 | + EOF |
| 152 | +} |
| 153 | + |
| 154 | +src_compile() { |
| 155 | + export RUST_BACKTRACE=1 |
| 156 | + export LLVM_LINK_SHARED=1 |
| 157 | + |
| 158 | + ./x.py build --verbose --config="${S}"/config.toml || die |
| 159 | +} |
| 160 | + |
| 161 | +src_install() { |
| 162 | + env DESTDIR="${D}" ./x.py dist --install || die |
| 163 | + |
| 164 | + mv "${D}/usr/bin/rustc" "${D}/usr/bin/rustc-${PV}" || die |
| 165 | + mv "${D}/usr/bin/rustdoc" "${D}/usr/bin/rustdoc-${PV}" || die |
| 166 | + mv "${D}/usr/bin/rust-gdb" "${D}/usr/bin/rust-gdb-${PV}" || die |
| 167 | + |
| 168 | + dodoc COPYRIGHT |
| 169 | + |
| 170 | + if use doc ; then |
| 171 | + dodir "/usr/share/doc/rust-${PV}/" |
| 172 | + mv "${D}/usr/share/doc/rust"/* "${D}/usr/share/doc/rust-${PV}/" || die |
| 173 | + rmdir "${D}/usr/share/doc/rust/" || die |
| 174 | + fi |
| 175 | + |
| 176 | + cat <<-EOF > "${T}"/50${P} |
| 177 | + LDPATH="/usr/$(get_libdir)/${P}" |
| 178 | + MANPATH="/usr/share/${P}/man" |
| 179 | + EOF |
| 180 | + doenvd "${T}"/50${P} |
| 181 | + |
| 182 | + cat <<-EOF > "${T}/provider-${P}" |
| 183 | + /usr/bin/rustdoc |
| 184 | + /usr/bin/rust-gdb |
| 185 | + EOF |
| 186 | + dodir /etc/env.d/rust |
| 187 | + insinto /etc/env.d/rust |
| 188 | + doins "${T}/provider-${P}" |
| 189 | +} |
| 190 | + |
| 191 | +pkg_postinst() { |
| 192 | + eselect rust update --if-unset |
| 193 | + |
| 194 | + elog "Rust installs a helper script for calling GDB now," |
| 195 | + elog "for your convenience it is installed under /usr/bin/rust-gdb-${PV}." |
| 196 | + |
| 197 | + if has_version app-editors/emacs || has_version app-editors/emacs-vcs; then |
| 198 | + elog "install app-emacs/rust-mode to get emacs support for rust." |
| 199 | + fi |
| 200 | + |
| 201 | + if has_version app-editors/gvim || has_version app-editors/vim; then |
| 202 | + elog "install app-vim/rust-vim to get vim support for rust." |
| 203 | + fi |
| 204 | + |
| 205 | + if has_version 'app-shells/zsh'; then |
| 206 | + elog "install app-shells/rust-zshcomp to get zsh completion for rust." |
| 207 | + fi |
| 208 | +} |
| 209 | + |
| 210 | +pkg_postrm() { |
| 211 | + eselect rust unset --if-invalid |
| 212 | +} |
0 commit comments