Skip to content

Remove default config from bootstrap #145352

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Shourya742
Copy link
Contributor

This PR removes the default config initialization from parse_inner, as it introduced many assumptions during config setup. Instead, each variable is now manually initialized to eliminate certain invariants in parse_inner and streamline the process.

The PR is still a WIP and has been opened for an initial review.

r? @Kobzol

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 13, 2025
@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-08-12-remove-default-config branch from e1f4e5c to 9662ff8 Compare August 13, 2025 13:04
@rust-log-analyzer

This comment has been minimized.

Copy link
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.

Heh, I had feedback for you, but I see that Clippy did it for me in one of the commits xD Let me know once it's ready and I'll check the changes locally, but in general looks great.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-08-12-remove-default-config branch from a53f060 to d22b2a4 Compare August 15, 2025 02:34
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Aug 15, 2025

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

@Shourya742 Shourya742 force-pushed the 2025-08-12-remove-default-config branch from fdcd154 to 77c3d6e Compare August 18, 2025 04:16
@rust-log-analyzer

This comment has been minimized.

Copy link
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.

Let me know if it's ready for another round of review :)

Copy link
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.

Great work! Left a bunch of comments.

In general, I'm not happy about DownloadContext. Even with the macro I proposed, it's still too easy to use values before they are initialized, for example rust_info is used in download context before it is initialized :( And that's just one thing I noticed, possibly there may be more.

Before we can remove more I/O from parse_inner, I would suggest creating more granular versions of DownloadContext. For example, download_beta_toolchain requires exec_ctx, stage0_metadata, host_target, out, patch_binaries_for_nix, bootstrap_cache_path, llvm_assertions and is_running_on_ci, so approx. 50% of DownloadContext. If we created a separate ctx for this function, we could reduce the likelihood of similar errors.

.or_else(|| {
build_host.map(|h| h.iter().map(|t| TargetSelection::from_user(t)).collect())
})
.unwrap_or_else(|| vec![host_target]);
Copy link
Member

Choose a reason for hiding this comment

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

Could you move

targets: flags_target
                .map(|TargetSelectionList(targets)| targets)
                .or_else(|| {
                    build_target.map(|t| t.iter().map(|t| TargetSelection::from_user(t)).collect())
                })
                .unwrap_or_else(|| hosts.clone())

below initialization of hosts? These three things should be configured next to one another.

In general, I would put complex initialization out of the Config { } literal and into a local variable. So e.g.

let skip = flags_skip
                .into_iter()
                .chain(flags_exclude)
                .chain(build_exclude.unwrap_or_default())
                .map(|p| {
                    // Never return top-level path here as it would break `--skip`
                    // logic on rustc's internal test framework which is utilized by compiletest.
                    #[cfg(windows)]
                    {
                        PathBuf::from(p.to_string_lossy().replace('/', "\\"))
                    }
                    #[cfg(not(windows))]
                    {
                        p
                    }
                })
                .collect();

...

Config { ..., skip, ... }

E.g. gdb: build_gdb.map(PathBuf::from) is fine to have in the Config constructor, but more complex and multiline initialization should be moved into a separate variable, to make it easier to read.

The let skip variable should still be declared as late as possible, so just before the Config constructor.

};

Config {
change_id: toml.change_id.inner,
Copy link
Member

Choose a reason for hiding this comment

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

Could you please sort the fields in this constructor, and apply // tidy-alphabetical-start + // tidy-alphabetical-end to make sure that they stay sorted? Currently some relates values are far from one another.

if exec_ctx.dry_run() {
out = out.join("tmp-dry-run");
fs::create_dir_all(&out).expect("Failed to create dry-run directory");
dwn_ctx.out = out.clone();
Copy link
Member

Choose a reason for hiding this comment

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

This is brittle and not much better than the original situation where we incrementally modified Config. What if we created a local macro?

// Macro for creating a new download context. For every usage that needs it, we want to
        // create it anew, to ensure that it uses the latest values of the various variables used
        // in this function.
        macro_rules! make_dwn_ctx {
            () => {
                DownloadContext {
                    path_modification_cache: path_modification_cache.clone(),
                    src: &src,
                    rust_info: rust_info.clone(),
                    submodules: &submodules,
                    download_rustc_commit: download_rustc_commit.clone(),
                    host_target,
                    llvm_from_ci,
                    target_config: target_config.clone(),
                    out: out.clone(),
                    patch_binaries_for_nix,
                    exec_ctx: &exec_ctx,
                    stage0_metadata: &stage0_metadata,
                    llvm_assertions,
                    bootstrap_cache_path: &bootstrap_cache_path,
                    is_running_on_ci,
                }
            };
        }

Then you can just put make_dwn_ctx!() everywhere we need a download context, and it will be created fresh with the latest values of all required local variables, without requiring us to ensure that the download context is kept updated.

@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-08-12-remove-default-config branch from 83d5b07 to e261e25 Compare August 21, 2025 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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