blob: 618e6cc360b1ae74306aef7513372bb9c7fe815a [file] [log] [blame]
Daniel Verkampd6c44282019-03-21 10:38:30 -07001# Copyright 1999-2018 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
3
Bob Haarman5c2443f2020-10-20 19:47:27 +00004EAPI=7
Daniel Verkampd6c44282019-03-21 10:38:30 -07005
George Burgess IVf3647162021-08-01 09:36:04 +00006# This is the list of target triples as they appear in the cros_sdk. If this
7# list gets changed, ensure that each of these values has a corresponding
8# compiler/rustc_target/src/spec file created below and a line referring to it
9# in 0001-add-cros-targets.patch.
Bob Haarmanb5128bf2022-04-11 11:27:38 -070010# shellcheck disable=SC2034 # Used by cros-rustc.eclass
Daniel Verkampd6c44282019-03-21 10:38:30 -070011RUSTC_TARGET_TRIPLES=(
Daniel Verkampd6c44282019-03-21 10:38:30 -070012 x86_64-cros-linux-gnu
13 armv7a-cros-linux-gnueabihf
14 aarch64-cros-linux-gnu
15)
16
George Burgess IV2961b6f2022-03-30 00:08:04 -070017# In this context BARE means the OS part of the triple is none and gcc is used
18# for C/C++ and linking.
Bob Haarmanb5128bf2022-04-11 11:27:38 -070019# shellcheck disable=SC2034 # Used by cros-rustc.eclass
Zach Reizner68bdbad2019-09-27 16:54:23 -070020RUSTC_BARE_TARGET_TRIPLES=(
21 thumbv6m-none-eabi # Cortex-M0, M0+, M1
22 thumbv7m-none-eabi # Cortex-M3
23 thumbv7em-none-eabihf # Cortex-M4F, M7F, FPU, hardfloat
Nicholas Bishopa52c3572022-08-03 13:41:29 -040024
25 # These UEFI targets are used by and supported for ChromeOS flex;
26 # contact chromeos-flex-eng@google.com with any questions. Please
27 # add chromeos-toolchain@google.com if you would like to use any of
28 # these triples for your project.
29 i686-unknown-uefi
30 x86_64-unknown-uefi
Zach Reizner68bdbad2019-09-27 16:54:23 -070031)
32
Bob Haarmanb5128bf2022-04-11 11:27:38 -070033# shellcheck disable=SC2034
34PYTHON_COMPAT=( python3_{6..9} )
George Burgess IV2961b6f2022-03-30 00:08:04 -070035
Bob Haarmanb5128bf2022-04-11 11:27:38 -070036inherit cros-rustc
George Burgess IV2961b6f2022-03-30 00:08:04 -070037
38# Use PVR to require simultaneous uprevs of both rust-host and rust, since
39# they're logically talking about the same sources.
Michael Benfielde2e2bed2022-08-13 17:49:04 +000040BDEPEND="=dev-lang/rust-host-${PVR} sys-devel/llvm"
Bob Haarmanb5128bf2022-04-11 11:27:38 -070041RDEPEND="=dev-lang/rust-host-${PVR}"
George Burgess IV2961b6f2022-03-30 00:08:04 -070042KEYWORDS="*"
43
44# NOTE: since CROS_RUSTC_BUILD_DIR is a local cache, the cases below can't
45# always presume that it exists.
46
47src_unpack() {
George Burgess IV5ffe7482022-06-22 17:24:31 -070048 if [[ -n "${CROS_RUSTC_BUILD_RAW_SOURCES}" ]]; then
49 if ! cros-rustc_has_existing_checkout; then
50 eerror "No existing checkout detected; build rust-host first."
51 die
52 fi
53 # Unpacking consists only of ensuring symlink validity in this
54 # case.
55 cros-rustc_src_unpack
56 elif cros-rustc_has_existing_checkout; then
George Burgess IV2961b6f2022-03-30 00:08:04 -070057 einfo "Skipping unpack; checkout already exists"
George Burgess IVddd0dc12022-09-24 12:38:13 -070058 cros-rustc_setup_portage_dirs
George Burgess IV2961b6f2022-03-30 00:08:04 -070059 else
60 ewarn "No existing cros-rustc checkout found. Did you" \
61 "remember to emerge dev-lang/rust-host?"
62 cros-rustc_src_unpack
Daniel Verkampd6c44282019-03-21 10:38:30 -070063 fi
64}
65
66src_prepare() {
George Burgess IV2961b6f2022-03-30 00:08:04 -070067 if cros-rustc_has_existing_checkout; then
68 einfo "Skipping src_prepare; checkout already exists"
69 # `src_prepare` requires this to be called before exiting. The
70 # actual use of user patches with this ebuild is not supported.
71 eapply_user
72 else
73 cros-rustc_src_prepare
Daniel Verkampd6c44282019-03-21 10:38:30 -070074 fi
Daniel Verkampd6c44282019-03-21 10:38:30 -070075}
76
77src_compile() {
George Burgess IV2961b6f2022-03-30 00:08:04 -070078 local keep_stages=()
79 if cros-rustc_has_existing_stage1_build; then
80 einfo "Stage1 build exists; instructing x.py to use it"
81 keep_stages=("--keep-stage=0" "--keep-stage=1")
82 fi
Michael Benfield5fab1f22022-11-14 05:30:11 +000083 cros-rustc_src_compile "${keep_stages[@]}" library
Daniel Verkampd6c44282019-03-21 10:38:30 -070084}
85
86src_install() {
Bob Haarmanb5128bf2022-04-11 11:27:38 -070087 # shellcheck disable=SC2154 # Defined in cros-rustc.eclass
George Burgess IV2961b6f2022-03-30 00:08:04 -070088 local obj="${CROS_RUSTC_BUILD_DIR}/x86_64-unknown-linux-gnu/stage2"
George Burgess IV2961b6f2022-03-30 00:08:04 -070089 for triple in "${RUSTC_TARGET_TRIPLES[@]}" "${RUSTC_BARE_TARGET_TRIPLES[@]}"; do
90 insinto "/usr/$(get_libdir)/rustlib/${triple}"
91 doins -r "${obj}/lib64/rustlib/${triple}/"*
92 done
Daniel Verkampd6c44282019-03-21 10:38:30 -070093}