Skip to content

bootstrap: add bootstrap step to run stdarch-gen checks in CI#156674

Open
xonx4l wants to merge 5 commits into
rust-lang:mainfrom
xonx4l:port-stdarch-gen
Open

bootstrap: add bootstrap step to run stdarch-gen checks in CI#156674
xonx4l wants to merge 5 commits into
rust-lang:mainfrom
xonx4l:port-stdarch-gen

Conversation

@xonx4l
Copy link
Copy Markdown
Contributor

@xonx4l xonx4l commented May 17, 2026

This PR ports stdarch-gen checks into the bootstrap test runner as a step, so that we can run the stdarch-gen checks via x.py test.

Changes -:
-> Adds a new StdarchGenCheck bootstrap step.
-> Mirrors https://github.com/rust-lang/stdarch/blob/f71ac102d30d5d1957277cbffc6ba631b67bffd1/.github/workflows/main.yml#L309-L333 (check-stdarch-gen job)
-> stdarch-gen-arm uses a nightly only feature (#![feature(pattern)]) but bootstrap's cargo runs on the beta toolchain thus we set RUSTC_BOOTSTRAP=1 on the child process so it builds.
-> The generators call out to rustfmt to format their output so rustfmt needs to be on PATH. So added bootstrap's rustfmt to PATH before each run. If rustfmt isn't available, the step fails early and tells the user to set rustfmt = true in bootstrap.toml .

r? @Kobzol

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels May 17, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 17, 2026

Kobzol is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 26, 2026

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

Copy link
Copy Markdown
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I left some comments, the most important one is the question about why things are copied over.

View changes since this review

});

let mut path_dirs: Vec<PathBuf> = Vec::new();
if let Some(cargo_dir) = builder.initial_cargo.parent() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does cargo need to be in PATH?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because cargo_dir is providing rustc . As cargo run build looks up rustc on PATH .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we should set RUSTC to point to the rustc that we want to invoke directly, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay makes sense can do.

let work_dir = builder.out.join("stdarch-gen-check");
let cargo_target_dir = work_dir.join("target");

// Writable copy of `crates/core_arch` that the generators write into.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Writable copy of `crates/core_arch` that the generators write into.
// Writable copy of `crates/core_arch` that the generators write into when blessing.

if out_core_arch.exists() {
t!(fs::remove_dir_all(&out_core_arch));
}
cp_writable_r(&src_core_arch, &out_core_arch);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to copy things over? My mental model of how this should work is:

  1. When running the test, we generate the output code into some temporary directory on disk
  2. We then check if the generated files are the same as the files committed in the repo.
  3. If not, and we are not blessing, the test fails.
  4. If not, and we are blessing, the generated files override the committed files (we also need to ensure that any leftover files are deleted, so the committed dir should probably be emptied first).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your mental model is right it's just the copy is mainly there for the arm generator. It writes its output files directly into existing folders under core_arch/src but doesn't create those folders itself so they have to already exist. Copying core_arch over gives it those folders. Having the full copy also let run a single git diff over the whole folder instead of listing every generated file by hand. It's the same thing stdarch's own check-stdarch-gen CI does.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather edit the generator to create those directories and make it so that it doesn't write to the source dirs, than do hacks with cp_writable_r.

In fact, to ensure that we run the same logic, it might be better if the check + bless logic actually lived within the generators themselves, and maybe we could also unify them under a single crate, it looks like they are separate right now? I wonder if there's an opportunity to do some refactoring there to make the whole setup less hacky.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approached with cp_writable_r to keep the changes minimal and strictly around bootstrap step only but if you want then I think we can edit the generator and can get rid of cp_writable_r . Yes they are separate right now and yeah by unifying it will make the whole setup less hacky for sure .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd rather also do targeted refactorings to stdarch to make the overall testing infra better, rather than to just try hacking bootstrap around whatever stdarch is currently doing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such changes are welcome. You can experiment here, and once you're happy we can see how to sync the changes back into stdarch


/// Recursively copy src to dst clearing the read-only bit so the destination can be
/// regenerated even when src lives on a read-only filesystem.
fn cp_writable_r(src: &Path, dst: &Path) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed. We shouldn't ever bless on CI, nor copy any files on CI, only locally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The read-only handling isn't for bless it only runs locally never on CI. It's there because we copy core_arch into the work folder at the start of every run and on CI the original files are read-only so the copies come out read-only too.

run_gen("-p", "stdarch-gen-hexagon", &[hexagon_out.as_os_str()], None);
run_gen("-p", "stdarch-gen-hexagon-scalar", &[hexagon_out.as_os_str()], None);

let mut git = helpers::git(Some(&stdarch_root));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I was kinda thinking that we would check the files using Rust code, but I checked bootstrap and it doesn't seem like we already do any diffing at the moment, so git diff seems fine.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

☔ The latest upstream changes (presumably #153957) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants