poky/meta/lib/oeqa/selftest/cases/rust.py
Yash Shinde 72d932cc5b rust: Upgrade 1.85.1->1.86.0
Rust stable version updated to 1.86.0.
https://blog.rust-lang.org/2025/04/03/Rust-1.86.0.html

* Add pkgconfig-native and openssl to resolve openssl-sys crate
dependency on pkg-config. As per rust document this is a required dependency.

Fixes:
| error: failed to run custom build command for `openssl-sys v0.9.106`
| Could not find openssl via pkg-config:
|   The pkg-config command could not be found.
|
|   Most likely, you need to install a pkg-config package for your OS.
|   Try `apt install pkg-config`, or `yum install pkg-config`,
|   or `pkg install pkg-config`, or `apk add pkgconfig` depending on your distribution

https://crates.io/crates/openssl-sys/0.9.108/dependencies
https://github.com/rust-lang/rust/blob/master/INSTALL.md#dependencies

* Add Ninja as a dependency for building Rust to prevent bootstrap
  build regression.

Fixes:
| Building LLD for x86_64-unknown-linux-gnu
|
| Couldn't find required command: ninja (or ninja-build)
|
| You should install ninja as described at
| <https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages>,
| or set `ninja = false` in the `[llvm]` section of `config.toml`.
| Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
| to download LLVM rather than building it.

* Add bash to DEPENDS to resolve missing dependency for subtree-sync.sh
Fixes:
ERROR: rust-1.86.0-r0 do_package_qa: QA Issue: /usr/lib/rustlib/src/rust/library/portable-simd/subtree-sync.sh
contained in package rust requires /bin/bash, but no providers found in RDEPENDS:rust? [file-rdeps]

* Add do_install:append() task to remove cargo bin from rust native builds.
This resolves the following conflict:

Fixes:
ERROR: libstd-rs-1.86.0-r0 do_prepare_recipe_sysroot: The file /usr/bin/cargo is
installed by both rust-native and cargo-native, aborting

* Update Unicode-3.0 license checksums.
License-Update: Copyright and license files to distributions are updated.

f9c16997dc
  It adds copyright and license files (including HTML versions) to distributions,
  aligns with license compliance tools like reuse, and ensures all required
  license texts are properly included and formatted.

* Disable building of extended Rust tools to reduce build time and filesystem usage.
  Update config.toml to disable building of extended Rust tools that are not required.
  This helps minimize unnecessary build time and filesystem usage.

* The "remote-test-server" bin is now generated in stage2-tools-bin dir
  rather than stage1. Update the test suite accordingly.

* Fix do_package QA issue by packing missing zsh files and directories:

Fixes:
do_package: QA Issue: rust: Files/directories were installed but not shipped in any package:
/usr/share/zsh
/usr/share/zsh/site-functions
/usr/share/zsh/site-functions/_cargo
Please set FILES such that these items are packaged. Alternatively if they are unneeded,
avoid installing them or delete them within do_install

* From v1.86.0, a "self-contained" LLD is built as part of rust
 bootstrap build. This results in additional build time and
 installations. Disable rust-lld in config.toml to prevent it.

 References: https://github.com/rust-lang/rust/pull/135001
             8744b44e6b

* Drop Zdual-proc-macros-additional-check.patch patch
 since it's merged with v1.86.0
 139d6ba054

* LTO config is applied to rustdoc from v1.86.0.
 Rebase 0001-src-core-build_steps-tool.rs-switch-off-lto-for-rust.patch
 which disables it to avoid suffixes in binaries causing non-reproducibility.
 https://github.com/rust-lang/rust/commit/1fe351b

* Restrict tests using "//@only <target_arch>" to avoid failures on riscv64,
  which is now part of default AB testing. Since riscv64 is Tier 2
  with no automated testing, some tests may fail. This approach ensures tests continue
  running on supported architectures while skipping them on riscv64.
  https://doc.rust-lang.org/rustc/platform-support.html#tier-2-with-host-tools

(From OE-Core rev: c064ef18343a956aea397d36d2e7665d6c8afd7d)

Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2025-06-12 13:12:06 +01:00

136 lines
6.9 KiB
Python

# SPDX-License-Identifier: MIT
import subprocess
import time
from oeqa.core.decorator import OETestTag
from oeqa.core.decorator.data import skipIfArch
from oeqa.core.case import OEPTestResultTestCase
from oeqa.selftest.case import OESelftestTestCase
from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
from oeqa.utils.sshcontrol import SSHControl
def parse_results(filename):
tests = {}
with open(filename, "r") as f:
lines = f.readlines()
for line in lines:
if "..." in line and "test [" in line:
test = line.split("test ")[1].split(" ... ")[0]
if "] " in test:
test = test.split("] ", 1)[1]
result = line.split(" ... ")[1].strip()
if result == "ok":
result = "PASS"
elif result == "failed":
result = "FAIL"
elif "ignored" in result:
result = "SKIPPED"
if test in tests:
if tests[test] != result:
print("Duplicate and mismatching result %s for %s" % (result, test))
else:
print("Duplicate result %s for %s" % (result, test))
else:
tests[test] = result
return tests
# Total time taken for testing is of about 2hr 20min, with PARALLEL_MAKE set to 40 number of jobs.
@OETestTag("toolchain-system")
@OETestTag("toolchain-user")
@OETestTag("runqemu")
class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase):
@skipIfArch(['mips', 'mips64'])
def test_rust(self, *args, **kwargs):
# build remote-test-server before image build
recipe = "rust"
start_time = time.time()
bitbake("{} -c test_compile".format(recipe))
builddir = get_bb_var("RUSTSRC", "rust")
# build core-image-minimal with required packages
default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"]
features = []
features.append('IMAGE_FEATURES += "ssh-server-dropbear"')
features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages)))
self.write_config("\n".join(features))
bitbake("core-image-minimal")
# Exclude the test folders that error out while building
# TODO: Fix the errors and include them for testing
# no-fail-fast: Run all tests regardless of failure.
# bless: First runs rustfmt to format the codebase,
# then runs tidy checks.
exclude_list = [
'src/bootstrap',
'src/doc/rustc',
'src/doc/rustdoc',
'src/doc/unstable-book',
'src/etc/test-float-parse',
'src/librustdoc',
'src/rustdoc-json-types',
'src/tools/jsondoclint',
'src/tools/lint-docs',
'src/tools/replace-version-placeholder',
'src/tools/rust-analyzer',
'src/tools/rustdoc-themes',
'src/tools/rust-installer',
'src/tools/suggest-tests',
'tests/assembly/asm/aarch64-outline-atomics.rs',
'tests/codegen/issues/issue-122805.rs',
'tests/codegen/thread-local.rs',
'tests/mir-opt/',
'tests/run-make',
'tests/run-make-fulldeps',
'tests/rustdoc',
'tests/rustdoc-json',
'tests/rustdoc-js-std',
'tests/ui/abi/stack-probes-lto.rs',
'tests/ui/abi/stack-probes.rs',
'tests/ui/codegen/mismatched-data-layouts.rs',
'tests/codegen/rust-abi-arch-specific-adjustment.rs',
'tests/ui/debuginfo/debuginfo-emit-llvm-ir-and-split-debuginfo.rs',
'tests/ui/feature-gates/version_check.rs',
'tests/ui-fulldeps/',
'tests/ui/process/nofile-limit.rs',
'tidyselftest'
]
exclude_fail_tests = " ".join([" --exclude " + item for item in exclude_list])
# Add exclude_fail_tests with other test arguments
testargs = exclude_fail_tests + " --no-fail-fast --bless"
# wrap the execution with a qemu instance.
# Tests are run with 512 tasks in parallel to execute all tests very quickly
with runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 512") as qemu:
# Copy remote-test-server to image through scp
host_sys = get_bb_var("RUST_BUILD_SYS", "rust")
ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user="root")
ssh.copy_to(builddir + "/build/" + host_sys + "/stage2-tools-bin/remote-test-server","~/")
# Execute remote-test-server on image through background ssh
command = '~/remote-test-server --bind 0.0.0.0:12345 -v'
sshrun=subprocess.Popen(("ssh", '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-f', "root@%s" % qemu.ip, command), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Get the values of variables.
tcpath = get_bb_var("TARGET_SYS", "rust")
targetsys = get_bb_var("RUST_TARGET_SYS", "rust")
rustlibpath = get_bb_var("WORKDIR", "rust")
tmpdir = get_bb_var("TMPDIR", "rust")
# Set path for target-poky-linux-gcc, RUST_TARGET_PATH and hosttools.
cmd = "export TARGET_VENDOR=\"-poky\";"
cmd = cmd + " export PATH=%s/recipe-sysroot-native/usr/bin/python3-native:%s/recipe-sysroot-native/usr/bin:%s/recipe-sysroot-native/usr/bin/%s:%s/hosttools:$PATH;" % (rustlibpath, rustlibpath, rustlibpath, tcpath, tmpdir)
cmd = cmd + " export RUST_TARGET_PATH=%s/rust-targets;" % rustlibpath
# Trigger testing.
cmd = cmd + " export TEST_DEVICE_ADDR=\"%s:12345\";" % qemu.ip
cmd = cmd + " cd %s; python3 src/bootstrap/bootstrap.py test %s --target %s" % (builddir, testargs, targetsys)
retval = runCmd(cmd)
end_time = time.time()
resultlog = rustlibpath + "/results-log.txt"
with open(resultlog, "w") as f:
f.write(retval.output)
ptestsuite = "rust"
self.ptest_section(ptestsuite, duration = int(end_time - start_time), logfile=resultlog)
test_results = parse_results(resultlog)
for test in test_results:
self.ptest_result(ptestsuite, test, test_results[test])