Skip to content

Commit 347452e

Browse files
committed
Auto merge of #116196 - onur-ozkan:reorganize-bootstrap-sources, r=Mark-Simulacrum
reorganize/refactor bootstrap codebase Currently, bootstrap stores everything on the root path, including very large modules, which makes things very hard to scale and adds too much complexity. This PR has the following objectives: - Improving scalability. - Making bootstrap source more understandable for the new contributors(or for everyone). - Improving the development experience and making maintenance easier for the bootstrap team. The new source structure: ``` . ├── defaults │   ├── README.md │   ├── config.codegen.toml │   ├── config.compiler.toml │   ├── config.dist.toml │   ├── config.library.toml │   └── config.tools.toml ├── mk │   └── Makefile.in ├── src │   ├── bin │   │   ├── main.rs │   │   ├── rustc.rs │   │   ├── rustdoc.rs │   │   └── sccache-plus-cl.rs │   ├── core │   │   ├── build_steps │   │   │   ├── check.rs │   │   │   ├── clean.rs │   │   │   ├── compile.rs │   │   │   ├── dist.rs │   │   │   ├── doc.rs │   │   │   ├── format.rs │   │   │   ├── install.rs │   │   │   ├── llvm.rs │   │   │   ├── mod.rs │   │   │   ├── run.rs │   │   │   ├── setup.rs │   │   │   ├── suggest.rs │   │   │   ├── synthetic_targets.rs │   │   │   ├── test.rs │   │   │   ├── tool.rs │   │   │   └── toolstate.rs │   │   ├── config │   │   │   ├── config.rs │   │   │   ├── flags.rs │   │   │   └── mod.rs │   │   ├── builder.rs │   │   ├── download.rs │   │   ├── metadata.rs │   │   ├── mod.rs │   │   └── sanity.rs │   ├── tests │   │   ├── builder.rs │   │   ├── config.rs │   │   └── setup.rs │   ├── utils │   │   ├── bin_helpers.rs │   │   ├── cache.rs │   │   ├── cc_detect.rs │   │   ├── channel.rs │   │   ├── dylib.rs │   │   ├── helpers.rs │   │   ├── job.rs │   │   ├── metrics.rs │   │   ├── mod.rs │   │   ├── render_tests.rs │   │   └── tarball.rs │   └── lib.rs ├── Cargo.lock ├── Cargo.toml ├── README.md ├── bootstrap.py ├── bootstrap_test.py ├── build.rs ├── configure.py └── download-ci-llvm-stamp ``` The next step involves: - Adding more doc-comments to the bootstrap internals (although we already have a decent amount, there is space for improvement). - Breaking large modules into smaller, more manageable modules. - Significantly increasing our unit test coverage (which is currently lacking). This PR should serve as an initial step to make the tasks above much more easier. r? Mark-Simulacrum
2 parents ddef56d + 3ecff1b commit 347452e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+530
-508
lines changed

src/bootstrap/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ default-run = "bootstrap"
99
build-metrics = ["sysinfo"]
1010

1111
[lib]
12-
path = "lib.rs"
12+
path = "src/lib.rs"
1313
doctest = false
1414

1515
[[bin]]
1616
name = "bootstrap"
17-
path = "bin/main.rs"
17+
path = "src/bin/main.rs"
1818
test = false
1919

2020
[[bin]]
2121
name = "rustc"
22-
path = "bin/rustc.rs"
22+
path = "src/bin/rustc.rs"
2323
test = false
2424

2525
[[bin]]
2626
name = "rustdoc"
27-
path = "bin/rustdoc.rs"
27+
path = "src/bin/rustdoc.rs"
2828
test = false
2929

3030
[[bin]]
3131
name = "sccache-plus-cl"
32-
path = "bin/sccache-plus-cl.rs"
32+
path = "src/bin/sccache-plus-cl.rs"
3333
test = false
3434

3535
[dependencies]

src/bootstrap/job.rs

-143
This file was deleted.
File renamed without changes.

src/bootstrap/bin/rustc.rs renamed to src/bootstrap/src/bin/rustc.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@
1515
//! switching compilers for the bootstrap and for build scripts will probably
1616
//! never get replaced.
1717
18-
include!("../dylib_util.rs");
19-
include!("./_helper.rs");
20-
2118
use std::env;
2219
use std::path::PathBuf;
23-
use std::process::{exit, Child, Command};
20+
use std::process::{Child, Command};
2421
use std::time::Instant;
2522

23+
use dylib_util::{dylib_path, dylib_path_var};
24+
25+
#[path = "../utils/bin_helpers.rs"]
26+
mod bin_helpers;
27+
28+
#[path = "../utils/dylib.rs"]
29+
mod dylib_util;
30+
2631
fn main() {
2732
let args = env::args_os().skip(1).collect::<Vec<_>>();
2833
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
2934

30-
let verbose = parse_rustc_verbose();
35+
let verbose = bin_helpers::parse_rustc_verbose();
3136

3237
// Detect whether or not we're a build script depending on whether --target
3338
// is passed (a bit janky...)

src/bootstrap/bin/rustdoc.rs renamed to src/bootstrap/src/bin/rustdoc.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
use std::env;
66
use std::ffi::OsString;
77
use std::path::PathBuf;
8-
use std::process::{exit, Command};
8+
use std::process::Command;
99

10-
include!("../dylib_util.rs");
10+
use dylib_util::{dylib_path, dylib_path_var};
1111

12-
include!("./_helper.rs");
12+
#[path = "../utils/bin_helpers.rs"]
13+
mod bin_helpers;
14+
15+
#[path = "../utils/dylib.rs"]
16+
mod dylib_util;
1317

1418
fn main() {
1519
let args = env::args_os().skip(1).collect::<Vec<_>>();
1620

17-
let stage = parse_rustc_stage();
18-
let verbose = parse_rustc_verbose();
21+
let stage = bin_helpers::parse_rustc_stage();
22+
let verbose = bin_helpers::parse_rustc_verbose();
1923

2024
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
2125
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");

src/bootstrap/check.rs renamed to src/bootstrap/src/core/build_steps/check.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use crate::builder::{crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step};
4-
use crate::cache::Interned;
5-
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo};
6-
use crate::config::TargetSelection;
7-
use crate::tool::{prepare_tool_cargo, SourceType};
3+
use crate::core::build_steps::compile::{
4+
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
5+
};
6+
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
7+
use crate::core::builder::{crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step};
8+
use crate::core::config::TargetSelection;
9+
use crate::utils::cache::Interned;
810
use crate::INTERNER;
911
use crate::{Compiler, Mode, Subcommand};
1012
use std::path::{Path, PathBuf};
@@ -16,7 +18,7 @@ pub struct Std {
1618
///
1719
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
1820
///
19-
/// [`compile::Rustc`]: crate::compile::Rustc
21+
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
2022
crates: Interned<Vec<String>>,
2123
}
2224

@@ -193,7 +195,7 @@ pub struct Rustc {
193195
///
194196
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
195197
///
196-
/// [`compile::Rustc`]: crate::compile::Rustc
198+
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
197199
crates: Interned<Vec<String>>,
198200
}
199201

@@ -237,8 +239,8 @@ impl Step for Rustc {
237239
// the sysroot for the compiler to find. Otherwise, we're going to
238240
// fail when building crates that need to generate code (e.g., build
239241
// scripts and their dependencies).
240-
builder.ensure(crate::compile::Std::new(compiler, compiler.host));
241-
builder.ensure(crate::compile::Std::new(compiler, target));
242+
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
243+
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
242244
} else {
243245
builder.ensure(Std::new(target));
244246
}
@@ -387,7 +389,7 @@ impl Step for RustAnalyzer {
387389
&["rust-analyzer/in-rust-tree".to_owned()],
388390
);
389391

390-
cargo.allow_features(crate::tool::RustAnalyzer::ALLOW_FEATURES);
392+
cargo.allow_features(crate::core::build_steps::tool::RustAnalyzer::ALLOW_FEATURES);
391393

392394
// For ./x.py clippy, don't check those targets because
393395
// linting tests and benchmarks can produce very noisy results

src/bootstrap/clean.rs renamed to src/bootstrap/src/core/build_steps/clean.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use std::fs;
99
use std::io::{self, ErrorKind};
1010
use std::path::Path;
1111

12-
use crate::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
13-
use crate::cache::Interned;
14-
use crate::util::t;
12+
use crate::core::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
13+
use crate::utils::cache::Interned;
14+
use crate::utils::helpers::t;
1515
use crate::{Build, Compiler, Mode, Subcommand};
1616

1717
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

src/bootstrap/compile.rs renamed to src/bootstrap/src/core/build_steps/compile.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ use std::str;
1919

2020
use serde_derive::Deserialize;
2121

22-
use crate::builder::crate_description;
23-
use crate::builder::Cargo;
24-
use crate::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
25-
use crate::cache::{Interned, INTERNER};
26-
use crate::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
27-
use crate::dist;
28-
use crate::llvm;
29-
use crate::tool::SourceType;
30-
use crate::util::get_clang_cl_resource_dir;
31-
use crate::util::{exe, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date};
22+
use crate::core::build_steps::dist;
23+
use crate::core::build_steps::llvm;
24+
use crate::core::build_steps::tool::SourceType;
25+
use crate::core::builder::crate_description;
26+
use crate::core::builder::Cargo;
27+
use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
28+
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
29+
use crate::utils::cache::{Interned, INTERNER};
30+
use crate::utils::helpers::{
31+
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date,
32+
};
3233
use crate::LLVM_TOOLS;
3334
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
3435
use filetime::FileTime;
@@ -510,7 +511,7 @@ impl Step for StdLink {
510511
let (libdir, hostdir) = if self.force_recompile && builder.download_rustc() {
511512
// NOTE: copies part of `sysroot_libdir` to avoid having to add a new `force_recompile` argument there too
512513
let lib = builder.sysroot_libdir_relative(self.compiler);
513-
let sysroot = builder.ensure(crate::compile::Sysroot {
514+
let sysroot = builder.ensure(crate::core::build_steps::compile::Sysroot {
514515
compiler: self.compiler,
515516
force_recompile: self.force_recompile,
516517
});
@@ -1016,7 +1017,8 @@ pub fn rustc_cargo_env(
10161017
// detected that LLVM is already built and good to go which helps prevent
10171018
// busting caches (e.g. like #71152).
10181019
if builder.config.llvm_enabled() {
1019-
let building_is_expensive = crate::llvm::prebuilt_llvm_config(builder, target).is_err();
1020+
let building_is_expensive =
1021+
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target).is_err();
10201022
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
10211023
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == stage;
10221024
let should_skip_build = building_is_expensive && can_skip_build;
@@ -1684,7 +1686,7 @@ impl Step for Assemble {
16841686
builder.copy(&lld_install.join("bin").join(&src_exe), &libdir_bin.join(&dst_exe));
16851687
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
16861688
t!(fs::create_dir(&self_contained_lld_dir));
1687-
let lld_wrapper_exe = builder.ensure(crate::tool::LldWrapper {
1689+
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
16881690
compiler: build_compiler,
16891691
target: target_compiler.host,
16901692
});

0 commit comments

Comments
 (0)