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}"))) |
| 84 | if "musl" in host_section: |
| 85 | 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] | 86 | |
| 87 | # If we don't do this rust-native will compile it's own llvm for BUILD. |
| 88 | # [target.${BUILD_ARCH}-unknown-linux-gnu] |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 89 | build_section = "target.{}".format(d.getVar('RUST_BUILD_SYS', True)) |
| 90 | if build_section != host_section: |
| 91 | config.add_section(build_section) |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 92 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 93 | config.set(build_section, "llvm-config", e(llvm_config_build)) |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 94 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 95 | config.set(build_section, "cxx", e(d.expand("${RUST_BUILD_CXX}"))) |
| 96 | config.set(build_section, "cc", e(d.expand("${RUST_BUILD_CC}"))) |
| 97 | |
| 98 | target_section = "target.{}".format(d.getVar('RUST_TARGET_SYS', True)) |
| 99 | if target_section != host_section and target_section != build_section: |
| 100 | config.add_section(target_section) |
| 101 | |
| 102 | config.set(target_section, "llvm-config", e(llvm_config_target)) |
| 103 | |
| 104 | config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}"))) |
| 105 | config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}"))) |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 106 | |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 107 | # [llvm] |
| 108 | config.add_section("llvm") |
| 109 | config.set("llvm", "static-libstdcpp", e(False)) |
| 110 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 111 | # [rust] |
| 112 | config.add_section("rust") |
| 113 | config.set("rust", "rpath", e(True)) |
| 114 | config.set("rust", "channel", e("stable")) |
| 115 | |
| 116 | # Whether or not to optimize the compiler and standard library |
| 117 | config.set("rust", "optimize", e(True)) |
| 118 | |
| 119 | # [build] |
| 120 | config.add_section("build") |
| 121 | config.set("build", "submodules", e(False)) |
| 122 | config.set("build", "docs", e(False)) |
| 123 | |
| 124 | rustc = d.expand("${WORKDIR}/rust-snapshot/bin/rustc") |
| 125 | config.set("build", "rustc", e(rustc)) |
| 126 | |
| 127 | # Support for the profiler runtime to generate e.g. coverage report, |
| 128 | # PGO etc. |
| 129 | config.set("build", "profiler", e(True)) |
| 130 | |
| 131 | cargo = d.expand("${WORKDIR}/rust-snapshot/bin/cargo") |
| 132 | config.set("build", "cargo", e(cargo)) |
| 133 | |
| 134 | config.set("build", "vendor", e(True)) |
| 135 | |
| 136 | if not "targets" in locals(): |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 137 | targets = [d.getVar("RUST_TARGET_SYS", True)] |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 138 | config.set("build", "target", e(targets)) |
| 139 | |
| 140 | if not "hosts" in locals(): |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 141 | hosts = [d.getVar("RUST_HOST_SYS", True)] |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 142 | config.set("build", "host", e(hosts)) |
| 143 | |
| 144 | # We can't use BUILD_SYS since that is something the rust snapshot knows |
| 145 | # nothing about when trying to build some stage0 tools (like fabricate) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 146 | config.set("build", "build", e(d.getVar("RUST_BUILD_SYS", True))) |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 147 | |
| 148 | # [install] |
| 149 | config.add_section("install") |
| 150 | # ./x.py install doesn't have any notion of "destdir" |
| 151 | # but we can prepend ${D} to all the directories instead |
| 152 | config.set("install", "prefix", e(d.getVar("D", True) + d.getVar("prefix", True))) |
| 153 | config.set("install", "bindir", e(d.getVar("D", True) + d.getVar("bindir", True))) |
| 154 | config.set("install", "libdir", e(d.getVar("D", True) + d.getVar("libdir", True))) |
| 155 | config.set("install", "datadir", e(d.getVar("D", True) + d.getVar("datadir", True))) |
| 156 | config.set("install", "mandir", e(d.getVar("D", True) + d.getVar("mandir", True))) |
| 157 | |
| 158 | with open("config.toml", "w") as f: |
| 159 | f.write('changelog-seen = 2\n\n') |
| 160 | config.write(f) |
| 161 | |
| 162 | # set up ${WORKDIR}/cargo_home |
| 163 | bb.build.exec_func("setup_cargo_environment", d) |
| 164 | } |
| 165 | |
| 166 | |
| 167 | rust_runx () { |
| 168 | echo "COMPILE ${PN}" "$@" |
| 169 | |
| 170 | # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a |
| 171 | # wide range of targets (not just TARGET). Yocto's settings for them will |
| 172 | # be inappropriate, avoid using. |
| 173 | unset CFLAGS |
| 174 | unset LDFLAGS |
| 175 | unset CXXFLAGS |
| 176 | unset CPPFLAGS |
| 177 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 178 | export RUSTFLAGS="${RUST_DEBUG_REMAP}" |
| 179 | |
| 180 | # Copy the natively built llvm-config into the target so we can run it. Horrible, |
| 181 | # but works! |
| 182 | if [ ${RUST_ALTERNATE_EXE_PATH_NATIVE} != ${RUST_ALTERNATE_EXE_PATH} ]; then |
| 183 | mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}` |
| 184 | cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH} |
| 185 | chrpath -d ${RUST_ALTERNATE_EXE_PATH} |
| 186 | fi |
| 187 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 188 | oe_cargo_fix_env |
| 189 | |
| 190 | python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose |
| 191 | } |
| 192 | rust_runx[vardepsexclude] += "PARALLEL_MAKE" |
| 193 | |
| 194 | do_compile () { |
| 195 | rust_runx build |
| 196 | } |
| 197 | |
| 198 | rust_do_install () { |
| 199 | mkdir -p ${D}${bindir} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 200 | cp build/${RUST_HOST_SYS}/stage2/bin/* ${D}${bindir} |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 201 | |
| 202 | mkdir -p ${D}${libdir}/rustlib |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 203 | cp -pRd build/${RUST_HOST_SYS}/stage2/lib/* ${D}${libdir} |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 204 | # Remove absolute symlink so bitbake doesn't complain |
| 205 | rm -f ${D}${libdir}/rustlib/src/rust |
| 206 | } |
| 207 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 208 | do_install () { |
| 209 | rust_do_install |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 210 | } |