From 992dd0bbe39fc65257fd9e8bfd21a1d0779ec52e Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 10 Aug 2024 14:56:22 +0200 Subject: [PATCH 1/6] CI: rfl: add a couple comments to split the steps and document them Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index 389abb2fdd38c..90706a550174f 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -62,11 +62,20 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ defconfig \ rfl-for-rust-ci.config +# Build a few Rust targets +# +# This does not include building the C side of the kernel nor linking, +# which can find other issues, but it is much faster. +# +# This includes transforming `rustdoc` tests into KUnit ones thanks to +# `CONFIG_RUST_KERNEL_DOCTESTS=y` above (which, for the moment, uses the +# unstable `--test-builder` and `--no-run`). make -C linux LLVM=1 -j$(($(nproc) + 1)) \ samples/rust/rust_minimal.o \ samples/rust/rust_print.o \ drivers/net/phy/ax88796b_rust.o \ rust/doctests_kernel_generated.o +# Generate documentation make -C linux LLVM=1 -j$(($(nproc) + 1)) \ rustdoc From d783b1dabdcf7e61612d9ab7dde35f38251d3736 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 28 Aug 2024 01:53:47 +0200 Subject: [PATCH 2/6] CI: rfl: switch to a stage 2 build Apparently tools like `rustfmt` require it in order to find the right `librustc_driver.so` without extra tweaks. Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index 90706a550174f..51644f2f47e77 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -5,7 +5,7 @@ set -euo pipefail LINUX_VERSION=4c7864e81d8bbd51036dacf92fb0a400e13aaeee # Build rustc, rustdoc and cargo -../x.py build --stage 1 library rustdoc +../x.py build --stage 2 library rustdoc ../x.py build --stage 0 cargo # Install rustup so that we can use the built toolchain easily, and also @@ -16,7 +16,7 @@ sh rustup.sh -y --default-toolchain none source /cargo/env BUILD_DIR=$(realpath ./build) -rustup toolchain link local "${BUILD_DIR}"/x86_64-unknown-linux-gnu/stage1 +rustup toolchain link local "${BUILD_DIR}"/x86_64-unknown-linux-gnu/stage2 rustup default local mkdir -p rfl From 824397ddf6536664ec91ac42c6473b7cbf8844f6 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 10 Aug 2024 16:35:52 +0200 Subject: [PATCH 3/6] CI: rfl: add a Clippy build Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index 51644f2f47e77..2f9ec3c23a8e8 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -4,8 +4,8 @@ set -euo pipefail LINUX_VERSION=4c7864e81d8bbd51036dacf92fb0a400e13aaeee -# Build rustc, rustdoc and cargo -../x.py build --stage 2 library rustdoc +# Build rustc, rustdoc, cargo and clippy-driver +../x.py build --stage 2 library rustdoc clippy ../x.py build --stage 0 cargo # Install rustup so that we can use the built toolchain easily, and also @@ -79,3 +79,14 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ # Generate documentation make -C linux LLVM=1 -j$(($(nproc) + 1)) \ rustdoc + +# Re-build with Clippy enabled +# +# This should not introduce Clippy errors, since `CONFIG_WERROR` is not +# set (thus no `-Dwarnings`) and the kernel uses `-W` for all Clippy +# lints, including `clippy::all`. However, it could catch ICEs. +make -C linux LLVM=1 -j$(($(nproc) + 1)) CLIPPY=1 \ + samples/rust/rust_minimal.o \ + samples/rust/rust_print.o \ + drivers/net/phy/ax88796b_rust.o \ + rust/doctests_kernel_generated.o From d584f7099a3c17c76a38f686a9af0b1d36a686ab Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 10 Aug 2024 16:47:20 +0200 Subject: [PATCH 4/6] CI: rfl: add a `rustfmt` run This change will also remove the current warnings in the build due to `rustfmt` not being available (for `bindgen` output): error: 'rustfmt' is not installed for the custom toolchain 'local'. note: this is a custom toolchain, which cannot use `rustup component add` help: if you built this toolchain from source, and used `rustup toolchain link`, then you may be able to build the component with `x.py` Failed to run rustfmt: Internal rustfmt error (non-fatal, continuing) Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index 2f9ec3c23a8e8..030b6f6ee1763 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -4,8 +4,8 @@ set -euo pipefail LINUX_VERSION=4c7864e81d8bbd51036dacf92fb0a400e13aaeee -# Build rustc, rustdoc, cargo and clippy-driver -../x.py build --stage 2 library rustdoc clippy +# Build rustc, rustdoc, cargo, clippy-driver and rustfmt +../x.py build --stage 2 library rustdoc clippy rustfmt ../x.py build --stage 0 cargo # Install rustup so that we can use the built toolchain easily, and also @@ -90,3 +90,10 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) CLIPPY=1 \ samples/rust/rust_print.o \ drivers/net/phy/ax88796b_rust.o \ rust/doctests_kernel_generated.o + +# Format the code +# +# This returns successfully even if there were changes, i.e. it is not +# a check. +make -C linux LLVM=1 -j$(($(nproc) + 1)) \ + rustfmt From 5c558d3ff419fce1d74dd455bb089e26938578af Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 10 Aug 2024 17:08:44 +0200 Subject: [PATCH 5/6] CI: rfl: add macro expanded source build (`-Zunpretty=expanded`) This particular target does not expand into much code, so it is a good first candidate to see if we could keep this in the CI. Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index 030b6f6ee1763..e8b6235921db0 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -80,6 +80,14 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ rustdoc +# Build macro expanded source (`-Zunpretty=expanded`) +# +# This target also formats the macro expanded code, thus it is also +# intended to catch ICEs with formatting `-Zunpretty=expanded` output +# like https://github.com/rust-lang/rustfmt/issues/6105. +make -C linux LLVM=1 -j$(($(nproc) + 1)) \ + samples/rust/rust_minimal.rsi + # Re-build with Clippy enabled # # This should not introduce Clippy errors, since `CONFIG_WERROR` is not From 778ff06ba6fe5d5c85604e569179100e00dd24d1 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 10 Aug 2024 17:22:42 +0200 Subject: [PATCH 6/6] CI: rfl: factor out build targets It will make it easier to add more in the future. Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index e8b6235921db0..8011e07e92e60 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -62,6 +62,13 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ defconfig \ rfl-for-rust-ci.config +BUILD_TARGETS=" + samples/rust/rust_minimal.o + samples/rust/rust_print.o + drivers/net/phy/ax88796b_rust.o + rust/doctests_kernel_generated.o +" + # Build a few Rust targets # # This does not include building the C side of the kernel nor linking, @@ -71,10 +78,7 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ # `CONFIG_RUST_KERNEL_DOCTESTS=y` above (which, for the moment, uses the # unstable `--test-builder` and `--no-run`). make -C linux LLVM=1 -j$(($(nproc) + 1)) \ - samples/rust/rust_minimal.o \ - samples/rust/rust_print.o \ - drivers/net/phy/ax88796b_rust.o \ - rust/doctests_kernel_generated.o + $BUILD_TARGETS # Generate documentation make -C linux LLVM=1 -j$(($(nproc) + 1)) \ @@ -94,10 +98,7 @@ make -C linux LLVM=1 -j$(($(nproc) + 1)) \ # set (thus no `-Dwarnings`) and the kernel uses `-W` for all Clippy # lints, including `clippy::all`. However, it could catch ICEs. make -C linux LLVM=1 -j$(($(nproc) + 1)) CLIPPY=1 \ - samples/rust/rust_minimal.o \ - samples/rust/rust_print.o \ - drivers/net/phy/ax88796b_rust.o \ - rust/doctests_kernel_generated.o + $BUILD_TARGETS # Format the code #