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 |
Andrew Jeffery | 1d89bf8 | 2022-03-01 01:09:47 +1030 | [diff] [blame] | 30 | SNAPSHOT_BUILD_SYS = "${RUST_BUILD_ARCH}-unknown-linux-gnu" |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 101 | # [llvm] |
| 102 | config.add_section("llvm") |
| 103 | config.set("llvm", "static-libstdcpp", e(False)) |
| 104 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 105 | # [rust] |
| 106 | config.add_section("rust") |
| 107 | config.set("rust", "rpath", e(True)) |
| 108 | config.set("rust", "channel", e("stable")) |
| 109 | |
| 110 | # Whether or not to optimize the compiler and standard library |
| 111 | config.set("rust", "optimize", e(True)) |
| 112 | |
| 113 | # [build] |
| 114 | config.add_section("build") |
| 115 | config.set("build", "submodules", e(False)) |
| 116 | config.set("build", "docs", e(False)) |
| 117 | |
| 118 | rustc = d.expand("${WORKDIR}/rust-snapshot/bin/rustc") |
| 119 | config.set("build", "rustc", e(rustc)) |
| 120 | |
| 121 | # Support for the profiler runtime to generate e.g. coverage report, |
| 122 | # PGO etc. |
| 123 | config.set("build", "profiler", e(True)) |
| 124 | |
| 125 | cargo = d.expand("${WORKDIR}/rust-snapshot/bin/cargo") |
| 126 | config.set("build", "cargo", e(cargo)) |
| 127 | |
| 128 | config.set("build", "vendor", e(True)) |
| 129 | |
| 130 | if not "targets" in locals(): |
| 131 | targets = [d.getVar("TARGET_SYS", True)] |
| 132 | config.set("build", "target", e(targets)) |
| 133 | |
| 134 | if not "hosts" in locals(): |
| 135 | hosts = [d.getVar("HOST_SYS", True)] |
| 136 | config.set("build", "host", e(hosts)) |
| 137 | |
| 138 | # We can't use BUILD_SYS since that is something the rust snapshot knows |
| 139 | # nothing about when trying to build some stage0 tools (like fabricate) |
| 140 | config.set("build", "build", e(d.getVar("SNAPSHOT_BUILD_SYS", True))) |
| 141 | |
| 142 | # [install] |
| 143 | config.add_section("install") |
| 144 | # ./x.py install doesn't have any notion of "destdir" |
| 145 | # but we can prepend ${D} to all the directories instead |
| 146 | config.set("install", "prefix", e(d.getVar("D", True) + d.getVar("prefix", True))) |
| 147 | config.set("install", "bindir", e(d.getVar("D", True) + d.getVar("bindir", True))) |
| 148 | config.set("install", "libdir", e(d.getVar("D", True) + d.getVar("libdir", True))) |
| 149 | config.set("install", "datadir", e(d.getVar("D", True) + d.getVar("datadir", True))) |
| 150 | config.set("install", "mandir", e(d.getVar("D", True) + d.getVar("mandir", True))) |
| 151 | |
| 152 | with open("config.toml", "w") as f: |
| 153 | f.write('changelog-seen = 2\n\n') |
| 154 | config.write(f) |
| 155 | |
| 156 | # set up ${WORKDIR}/cargo_home |
| 157 | bb.build.exec_func("setup_cargo_environment", d) |
| 158 | } |
| 159 | |
| 160 | |
| 161 | rust_runx () { |
| 162 | echo "COMPILE ${PN}" "$@" |
| 163 | |
| 164 | # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a |
| 165 | # wide range of targets (not just TARGET). Yocto's settings for them will |
| 166 | # be inappropriate, avoid using. |
| 167 | unset CFLAGS |
| 168 | unset LDFLAGS |
| 169 | unset CXXFLAGS |
| 170 | unset CPPFLAGS |
| 171 | |
| 172 | oe_cargo_fix_env |
| 173 | |
| 174 | python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose |
| 175 | } |
| 176 | rust_runx[vardepsexclude] += "PARALLEL_MAKE" |
| 177 | |
| 178 | do_compile () { |
| 179 | rust_runx build |
| 180 | } |
| 181 | |
| 182 | rust_do_install () { |
| 183 | mkdir -p ${D}${bindir} |
| 184 | cp build/${HOST_SYS}/stage2/bin/* ${D}${bindir} |
| 185 | |
| 186 | mkdir -p ${D}${libdir}/rustlib |
| 187 | cp -pRd build/${HOST_SYS}/stage2/lib/* ${D}${libdir} |
| 188 | # Remove absolute symlink so bitbake doesn't complain |
| 189 | rm -f ${D}${libdir}/rustlib/src/rust |
| 190 | } |
| 191 | |
| 192 | rust_install_targets() { |
| 193 | # Install our custom target.json files |
| 194 | local td="${D}${libdir}/rustlib/" |
| 195 | install -d "$td" |
| 196 | for tgt in "${WORKDIR}/targets/"* ; do |
| 197 | install -m 0644 "$tgt" "$td" |
| 198 | done |
| 199 | } |
| 200 | |
| 201 | |
| 202 | do_install () { |
| 203 | rust_do_install |
| 204 | rust_install_targets |
| 205 | } |
| 206 | # ex: sts=4 et sw=4 ts=8 |