Skip to content

Add new --test-codegen-backend bootstrap option #145256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2025

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 11, 2025

This new bootstrap command line flag allows to do:

./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc

This is the last step before running it into the CI.

Supersedes #144687.

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 Aug 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 11, 2025

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

{
let sysroot = sysroot.join("lib");
let sysroot_str = sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
cargo.env("LD_LIBRARY_PATH", sysroot_str);
Copy link
Member Author

Choose a reason for hiding this comment

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

Sadly I still need to change this env variable to be able to build the compiler with the GCC backend. However, no need anymore for the tests. \o/

@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Member

Kobzol commented Aug 11, 2025

Why isn't it enough to set rust.codegen-backends = ["gcc"] and then run x test? It should build stage 1 rustc configured to use the GCC backend by default, so when it is used in tests, it should compile everything using the GCC codegen backend.

@GuillaumeGomez
Copy link
Member Author

Because as a first step we want to keep rustc built with LLVM and run tests with the GCC backend to limit the potential impact.

@GuillaumeGomez GuillaumeGomez force-pushed the bootstrap-test-codegen-backend branch from 65df661 to 09c014a Compare August 11, 2025 16:28
@Kobzol
Copy link
Member

Kobzol commented Aug 11, 2025

If stage 1 tests are enough for you, then using the default codegen backend would be enough for that. We would build rustc using LLVM, then build libstd using GCC, and then run tests using GCC. Or do you think we require stage 2 at this moment?

@GuillaumeGomez
Copy link
Member Author

I have two use cases for this:

  1. It's super easy to test another codegen backend without having to edit a config file without (potentially) having to recompile.
  2. I'd like to be able to "cross test" rustc built with one backend and using another one to ensure no weird corner cases come up.

@GuillaumeGomez
Copy link
Member Author

Forgot but we're supposed to have a command-line argument as described here.

@Kobzol
Copy link
Member

Kobzol commented Aug 11, 2025

I have two use cases for this:

  1. It's super easy to test another codegen backend without having to edit a config file without (potentially) having to recompile.
  2. I'd like to be able to "cross test" rustc built with one backend and using another one to ensure no weird corner cases come up.

You can do e.g. x test --set 'rust.codegen-backends=["gcc"]' to run tests with the GCC backend without modifying the config file.

I'm fine with having a flag, but I don't think that what the PR currently does is what you want 🤔It only tells compiletest that you're using a rustc that builds stuff using the GCC backend, but you don't make sure that is indeed what happens. In other words, the flag as currently implemented is a no-op, and the actual functionality that gets you GCC used during tests is setting "gcc" as the first member of "rust.codegen-backends". That's why I was confused about what the flag should do and how does it differ from setting the "gcc" field 😅

I would suggest either:

  • Not add a flag for now and just set "gcc" as the first member of rust.codegen-backends. This allows you to use a LLVM-compiled rustc and GCC-compiled stdlib to run (stage 1) tests using the GCC backend.
  • Add a flag that will instruct compiletest to append something like -Zcodegen-backend=gcc to the compile flags of every executed test. This allows you to use a LLVM-compiled rustc + LLVM-compiled stdlib and run (even stage 2) tests using the GCC backend.

@GuillaumeGomez GuillaumeGomez force-pushed the bootstrap-test-codegen-backend branch from 09c014a to 67a7a4d Compare August 12, 2025 14:07
@rustbot rustbot added the A-compiletest Area: The compiletest test runner label Aug 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 12, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@GuillaumeGomez
Copy link
Member Author

Arf indeed, forgot to put back the Zcodegen-backend in compiletest like I did in the original PR. Fixed it.

@Kobzol
Copy link
Member

Kobzol commented Aug 12, 2025

@bors try jobs=i686-gnu-1,i686-gnu-2

Checking if this won't break the duplicated-path-in-error test, which already sets a codegen backend.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 12, 2025
…, r=<try>

Add new `--test-codegen-backend` bootstrap option

try-job: i686-gnu-1
try-job: i686-gnu-2
@rust-bors
Copy link

rust-bors bot commented Aug 12, 2025

☀️ Try build successful (CI)
Build commit: 358a1b9 (358a1b968738bf403b88d97d95495d552a6df7c3, parent: a1531335fe2807715fff569904d99602022643a7)

@antoyo
Copy link
Contributor

antoyo commented Aug 12, 2025

cc @RalfJung: Please confirm that this feature is what you were suggesting in the MCP discussion to run more tests of cg_gcc in the CI.

@Kobzol
Copy link
Member

Kobzol commented Aug 12, 2025

I think Ralf is on a vacation, so might take a while to respond. In the meantime I'll review how the LD_LIBRARY_PATH is configured, I'd like to land that separately from the flag.

@GuillaumeGomez
Copy link
Member Author

I can move it to another PR if you prefer (can wait until your review is done).

@RalfJung
Copy link
Member

I lost all context, if you could provide some references that'd help.

But IIRC all I asked for is a simple command to run these tests that works without much fuzz on as many contributors' systems as reasonably possible -- the usual standard we have for our test suite. Also looking at the error log when the test fails should make it as clear as possible how to reproduce the failure locally (generally we're not great at that; as the number of test suites and targets and other combinations we cover increases, we should think about this more systematically).

@GuillaumeGomez GuillaumeGomez force-pushed the bootstrap-test-codegen-backend branch from 67a7a4d to aa8fdd7 Compare August 14, 2025 09:56
@GuillaumeGomez
Copy link
Member Author

Removed first commit since it was done in #145341.

@RalfJung Context was in superseded PR, should have copied it here as well: rust-lang/compiler-team#891

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 20, 2025
@bors
Copy link
Collaborator

bors commented Aug 20, 2025

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

@Kobzol
Copy link
Member

Kobzol commented Aug 20, 2025

This flag is orthogonal to that. We can just document something like x build --set 'rust.codegen-backends=["gcc"]', which builds libstd with cg_gcc.

Just to make sure I understand, is the purpose of the new flag --test-codegen-backend to be able to run the UI tests with a different backend than the one used to compile the sysroot?
If so, if we will need to use --set 'rust.codegen-backends=["gcc"]' implicitly or not in the future to compile the sysroot with cg_gcc, does that mean that this new flag --test-codegen-backend will only be used temporarily until we get there?
I'm asking since --set 'rust.codegen-backends=["gcc"]' would do the same and more, if I understand correctly.

Your understanding of the flag is correct. I
The flag is not just temporary though, it's generally useful to override the used backend without having to recompile rustc.

@GuillaumeGomez GuillaumeGomez force-pushed the bootstrap-test-codegen-backend branch from 2d3ee01 to e4cdc0f Compare August 20, 2025 10:19
@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez
Copy link
Member Author

Fixed merge conflict.

@bors r=Kobzol,bjorn3 rollup

@bors
Copy link
Collaborator

bors commented Aug 20, 2025

📌 Commit e4cdc0f has been approved by Kobzol,bjorn3

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 20, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 20, 2025
…gen-backend, r=Kobzol,bjorn3

Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes rust-lang#144687.

r? `@Kobzol`
bors added a commit that referenced this pull request Aug 20, 2025
Rollup of 5 pull requests

Successful merges:

 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145647 (miri subtree update)
 - #145650 (Fix JS search scripts path)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 20, 2025
…gen-backend, r=Kobzol,bjorn3

Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes rust-lang#144687.

r? ``@Kobzol``
bors added a commit that referenced this pull request Aug 20, 2025
Rollup of 12 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144443 (Make target pointer width in target json an integer)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145573 (Add an experimental unsafe(force_target_feature) attribute.)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)

Failed merges:

 - #145647 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 20, 2025
…gen-backend, r=Kobzol,bjorn3

Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes rust-lang#144687.

r? ```@Kobzol```
bors added a commit that referenced this pull request Aug 20, 2025
Rollup of 14 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144443 (Make target pointer width in target json an integer)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145137 (Consolidate panicking functions in `slice/index.rs`)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 21, 2025
…gen-backend, r=Kobzol,bjorn3

Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes rust-lang#144687.

r? ````@Kobzol````
bors added a commit that referenced this pull request Aug 21, 2025
Rollup of 15 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145137 (Consolidate panicking functions in `slice/index.rs`)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145590 (Prevent impossible combinations in `ast::ModKind`.)
 - #145621 (Fix some doc typos)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 21, 2025
…gen-backend, r=Kobzol,bjorn3

Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes rust-lang#144687.

r? `````@Kobzol`````
bors added a commit that referenced this pull request Aug 21, 2025
Rollup of 19 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145390 (Shorten some dependency chains in the compiler)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145525 (stdlib: Replace typedef -> type alias in doc comment)
 - #145590 (Prevent impossible combinations in `ast::ModKind`.)
 - #145593 (UnsafePinned::raw_get: sync signature with get)
 - #145621 (Fix some doc typos)
 - #145627 (Unconditionally-const supertraits are considered not dyn compatible)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145673 (Add flock support for cygwin)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b0dd772 into rust-lang:master Aug 21, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 21, 2025
rust-timer added a commit that referenced this pull request Aug 21, 2025
Rollup merge of #145256 - GuillaumeGomez:bootstrap-test-codegen-backend, r=Kobzol,bjorn3

Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes #144687.

r? ``````@Kobzol``````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

9 participants