summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rust/rust_1.80.1.bb
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/rust/rust_1.80.1.bb')
-rw-r--r--meta/recipes-devtools/rust/rust_1.80.1.bb369
1 files changed, 369 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rust/rust_1.80.1.bb b/meta/recipes-devtools/rust/rust_1.80.1.bb
new file mode 100644
index 0000000000..eae1f28bb8
--- /dev/null
+++ b/meta/recipes-devtools/rust/rust_1.80.1.bb
@@ -0,0 +1,369 @@
1SUMMARY = "Rust compiler and runtime libaries"
2HOMEPAGE = "http://www.rust-lang.org"
3SECTION = "devel"
4LICENSE = "(MIT | Apache-2.0) & Unicode-TOU"
5LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=c2cccf560306876da3913d79062a54b9"
6
7inherit rust
8inherit cargo_common
9
10DEPENDS += "file-native python3-native"
11DEPENDS:append:class-native = " rust-llvm-native"
12DEPENDS:append:class-nativesdk = " nativesdk-rust-llvm"
13
14# native rust uses cargo/rustc from binary snapshots to bootstrap
15# but everything else should use our native builds
16DEPENDS:append:class-target = " cargo-native rust-native"
17DEPENDS:append:class-nativesdk = " cargo-native rust-native"
18
19DEPENDS += "rust-llvm (=${PV})"
20
21RDEPENDS:${PN}:append:class-target = " gcc g++ binutils"
22
23# Otherwise we'll depend on what we provide
24INHIBIT_DEFAULT_RUST_DEPS:class-native = "1"
25# We don't need to depend on gcc-native because yocto assumes it exists
26PROVIDES:class-native = "virtual/${TARGET_PREFIX}rust"
27
28S = "${RUSTSRC}"
29
30# Use at your own risk, accepted values are stable, beta and nightly
31RUST_CHANNEL ?= "stable"
32PV .= "${@bb.utils.contains('RUST_CHANNEL', 'stable', '', '-${RUST_CHANNEL}', d)}"
33
34export FORCE_CRATE_HASH="${BB_TASKHASH}"
35
36RUST_ALTERNATE_EXE_PATH ?= "${STAGING_LIBDIR}/llvm-rust/bin/llvm-config"
37RUST_ALTERNATE_EXE_PATH_NATIVE = "${STAGING_LIBDIR_NATIVE}/llvm-rust/bin/llvm-config"
38
39# We don't want to use bitbakes vendoring because the rust sources do their
40# own vendoring.
41CARGO_DISABLE_BITBAKE_VENDORING = "1"
42
43setup_cargo_environment () {
44 # The first step is to build bootstrap and some early stage tools,
45 # these are build for the same target as the snapshot, e.g.
46 # x86_64-unknown-linux-gnu.
47 # Later stages are build for the native target (i.e. target.x86_64-linux)
48 cargo_common_do_configure
49}
50
51inherit rust-target-config
52
53do_rust_setup_snapshot () {
54 for installer in "${UNPACKDIR}/rust-snapshot-components/"*"/install.sh"; do
55 "${installer}" --prefix="${WORKDIR}/rust-snapshot" --disable-ldconfig
56 done
57
58 # Some versions of rust (e.g. 1.18.0) tries to find cargo in stage0/bin/cargo
59 # and fail without it there.
60 mkdir -p ${RUSTSRC}/build/${RUST_BUILD_SYS}
61 ln -sf ${WORKDIR}/rust-snapshot/ ${RUSTSRC}/build/${RUST_BUILD_SYS}/stage0
62
63 # Need to use uninative's loader if enabled/present since the library paths
64 # are used internally by rust and result in symbol mismatches if we don't
65 if [ ! -z "${UNINATIVE_LOADER}" -a -e "${UNINATIVE_LOADER}" ]; then
66 for bin in cargo rustc rustdoc; do
67 patchelf-uninative ${WORKDIR}/rust-snapshot/bin/$bin --set-interpreter ${UNINATIVE_LOADER}
68 done
69 fi
70}
71addtask rust_setup_snapshot after do_unpack before do_configure
72addtask do_test_compile after do_configure do_rust_gen_targets
73do_rust_setup_snapshot[dirs] += "${WORKDIR}/rust-snapshot"
74do_rust_setup_snapshot[vardepsexclude] += "UNINATIVE_LOADER"
75
76RUSTC_BOOTSTRAP = "${STAGING_BINDIR_NATIVE}/rustc"
77CARGO_BOOTSTRAP = "${STAGING_BINDIR_NATIVE}/cargo"
78RUSTC_BOOTSTRAP:class-native = "${WORKDIR}/rust-snapshot/bin/rustc"
79CARGO_BOOTSTRAP:class-native = "${WORKDIR}/rust-snapshot/bin/cargo"
80
81python do_configure() {
82 import json
83 import configparser
84
85 # toml is rather similar to standard ini like format except it likes values
86 # that look more JSON like. So for our purposes simply escaping all values
87 # as JSON seem to work fine.
88
89 e = lambda s: json.dumps(s)
90
91 config = configparser.RawConfigParser()
92
93 # [target.ARCH-poky-linux]
94 host_section = "target.{}".format(d.getVar('RUST_HOST_SYS'))
95 config.add_section(host_section)
96
97 llvm_config_target = d.expand("${RUST_ALTERNATE_EXE_PATH}")
98 llvm_config_build = d.expand("${RUST_ALTERNATE_EXE_PATH_NATIVE}")
99 config.set(host_section, "llvm-config", e(llvm_config_target))
100
101 config.set(host_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
102 config.set(host_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
103 config.set(host_section, "linker", e(d.expand("${RUST_TARGET_CCLD}")))
104 if "musl" in host_section:
105 config.set(host_section, "musl-root", e(d.expand("${STAGING_DIR_HOST}${exec_prefix}")))
106
107 # If we don't do this rust-native will compile it's own llvm for BUILD.
108 # [target.${BUILD_ARCH}-unknown-linux-gnu]
109 build_section = "target.{}".format(d.getVar('RUST_BUILD_SYS'))
110 if build_section != host_section:
111 config.add_section(build_section)
112
113 config.set(build_section, "llvm-config", e(llvm_config_build))
114
115 config.set(build_section, "cxx", e(d.expand("${RUST_BUILD_CXX}")))
116 config.set(build_section, "cc", e(d.expand("${RUST_BUILD_CC}")))
117 config.set(build_section, "linker", e(d.expand("${RUST_BUILD_CCLD}")))
118
119 target_section = "target.{}".format(d.getVar('RUST_TARGET_SYS'))
120 if target_section != host_section and target_section != build_section:
121 config.add_section(target_section)
122
123 config.set(target_section, "llvm-config", e(llvm_config_target))
124
125 config.set(target_section, "cxx", e(d.expand("${RUST_TARGET_CXX}")))
126 config.set(target_section, "cc", e(d.expand("${RUST_TARGET_CC}")))
127 config.set(target_section, "linker", e(d.expand("${RUST_TARGET_CCLD}")))
128
129 # [llvm]
130 config.add_section("llvm")
131 config.set("llvm", "static-libstdcpp", e(False))
132 if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
133 config.set("llvm", "use-libcxx", e(True))
134
135 # [rust]
136 config.add_section("rust")
137 config.set("rust", "rpath", e(True))
138 config.set("rust", "remap-debuginfo", e(True))
139 config.set("rust", "lto", "\"off\"")
140 config.set("rust", "channel", e(d.expand("${RUST_CHANNEL}")))
141
142 # Whether or not to optimize the compiler and standard library
143 config.set("rust", "optimize", e(True))
144
145 # Emits extraneous output from tests to ensure that failures of the test
146 # harness are debuggable just from logfiles
147 config.set("rust", "verbose-tests", e(True))
148
149 # [build]
150 config.add_section("build")
151 config.set("build", "submodules", e(False))
152 config.set("build", "docs", e(False))
153
154 rustc = d.getVar('RUSTC_BOOTSTRAP')
155 config.set("build", "rustc", e(rustc))
156
157 cargo = d.getVar('CARGO_BOOTSTRAP')
158 config.set("build", "cargo", e(cargo))
159
160 config.set("build", "vendor", e(True))
161
162 config.set("build", "target", e([d.getVar("RUST_TARGET_SYS")]))
163
164 config.set("build", "host", e([d.getVar("RUST_HOST_SYS")]))
165
166 # We can't use BUILD_SYS since that is something the rust snapshot knows
167 # nothing about when trying to build some stage0 tools (like fabricate)
168 config.set("build", "build", e(d.getVar("RUST_BUILD_SYS")))
169
170 # [install]
171 config.add_section("install")
172 # ./x.py install doesn't have any notion of "destdir"
173 # but we can prepend ${D} to all the directories instead
174 config.set("install", "prefix", e(d.getVar("D") + d.getVar("prefix")))
175 config.set("install", "bindir", e(d.getVar("D") + d.getVar("bindir")))
176 config.set("install", "libdir", e(d.getVar("D") + d.getVar("libdir")))
177 config.set("install", "datadir", e(d.getVar("D") + d.getVar("datadir")))
178 config.set("install", "mandir", e(d.getVar("D") + d.getVar("mandir")))
179 config.set("install", "sysconfdir", e(d.getVar("D") + d.getVar("sysconfdir")))
180
181 with open("config.toml", "w") as f:
182 f.write('change-id = 116881\n\n')
183 config.write(f)
184
185 # set up ${WORKDIR}/cargo_home
186 bb.build.exec_func("setup_cargo_environment", d)
187}
188
189rust_runx () {
190 echo "COMPILE ${PN}" "$@"
191
192 # CFLAGS, LDFLAGS, CXXFLAGS, CPPFLAGS are used by rust's build for a
193 # wide range of targets (not just TARGET). Yocto's settings for them will
194 # be inappropriate, avoid using.
195 unset CFLAGS
196 unset LDFLAGS
197 unset CXXFLAGS
198 unset CPPFLAGS
199
200 export RUSTFLAGS="${RUST_DEBUG_REMAP}"
201
202 # Copy the natively built llvm-config into the target so we can run it. Horrible,
203 # but works!
204 if [ ${RUST_ALTERNATE_EXE_PATH_NATIVE} != ${RUST_ALTERNATE_EXE_PATH} -a ! -f ${RUST_ALTERNATE_EXE_PATH} ]; then
205 mkdir -p `dirname ${RUST_ALTERNATE_EXE_PATH}`
206 cp ${RUST_ALTERNATE_EXE_PATH_NATIVE} ${RUST_ALTERNATE_EXE_PATH}
207 if [ -e ${STAGING_LIBDIR_NATIVE}/libc++.so.1 ]; then
208 chrpath -r \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
209 else
210 chrpath -d ${RUST_ALTERNATE_EXE_PATH}
211 fi
212 fi
213
214 oe_cargo_fix_env
215
216 python3 src/bootstrap/bootstrap.py ${@oe.utils.parallel_make_argument(d, '-j %d')} "$@" --verbose
217}
218rust_runx[vardepsexclude] += "PARALLEL_MAKE"
219
220require rust-source.inc
221require rust-snapshot.inc
222
223INSANE_SKIP:${PN}:class-native = "already-stripped"
224FILES:${PN} += "${libdir}/rustlib"
225FILES:${PN} += "${libdir}/*.so"
226FILES:${PN}-dev = ""
227
228do_compile () {
229}
230
231do_test_compile[dirs] = "${B}"
232do_test_compile () {
233 rust_runx build src/tools/remote-test-server --target "${RUST_TARGET_SYS}"
234}
235
236ALLOW_EMPTY:${PN} = "1"
237
238PACKAGES =+ "${PN}-rustdoc ${PN}-tools-clippy ${PN}-tools-rustfmt"
239FILES:${PN}-rustdoc = "${bindir}/rustdoc"
240FILES:${PN}-tools-clippy = "${bindir}/cargo-clippy ${bindir}/clippy-driver"
241FILES:${PN}-tools-rustfmt = "${bindir}/rustfmt"
242RDEPENDS:${PN}-rustdoc = "${PN}"
243RDEPENDS:${PN}-tools-clippy = "${PN}"
244RDEPENDS:${PN}-tools-rustfmt = "${PN}"
245
246SUMMARY:${PN}-tools-clippy = "A collection of lints to catch common mistakes and improve your Rust code"
247SUMMARY:${PN}-tools-rustfmt = "A tool for formatting Rust code according to style guidelines"
248
249do_install () {
250 rust_do_install
251}
252
253rust_do_install() {
254 rust_runx install
255}
256
257rust_do_install:class-nativesdk() {
258 export PSEUDO_UNLOAD=1
259 rust_runx install
260 rust_runx install clippy
261 rust_runx install rustfmt
262 unset PSEUDO_UNLOAD
263
264 install -d ${D}${bindir}
265 for i in cargo-clippy clippy-driver rustfmt; do
266 cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
267 chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
268 done
269
270 chown root:root ${D}/ -R
271 rm ${D}${libdir}/rustlib/uninstall.sh
272 rm ${D}${libdir}/rustlib/install.log
273 rm ${D}${libdir}/rustlib/manifest*
274}
275
276EXTRA_TOOLS ?= "cargo-clippy clippy-driver rustfmt"
277rust_do_install:class-target() {
278 export PSEUDO_UNLOAD=1
279 rust_runx install
280 rust_runx install clippy
281 rust_runx install rustfmt
282 unset PSEUDO_UNLOAD
283
284 install -d ${D}${bindir}
285 for i in ${EXTRA_TOOLS}; do
286 cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
287 chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
288 done
289
290 install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}
291 install -m 0644 ${WORKDIR}/rust-targets/${RUST_HOST_SYS}.json ${D}${libdir}/rustlib/${RUST_HOST_SYS}/target.json
292
293 chown root:root ${D}/ -R
294 rm ${D}${libdir}/rustlib/uninstall.sh
295 rm ${D}${libdir}/rustlib/install.log
296 rm ${D}${libdir}/rustlib/manifest*
297}
298
299addtask do_update_snapshot after do_patch
300do_update_snapshot[nostamp] = "1"
301
302# Run with `bitbake -c update_snapshot rust` to update `rust-snapshot.inc`
303# with the checksums for the rust snapshot associated with this rustc-src
304# tarball.
305python do_update_snapshot() {
306 import json
307 import re
308 import sys
309
310 from collections import defaultdict
311
312 with open(os.path.join(d.getVar("S"), "src", "stage0.json")) as f:
313 j = json.load(f)
314
315 config_dist_server = j['config']['dist_server']
316 compiler_date = j['compiler']['date']
317 compiler_version = j['compiler']['version']
318
319 src_uri = defaultdict(list)
320 for k, v in j['checksums_sha256'].items():
321 m = re.search(f"dist/{compiler_date}/(?P<component>.*)-{compiler_version}-(?P<arch>.*)-unknown-linux-gnu\\.tar\\.xz", k)
322 if m:
323 component = m.group('component')
324 arch = m.group('arch')
325 src_uri[arch].append(f"SRC_URI[{component}-snapshot-{arch}.sha256sum] = \"{v}\"")
326
327 snapshot = """\
328## This is information on the rust-snapshot (binary) used to build our current release.
329## snapshot info is taken from rust/src/stage0.json
330## Rust is self-hosting and bootstraps itself with a pre-built previous version of itself.
331## The exact (previous) version that has been used is specified in the source tarball.
332## The version is replicated here.
333
334SNAPSHOT_VERSION = "%s"
335
336""" % compiler_version
337
338 for arch, components in src_uri.items():
339 snapshot += "\n".join(components) + "\n\n"
340
341 snapshot += """\
342SRC_URI += " \\
343 ${RUST_DIST_SERVER}/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
344 ${RUST_DIST_SERVER}/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
345 ${RUST_DIST_SERVER}/dist/${CARGO_SNAPSHOT}.tar.xz;name=cargo-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
346"
347
348RUST_DIST_SERVER = "%s"
349
350RUST_STD_SNAPSHOT = "rust-std-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
351RUSTC_SNAPSHOT = "rustc-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
352CARGO_SNAPSHOT = "cargo-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
353""" % config_dist_server
354
355 with open(os.path.join(d.getVar("THISDIR"), "rust-snapshot.inc"), "w") as f:
356 f.write(snapshot)
357}
358
359RUSTLIB_DEP:class-nativesdk = ""
360
361# musl builds include libunwind.a
362INSANE_SKIP:${PN} = "staticdev"
363
364BBCLASSEXTEND = "native nativesdk"
365
366# Since 1.70.0 upgrade this fails to build with gold:
367# http://errors.yoctoproject.org/Errors/Details/708196/
368# ld: error: version script assignment of to symbol __rust_alloc_error_handler_should_panic failed: symbol not defined
369LDFLAGS += "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', '-fuse-ld=bfd', '', d)}"