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