summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rust/rust_1.84.1.bb
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/rust/rust_1.84.1.bb')
-rw-r--r--meta/recipes-devtools/rust/rust_1.84.1.bb382
1 files changed, 382 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rust/rust_1.84.1.bb b/meta/recipes-devtools/rust/rust_1.84.1.bb
new file mode 100644
index 0000000000..ee8c782ce3
--- /dev/null
+++ b/meta/recipes-devtools/rust/rust_1.84.1.bb
@@ -0,0 +1,382 @@
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 config.set("llvm", "download-ci-llvm", e(False))
133 if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
134 config.set("llvm", "use-libcxx", e(True))
135
136 # [rust]
137 config.add_section("rust")
138 config.set("rust", "rpath", e(True))
139 config.set("rust", "remap-debuginfo", e(True))
140 config.set("rust", "download-rustc", e(False))
141 config.set("rust", "llvm-tools", e(False))
142 config.set("rust", "channel", e(d.expand("${RUST_CHANNEL}")))
143
144 # Whether or not to optimize the compiler and standard library
145 config.set("rust", "optimize", e(True))
146
147 # Emits extraneous output from tests to ensure that failures of the test
148 # harness are debuggable just from logfiles
149 config.set("rust", "verbose-tests", e(True))
150
151 # [build]
152 config.add_section("build")
153 config.set("build", "submodules", e(False))
154 config.set("build", "docs", e(False))
155
156 rustc = d.getVar('RUSTC_BOOTSTRAP')
157 config.set("build", "rustc", e(rustc))
158
159 cargo = d.getVar('CARGO_BOOTSTRAP')
160 config.set("build", "cargo", e(cargo))
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 chrpath -r \$ORIGIN/../../../../../`basename ${STAGING_DIR_NATIVE}`${libdir_native} ${RUST_ALTERNATE_EXE_PATH}
211 else
212 chrpath -d ${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"
244RDEPENDS:${PN}-rustdoc = "${PN}"
245RDEPENDS:${PN}-tools-clippy = "${PN}"
246RDEPENDS:${PN}-tools-rustfmt = "${PN}"
247
248SUMMARY:${PN}-tools-clippy = "A collection of lints to catch common mistakes and improve your Rust code"
249SUMMARY:${PN}-tools-rustfmt = "A tool for formatting Rust code according to style guidelines"
250
251do_install () {
252 rust_do_install
253}
254
255rust_do_install() {
256 rust_runx install
257}
258
259rust_do_install:class-nativesdk() {
260 export PSEUDO_UNLOAD=1
261 rust_runx install
262 rust_runx install clippy
263 rust_runx install rustfmt
264 unset PSEUDO_UNLOAD
265
266 install -d ${D}${bindir}
267 for i in cargo-clippy clippy-driver rustfmt; do
268 cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
269 chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
270 done
271
272 chown root:root ${D}/ -R
273 rm ${D}${libdir}/rustlib/uninstall.sh
274 rm ${D}${libdir}/rustlib/install.log
275 rm ${D}${libdir}/rustlib/manifest*
276 rm ${D}${libdir}/rustlib/${RUST_HOST_SYS}/lib/libstd*.so
277
278 ENV_SETUP_DIR=${D}${base_prefix}/environment-setup.d
279 mkdir "${ENV_SETUP_DIR}"
280 RUST_ENV_SETUP_SH="${ENV_SETUP_DIR}/rust.sh"
281 RUST_HOST_TRIPLE=`echo ${RUST_HOST_SYS} | tr '[:lower:]' '[:upper:]' | sed 's/-/_/g'`
282 RUST_HOST_CC=`echo ${RUST_HOST_SYS} | sed 's/-/_/g'`
283 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)}
284
285 cat <<- EOF > "${RUST_ENV_SETUP_SH}"
286 export CARGO_TARGET_${RUST_HOST_TRIPLE}_RUNNER="\$OECORE_NATIVE_SYSROOT/lib/${SDKLOADER}"
287 export CC_$RUST_HOST_CC="${CCACHE}${HOST_PREFIX}gcc"
288 EOF
289}
290
291FILES:${PN} += "${base_prefix}/environment-setup.d"
292
293EXTRA_TOOLS ?= "cargo-clippy clippy-driver rustfmt"
294rust_do_install:class-target() {
295 export PSEUDO_UNLOAD=1
296 rust_runx install
297 rust_runx install clippy
298 rust_runx install rustfmt
299 unset PSEUDO_UNLOAD
300
301 install -d ${D}${bindir}
302 for i in ${EXTRA_TOOLS}; do
303 cp build/${RUST_BUILD_SYS}/stage2-tools/${RUST_HOST_SYS}/release/$i ${D}${bindir}
304 chrpath -r "\$ORIGIN/../lib" ${D}${bindir}/$i
305 done
306
307 install -d ${D}${libdir}/rustlib/${RUST_HOST_SYS}
308 install -m 0644 ${WORKDIR}/rust-targets/${RUST_HOST_SYS}.json ${D}${libdir}/rustlib/${RUST_HOST_SYS}/target.json
309
310 chown root:root ${D}/ -R
311 rm ${D}${libdir}/rustlib/uninstall.sh
312 rm ${D}${libdir}/rustlib/install.log
313 rm ${D}${libdir}/rustlib/manifest*
314 rm ${D}${libdir}/rustlib/${RUST_HOST_SYS}/lib/libstd*.so
315}
316
317addtask do_update_snapshot after do_patch
318do_update_snapshot[nostamp] = "1"
319
320# Run with `bitbake -c update_snapshot rust` to update `rust-snapshot.inc`
321# with the checksums for the rust snapshot associated with this rustc-src
322# tarball.
323python do_update_snapshot() {
324 import json
325 import re
326 import sys
327
328 from collections import defaultdict
329
330 with open(os.path.join(d.getVar("S"), "src", "stage0.json")) as f:
331 j = json.load(f)
332
333 config_dist_server = j['config']['dist_server']
334 compiler_date = j['compiler']['date']
335 compiler_version = j['compiler']['version']
336
337 src_uri = defaultdict(list)
338 for k, v in j['checksums_sha256'].items():
339 m = re.search(f"dist/{compiler_date}/(?P<component>.*)-{compiler_version}-(?P<arch>.*)-unknown-linux-gnu\\.tar\\.xz", k)
340 if m:
341 component = m.group('component')
342 arch = m.group('arch')
343 src_uri[arch].append(f"SRC_URI[{component}-snapshot-{arch}.sha256sum] = \"{v}\"")
344
345 snapshot = """\
346## This is information on the rust-snapshot (binary) used to build our current release.
347## snapshot info is taken from rust/src/stage0.json
348## Rust is self-hosting and bootstraps itself with a pre-built previous version of itself.
349## The exact (previous) version that has been used is specified in the source tarball.
350## The version is replicated here.
351
352SNAPSHOT_VERSION = "%s"
353
354""" % compiler_version
355
356 for arch, components in src_uri.items():
357 snapshot += "\n".join(components) + "\n\n"
358
359 snapshot += """\
360SRC_URI += " \\
361 ${RUST_DIST_SERVER}/dist/${RUST_STD_SNAPSHOT}.tar.xz;name=rust-std-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
362 ${RUST_DIST_SERVER}/dist/${RUSTC_SNAPSHOT}.tar.xz;name=rustc-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
363 ${RUST_DIST_SERVER}/dist/${CARGO_SNAPSHOT}.tar.xz;name=cargo-snapshot-${RUST_BUILD_ARCH};subdir=rust-snapshot-components \\
364"
365
366RUST_DIST_SERVER = "%s"
367
368RUST_STD_SNAPSHOT = "rust-std-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
369RUSTC_SNAPSHOT = "rustc-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
370CARGO_SNAPSHOT = "cargo-${SNAPSHOT_VERSION}-${RUST_BUILD_ARCH}-unknown-linux-gnu"
371""" % config_dist_server
372
373 with open(os.path.join(d.getVar("THISDIR"), "rust-snapshot.inc"), "w") as f:
374 f.write(snapshot)
375}
376
377RUSTLIB_DEP:class-nativesdk = ""
378
379# musl builds include libunwind.a
380INSANE_SKIP:${PN} = "staticdev"
381
382BBCLASSEXTEND = "native nativesdk"