Daniel Verkamp | d6c4428 | 2019-03-21 10:38:30 -0700 | [diff] [blame^] | 1 | # Copyright 1999-2018 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | |
| 4 | EAPI=5 |
| 5 | |
| 6 | PYTHON_COMPAT=( python2_7 ) |
| 7 | inherit python-any-r1 versionator toolchain-funcs |
| 8 | |
| 9 | if [[ ${PV} = *beta* ]]; then |
| 10 | betaver=${PV//*beta} |
| 11 | BETA_SNAPSHOT="${betaver:0:4}-${betaver:4:2}-${betaver:6:2}" |
| 12 | MY_P="rustc-beta" |
| 13 | SLOT="beta/${PV}" |
| 14 | SRC="${BETA_SNAPSHOT}/rustc-beta-src.tar.gz" |
| 15 | KEYWORDS="" |
| 16 | else |
| 17 | ABI_VER="$(get_version_component_range 1-2)" |
| 18 | SLOT="stable/${ABI_VER}" |
| 19 | MY_P="rustc-${PV}" |
| 20 | SRC="${MY_P}-src.tar.gz" |
| 21 | KEYWORDS="*" |
| 22 | fi |
| 23 | |
| 24 | |
| 25 | STAGE0_VERSION="1.$(($(get_version_component_range 2) - 1)).0" |
| 26 | STAGE0_VERSION_CARGO="0.$(($(get_version_component_range 2))).0" |
| 27 | STAGE0_DATE="2019-01-17" |
| 28 | RUST_STAGE0_amd64="rustc-${STAGE0_VERSION}-x86_64-unknown-linux-gnu" |
| 29 | |
| 30 | DESCRIPTION="Systems programming language from Mozilla" |
| 31 | HOMEPAGE="http://www.rust-lang.org/" |
| 32 | |
| 33 | SRC_URI="https://static.rust-lang.org/dist/${SRC} -> rustc-${PV}-src.tar.gz |
| 34 | https://static.rust-lang.org/dist/${STAGE0_DATE}/rust-std-${STAGE0_VERSION}-x86_64-unknown-linux-gnu.tar.gz |
| 35 | https://static.rust-lang.org/dist/${RUST_STAGE0_amd64}.tar.gz |
| 36 | https://static.rust-lang.org/dist/cargo-${STAGE0_VERSION_CARGO}-x86_64-unknown-linux-gnu.tar.gz |
| 37 | " |
| 38 | |
| 39 | LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA" |
| 40 | |
| 41 | RESTRICT="binchecks strip" |
| 42 | REQUIRED_USE="amd64" |
| 43 | |
| 44 | DEPEND="${PYTHON_DEPS} |
| 45 | >=dev-libs/libxml2-2.9.6 |
| 46 | >=dev-lang/perl-5.0 |
| 47 | " |
| 48 | |
| 49 | PATCHES=( |
| 50 | "${FILESDIR}"/0001-add-cros-targets.patch |
| 51 | "${FILESDIR}"/0002-fix-rpath.patch |
| 52 | "${FILESDIR}"/0003-enable-sanitizers.patch |
| 53 | "${FILESDIR}"/0004-Revert-CMake-Unconditionally-add-.h-and-.td-files-to.patch |
| 54 | "${FILESDIR}"/0005-libstd-sanitizer-paths.patch |
| 55 | "${FILESDIR}"/0006-sanitizer-lib-boilerplate.patch |
| 56 | ) |
| 57 | |
| 58 | S="${WORKDIR}/${MY_P}-src" |
| 59 | |
| 60 | # This is the list of target triples as they appear in the cros_sdk. If this list gets changed, |
| 61 | # ensure that each of these values has a corresponding librustc_target/spec file created below |
| 62 | # and a line referring to it in 0001-add-cros-targets.patch. |
| 63 | RUSTC_TARGET_TRIPLES=( |
| 64 | x86_64-pc-linux-gnu |
| 65 | x86_64-cros-linux-gnu |
| 66 | armv7a-cros-linux-gnueabihf |
| 67 | aarch64-cros-linux-gnu |
| 68 | ) |
| 69 | |
| 70 | pkg_setup() { |
| 71 | python-any-r1_pkg_setup |
| 72 | # Skips the toolchain check if we are installing a binpkg. |
| 73 | if [[ "${MERGE_TYPE}" != "binary" ]]; then |
| 74 | local tt |
| 75 | for tt in "${RUSTC_TARGET_TRIPLES[@]}" ; do |
| 76 | which "${tt}-clang" >/dev/null || die "missing toolchain ${tt}" |
| 77 | done |
| 78 | fi |
| 79 | } |
| 80 | |
| 81 | src_prepare() { |
| 82 | local stagename="RUST_STAGE0_${ARCH}" |
| 83 | local stage0="${!stagename}" |
| 84 | |
| 85 | cp -r "${WORKDIR}"/rust-std-${STAGE0_VERSION}-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu \ |
| 86 | "${WORKDIR}"/${stage0}/rustc/lib/rustlib || die |
| 87 | |
| 88 | # Copy "unknown" vendor targets to create cros_sdk target triple |
| 89 | # variants as referred to in 0001-add-cros-targets.patch and RUSTC_TARGET_TRIPLES. |
| 90 | # armv7a is treated specially because the cros toolchain differs in |
| 91 | # more than just the vendor part of the target triple. The arch is |
| 92 | # armv7a in cros versus armv7. |
| 93 | pushd src/librustc_target/spec || die |
| 94 | sed -e 's:"unknown":"pc":g' x86_64_unknown_linux_gnu.rs >x86_64_pc_linux_gnu.rs || die |
| 95 | sed -e 's:"unknown":"cros":g' x86_64_unknown_linux_gnu.rs >x86_64_cros_linux_gnu.rs || die |
| 96 | sed -e 's:"unknown":"cros":g' armv7_unknown_linux_gnueabihf.rs >armv7a_cros_linux_gnueabihf.rs || die |
| 97 | sed -e 's:"unknown":"cros":g' aarch64_unknown_linux_gnu.rs >aarch64_cros_linux_gnu.rs || die |
| 98 | popd |
| 99 | |
| 100 | # One of the patches changes a vendored library, thereby changing the |
| 101 | # checksum. |
| 102 | pushd vendor/compiler_builtins || die |
| 103 | sed -i 's:66e76e0e8016a6a4e5d5b0a4a08a83051b24699047bda3a54dc18593cfef7801:183ce3f632aaceea80d6544eb631128b98f0d562d7c730061c7e49c1d8cd0f0d:g' \ |
| 104 | .cargo-checksum.json |
| 105 | popd |
| 106 | |
| 107 | # The miri tool is built because of 'extended = true' in cros-config.toml, |
| 108 | # but the build is busted. See the upstream issue: [https://github.com/rust- |
| 109 | # lang/rust/issues/56576]. Because miri isn't installed or needed, this sed |
| 110 | # script eradicates the command that builds it during the bootstrap script. |
| 111 | pushd src/bootstrap || die |
| 112 | sed -i 's@tool::Miri,@@g' builder.rs |
| 113 | popd |
| 114 | |
| 115 | # Tsk. Tsk. The rust makefile for LLVM's compiler-rt uses -ffreestanding |
| 116 | # but one of the files includes <stdlib.h> causing occasional problems |
| 117 | # with MB_LEN_MAX. See crbug.com/730845 for the thrilling details. This |
| 118 | # line patches over the problematic include. This must go here because |
| 119 | # src/compiler-rt is a submodule that only gets filled in after |
| 120 | # ./configure. |
| 121 | sed -e 's:#include <stdlib.h>:void abort(void);:g' \ |
| 122 | -i "${ECONF_SOURCE:-.}"/vendor/compiler_builtins/compiler-rt/lib/builtins/int_util.c || die |
| 123 | |
| 124 | epatch "${PATCHES[@]}" |
| 125 | |
| 126 | # For the librustc_llvm module, the build will link with -nodefaultlibs and manually choose the |
| 127 | # std C++ library. For x86_64 Linux, the build script always chooses libstdc++ which will not |
| 128 | # work if LLVM was built with USE="default-libcxx". This snippet changes that choice to libc++ |
| 129 | # in the case that clang++ defaults to libc++. |
| 130 | if "${CXX}" -### -x c++ - < /dev/null 2>&1 | grep -q -e '-lc++'; then |
| 131 | sed -i 's:"stdc++":"c++":g' src/librustc_llvm/build.rs || die |
| 132 | fi |
| 133 | |
| 134 | default |
| 135 | } |
| 136 | |
| 137 | src_configure() { |
| 138 | local stagename="RUST_STAGE0_${ARCH}" |
| 139 | local stage0="${!stagename}" |
| 140 | |
| 141 | local targets="" |
| 142 | local tt |
| 143 | for tt in "${RUSTC_TARGET_TRIPLES[@]}" ; do |
| 144 | targets+="\"${tt}\", " |
| 145 | done |
| 146 | |
| 147 | local config=cros-config.toml |
| 148 | cat > "${config}" <<EOF |
| 149 | [build] |
| 150 | target = [${targets}] |
| 151 | cargo = "${WORKDIR}/cargo-${STAGE0_VERSION_CARGO}-x86_64-unknown-linux-gnu/cargo/bin/cargo" |
| 152 | rustc = "${WORKDIR}/${stage0}/rustc/bin/rustc" |
| 153 | docs = false |
| 154 | submodules = false |
| 155 | python = "${EPYTHON}" |
| 156 | vendor = true |
| 157 | extended = true |
| 158 | tools = ["rustfmt", "clippy", "cargofmt"] |
| 159 | sanitizers = true |
| 160 | |
| 161 | [llvm] |
| 162 | ninja = true |
| 163 | |
| 164 | [install] |
| 165 | prefix = "${ED}usr" |
| 166 | libdir = "$(get_libdir)/rust" |
| 167 | mandir = "share/man" |
| 168 | |
| 169 | [rust] |
| 170 | default-linker = "${CBUILD}-clang" |
| 171 | channel = "${SLOT%%/*}" |
| 172 | codegen-units = 0 |
| 173 | |
| 174 | EOF |
| 175 | for tt in "${RUSTC_TARGET_TRIPLES[@]}" ; do |
| 176 | cat >> cros-config.toml <<EOF |
| 177 | [target."${tt}"] |
| 178 | cc = "${tt}-clang" |
| 179 | cxx = "${tt}-clang++" |
| 180 | linker = "${tt}-clang++" |
| 181 | |
| 182 | EOF |
| 183 | done |
| 184 | } |
| 185 | |
| 186 | src_compile() { |
| 187 | ${EPYTHON} x.py build --config cros-config.toml || die |
| 188 | } |
| 189 | |
| 190 | src_install() { |
| 191 | local obj="build/x86_64-unknown-linux-gnu/stage2" |
| 192 | local tools="${obj}-tools/x86_64-unknown-linux-gnu/release/" |
| 193 | dobin "${obj}/bin/rustc" "${obj}/bin/rustdoc" |
| 194 | dobin "${tools}/rustfmt" "${tools}/cargo-fmt" |
| 195 | dobin "${tools}/clippy-driver" "${tools}/cargo-clippy" |
| 196 | dobin src/etc/rust-gdb src/etc/rust-lldb |
| 197 | insinto "/usr/$(get_libdir)" |
| 198 | doins -r "${obj}/lib/"* |
| 199 | doins -r "${obj}/lib64/"* |
| 200 | } |