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