summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rust/rust_1.87.0.bb
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/rust/rust_1.87.0.bb')
-rw-r--r--meta/recipes-devtools/rust/rust_1.87.0.bb396
1 files changed, 396 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rust/rust_1.87.0.bb b/meta/recipes-devtools/rust/rust_1.87.0.bb
new file mode 100644
index 0000000000..5d804c7398
--- /dev/null
+++ b/meta/recipes-devtools/rust/rust_1.87.0.bb
@@ -0,0 +1,396 @@
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"
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"
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"
241FILES:${PN}-rustdoc = "${bindir}/rustdoc"
242FILES:${PN}-tools-clippy = "${bindir}/cargo-clippy ${bindir}/clippy-driver"
243FILES:${PN}-tools-rustfmt = "${bindir}/rustfmt"
244
245RDEPENDS:${PN}-rustdoc = "${PN}"
246RDEPENDS:${PN}-tools-clippy = "${PN}"
247RDEPENDS:${PN}-tools-rustfmt = "${PN}"
248
249SUMMARY:${PN}-tools-clippy = "A collection of lints to catch common mistakes and improve your Rust code"
250SUMMARY:${PN}-tools-rustfmt = "A tool for formatting Rust code according to style guidelines"
251
252do_install () {
253 rust_do_install
254}
255
256rust_do_install() {
257 rust_runx install
258}
259
260rust_do_install:class-nativesdk() {
261 export PSEUDO_UNLOAD=1
262 rust_runx install
263 rust_runx install clippy
264 rust_runx install rustfmt
265 unset PSEUDO_UNLOAD
266
267 install -d ${D}${bindir}
268 for i in cargo-clippy clippy-driver rustfmt; do
269 cp build/${RUST_BUILD_SYS}/stage1-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
270 patchelf --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
271 done
272
273 chown root:root ${D}/ -R
274 rm ${D}${libdir}/rustlib/uninstall.sh
275 rm ${D}${libdir}/rustlib/install.log
276 rm ${D}${libdir}/rustlib/manifest*
277 rm ${D}${libdir}/rustlib/${RUST_HOST_SYS}/lib/libstd*.so
278
279 ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
280 mkdir "${ENV_SETUP_DIR}"
281 RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
282 RUST_HOST_TRIPLE=`echo ${RUST_HOST_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
283 RUST_HOST_CC=`echo ${RUST_HOST_SYS} | sed 's/-/_/g'`
284 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)}
285
286 cat <<- EOF > "${RUST_ENV_SETUP_SH}"
287 export CARGO_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/${SDKLOADER}"
288 export CC_$RUST_HOST_CC="${CCACHE}${HOST_PREFIX}gcc"
289 EOF
290}
291
292FILES:${PN} += "${base_prefix}/environment-setup.d"
293
294EXTRA_TOOLS ?= "cargo-clippy clippy-driver rustfmt"
295rust_do_install:class-target() {
296 export PSEUDO_UNLOAD=1
297 rust_runx install
298 rust_runx install clippy
299 rust_runx install rustfmt
300 unset PSEUDO_UNLOAD
301
302 install -d ${D}${bindir}
303 for i in ${EXTRA_TOOLS}; do
304 cp build/${RUST_BUILD_SYS}/stage1-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
305 patchelf --set-rpath "\$ORIGIN/../lib" ${D}${bindir}/$i
306 done
307
308 install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}
309 install -m 0644 ${WORKDIR}/rust-targets/${RUST_HOST_SYS}.json ${D}${libdir}/rustlib/${RUST_HOST_SYS}/target.json
310
311 chown root:root ${D}/ -R
312 rm ${D}${libdir}/rustlib/uninstall.sh
313 rm ${D}${libdir}/rustlib/install.log
314 rm ${D}${libdir}/rustlib/manifest*
315 rm ${D}${libdir}/rustlib/${RUST_HOST_SYS}/lib/libstd*.so
316}
317
318addtask do_update_snapshot after do_patch
319do_update_snapshot[nostamp] = "1"
320
321# Run with `bitbake -c update_snapshot rust` to update `rust-snapshot.inc`
322# with the checksums for the rust snapshot associated with this rustc-src
323# tarball.
324python do_update_snapshot() {
325 import json
326 import re
327 import sys
328
329 from collections import defaultdict
330
331 key_value_pairs = {}
332 with open(os.path.join(d.getVar("S"), "src", "stage0")) as f:
333 for line in f:
334 # Skip empty lines or comments
335 if not line.strip() or line.startswith("#"):
336 continue
337 # Split the line into key and value using '=' as separator
338 match = re.match(r'(\S+)\s*=\s*(\S+)', line.strip())
339 if match:
340 key = match.group(1)
341 value = match.group(2)
342 key_value_pairs[key] = value
343 # Extract the required values from key_value_pairs
344 config_dist_server = key_value_pairs.get('dist_server', '')
345 compiler_date = key_value_pairs.get('compiler_date', '')
346 compiler_version = key_value_pairs.get('compiler_version', '')
347
348 src_uri = defaultdict(list)
349 # Assuming checksums_sha256 is now a key-value pair like: checksum_key = checksum_value
350 for k, v in key_value_pairs.items():
351 # Match the pattern for checksums
352 if "dist" in k and "tar.xz" in k:
353 m = re.search(f"dist/{compiler_date}/(?P<component>.*)-{compiler_version}-(?P<arch>.*)-unknown-linux-gnu\\.tar\\.xz", k)
354 if m:
355 component = m.group('component')
356 arch = m.group('arch')
357 src_uri[arch].append(f"SRC_URI[{component}-snapshot-{arch}.sha256sum] = \"{v}\"")
358 # Create the snapshot string with the extracted values
359 snapshot = """\
360## This is information on the rust-snapshot (binary) used to build our current release.
361## snapshot info is taken from rust/src/stage0
362## Rust is self-hosting and bootstraps itself with a pre-built previous version of itself.
363## The exact (previous) version that has been used is specified in the source tarball.
364## The version is replicated here.
365
366SNAPSHOT_VERSION = "%s"
367
368""" % compiler_version
369 # Add the checksum components to the snapshot
370 for arch, components in src_uri.items():
371 snapshot += "\n".join(components) + "\n\n"
372 # Add the additional snapshot URIs
373 snapshot += """\
374SRC_URI += " \\
375 ${RUST_DIST_SERVER}/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
376 ${RUST_DIST_SERVER}/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
377 ${RUST_DIST_SERVER}/dist/${CARGO_SNAPSHOT}.tar.xz;name=cargo-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
378"
379
380RUST_DIST_SERVER = "%s"
381
382RUST_STD_SNAPSHOT = "rust-std-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
383RUSTC_SNAPSHOT = "rustc-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
384CARGO_SNAPSHOT = "cargo-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
385""" % config_dist_server
386 # Write the updated snapshot information to the rust-snapshot.inc file
387 with open(os.path.join(d.getVar("THISDIR"), "rust-snapshot.inc"), "w") as f:
388 f.write(snapshot)
389}
390
391RUSTLIB_DEP:class-nativesdk = ""
392
393# musl builds include libunwind.a
394INSANE_SKIP:${PN} = "staticdev"
395
396BBCLASSEXTEND = "native nativesdk"