Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 1 | SUMMARY = "Rust compiler and runtime libaries" |
| 2 | HOMEPAGE = "http://www.rust-lang.org" |
| 3 | SECTION = "devel" |
| 4 | LICENSE = "MIT | Apache-2.0" |
| 5 | LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=93a95682d51b4cb0a633a97046940ef0" |
| 6 | |
| 7 | inherit rust |
| 8 | inherit cargo_common |
| 9 | |
| 10 | DEPENDS += "file-native python3-native" |
| 11 | DEPENDS:append:class-native = " rust-llvm-native" |
| 12 | |
| 13 | S = "${RUSTSRC}" |
| 14 | |
| 15 | # We generate local targets, and need to be able to locate them |
| 16 | export RUST_TARGET_PATH="${WORKDIR}/targets/" |
| 17 | |
| 18 | export FORCE_CRATE_HASH="${BB_TASKHASH}" |
| 19 | |
| 20 | RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config" |
| 21 | export YOCTO_ALTERNATE_EXE_PATH = "${RUST_ALTERNATE_EXE_PATH}" |
| 22 | export YOCTO_ALTERNATE_MULTILIB_NAME = "/${BASELIB}" |
| 23 | |
| 24 | # We don't want to use bitbakes vendoring because the rust sources do their |
| 25 | # own vendoring. |
| 26 | CARGO_DISABLE_BITBAKE_VENDORING = "1" |
| 27 | |
| 28 | # We can't use RUST_BUILD_SYS here because that may be "musl" if |
| 29 | # TCLIBC="musl". Snapshots are always -unknown-linux-gnu |
| 30 | SNAPSHOT_BUILD_SYS = "${BUILD_ARCH}-unknown-linux-gnu" |
| 31 | setup_cargo_environment () { |
| 32 | # The first step is to build bootstrap and some early stage tools, |
| 33 | # these are build for the same target as the snapshot, e.g. |
| 34 | # x86_64-unknown-linux-gnu. |
| 35 | # Later stages are build for the native target (i.e. target.x86_64-linux) |
| 36 | cargo_common_do_configure |
| 37 | |
| 38 | printf '[target.%s]\n' "${SNAPSHOT_BUILD_SYS}" >> ${CARGO_HOME}/config |
| 39 | printf "linker = '%s'\n" "${RUST_BUILD_CCLD}" >> ${CARGO_HOME}/config |
| 40 | } |
| 41 | |
| 42 | include rust-common.inc |
| 43 | |
| 44 | do_rust_setup_snapshot () { |
| 45 | for installer in "${WORKDIR}/rust-snapshot-components/"*"/install.sh"; do |
| 46 | "${installer}" --prefix="${WORKDIR}/rust-snapshot" --disable-ldconfig |
| 47 | done |
| 48 | |
| 49 | # Some versions of rust (e.g. 1.18.0) tries to find cargo in stage0/bin/cargo |
| 50 | # and fail without it there. |
| 51 | mkdir -p ${RUSTSRC}/build/${BUILD_SYS} |
| 52 | ln -sf ${WORKDIR}/rust-snapshot/ ${RUSTSRC}/build/${BUILD_SYS}/stage0 |
| 53 | |
| 54 | # Need to use uninative's loader if enabled/present since the library paths |
| 55 | # are used internally by rust and result in symbol mismatches if we don't |
| 56 | if [ ! -z "${UNINATIVE_LOADER}" -a -e "${UNINATIVE_LOADER}" ]; then |
| 57 | for bin in cargo rustc rustdoc; do |
| 58 | patchelf-uninative ${WORKDIR}/rust-snapshot/bin/$bin --set-interpreter ${UNINATIVE_LOADER} |
| 59 | done |
| 60 | fi |
| 61 | } |
| 62 | addtask rust_setup_snapshot after do_unpack before do_configure |
| 63 | do_rust_setup_snapshot[dirs] += "${WORKDIR}/rust-snapshot" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 64 | do_rust_setup_snapshot[vardepsexclude] += "UNINATIVE_LOADER" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 65 | |
| 66 | python do_configure() { |
| 67 | import json |
| 68 | try: |
| 69 | import configparser |
| 70 | except ImportError: |
| 71 | import ConfigParser as configparser |
| 72 | |
| 73 | # toml is rather similar to standard ini like format except it likes values |
| 74 | # that look more JSON like. So for our purposes simply escaping all values |
| 75 | # as JSON seem to work fine. |
| 76 | |
| 77 | e = lambda s: json.dumps(s) |
| 78 | |
| 79 | config = configparser.RawConfigParser() |
| 80 | |
| 81 | # [target.ARCH-poky-linux] |
| 82 | target_section = "target.{}".format(d.getVar('TARGET_SYS', True)) |
| 83 | config.add_section(target_section) |
| 84 | |
| 85 | llvm_config = d.expand("${YOCTO_ALTERNATE_EXE_PATH}") |
| 86 | config.set(target_section, "llvm-config", e(llvm_config)) |
| 87 | |
| 88 | config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}"))) |
| 89 | config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}"))) |
| 90 | |
| 91 | # If we don't do this rust-native will compile it's own llvm for BUILD. |
| 92 | # [target.${BUILD_ARCH}-unknown-linux-gnu] |
| 93 | target_section = "target.{}".format(d.getVar('SNAPSHOT_BUILD_SYS', True)) |
| 94 | config.add_section(target_section) |
| 95 | |
| 96 | config.set(target_section, "llvm-config", e(llvm_config)) |
| 97 | |
| 98 | config.set(target_section, "cxx", e(d.expand("${RUST_BUILD_CXX}"))) |
| 99 | config.set(target_section, "cc", e(d.expand("${RUST_BUILD_CC}"))) |
| 100 | |
| 101 | # [rust] |
| 102 | config.add_section("rust") |
| 103 | config.set("rust", "rpath", e(True)) |
| 104 | config.set("rust", "channel", e("stable")) |
| 105 | |
| 106 | # Whether or not to optimize the compiler and standard library |
| 107 | config.set("rust", "optimize", e(True)) |
| 108 | |
| 109 | # [build] |
| 110 | config.add_section("build") |
| 111 | config.set("build", "submodules", e(False)) |
| 112 | config.set("build", "docs", e(False)) |
| 113 | |
| 114 | rustc = d.expand("${WORKDIR}/rust-snapshot/bin/rustc") |
| 115 | config.set("build", "rustc", e(rustc)) |
| 116 | |
| 117 | # Support for the profiler runtime to generate e.g. coverage report, |
| 118 | # PGO etc. |
| 119 | config.set("build", "profiler", e(True)) |
| 120 | |
| 121 | cargo = d.expand("${WORKDIR}/rust-snapshot/bin/cargo") |
| 122 | config.set("build", "cargo", e(cargo)) |
| 123 | |
| 124 | config.set("build", "vendor", e(True)) |
| 125 | |
| 126 | if not "targets" in locals(): |
| 127 | targets = [d.getVar("TARGET_SYS", True)] |
| 128 | config.set("build", "target", e(targets)) |
| 129 | |
| 130 | if not "hosts" in locals(): |
| 131 | hosts = [d.getVar("HOST_SYS", True)] |
| 132 | config.set("build", "host", e(hosts)) |
| 133 | |
| 134 | # We can't use BUILD_SYS since that is something the rust snapshot knows |
| 135 | # nothing about when trying to build some stage0 tools (like fabricate) |
| 136 | config.set("build", "build", e(d.getVar("SNAPSHOT_BUILD_SYS", True))) |
| 137 | |
| 138 | # [install] |
| 139 | config.add_section("install") |
| 140 | # ./x.py install doesn't have any notion of "destdir" |
| 141 | # but we can prepend ${D} to all the directories instead |
| 142 | config.set("install", "prefix", e(d.getVar("D", True) + d.getVar("prefix", True))) |
| 143 | config.set("install", "bindir", e(d.getVar("D", True) + d.getVar("bindir", True))) |
| 144 | config.set("install", "libdir", e(d.getVar("D", True) + d.getVar("libdir", True))) |
| 145 | config.set("install", "datadir", e(d.getVar("D", True) + d.getVar("datadir", True))) |
| 146 | config.set("install", "mandir", e(d.getVar("D", True) + d.getVar("mandir", True))) |
| 147 | |
| 148 | with open("config.toml", "w") as f: |
| 149 | f.write('changelog-seen = 2\n\n') |
| 150 | config.write(f) |
| 151 | |
| 152 | # set up ${WORKDIR}/cargo_home |
| 153 | bb.build.exec_func("setup_cargo_environment", d) |
| 154 | } |
| 155 | |
| 156 | |
| 157 | rust_runx () { |
| 158 | echo "COMPILE ${PN}" "$@" |
| 159 | |
| 160 | # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a |
| 161 | # wide range of targets (not just TARGET). Yocto's settings for them will |
| 162 | # be inappropriate, avoid using. |
| 163 | unset CFLAGS |
| 164 | unset LDFLAGS |
| 165 | unset CXXFLAGS |
| 166 | unset CPPFLAGS |
| 167 | |
| 168 | oe_cargo_fix_env |
| 169 | |
| 170 | python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose |
| 171 | } |
| 172 | rust_runx[vardepsexclude] += "PARALLEL_MAKE" |
| 173 | |
| 174 | do_compile () { |
| 175 | rust_runx build |
| 176 | } |
| 177 | |
| 178 | rust_do_install () { |
| 179 | mkdir -p ${D}${bindir} |
| 180 | cp build/${HOST_SYS}/stage2/bin/* ${D}${bindir} |
| 181 | |
| 182 | mkdir -p ${D}${libdir}/rustlib |
| 183 | cp -pRd build/${HOST_SYS}/stage2/lib/* ${D}${libdir} |
| 184 | # Remove absolute symlink so bitbake doesn't complain |
| 185 | rm -f ${D}${libdir}/rustlib/src/rust |
| 186 | } |
| 187 | |
| 188 | rust_install_targets() { |
| 189 | # Install our custom target.json files |
| 190 | local td="${D}${libdir}/rustlib/" |
| 191 | install -d "$td" |
| 192 | for tgt in "${WORKDIR}/targets/"* ; do |
| 193 | install -m 0644 "$tgt" "$td" |
| 194 | done |
| 195 | } |
| 196 | |
| 197 | |
| 198 | do_install () { |
| 199 | rust_do_install |
| 200 | rust_install_targets |
| 201 | } |
| 202 | # ex: sts=4 et sw=4 ts=8 |