Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ macro_rules! bootstrap_tool {
;
)+) => {
#[derive(PartialEq, Eq, Clone)]
pub enum Tool {
pub(crate) enum Tool {
$(
#[allow(dead_code, reason = "not all bootstrap-tools need a variant")]
$name,
)+
}
Expand All @@ -419,14 +420,14 @@ macro_rules! bootstrap_tool {
/// Ensure a tool is built, then get the path to its executable.
///
/// The actual building, if any, will be handled via [`ToolBuild`].
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
pub(crate) fn tool_exe(&self, tool: Tool) -> PathBuf {
self.tool(tool).tool_path
}

/// Ensure a tool is built, then return its build output.
///
/// The actual building, if any, will be handled via [`ToolBuild`].
pub fn tool(&self, tool: Tool) -> ToolBuildResult {
pub(crate) fn tool(&self, tool: Tool) -> ToolBuildResult {
match tool {
$(Tool::$name =>
self.ensure($name {
Expand Down Expand Up @@ -1621,7 +1622,7 @@ impl Builder<'_> {
/// `host`.
///
/// This also ensures that the given tool is built (using [`ToolBuild`]).
pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
pub(crate) fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
let mut cmd = command(self.tool_exe(tool));
let compiler = self.compiler(0, self.config.host_target);
let host = &compiler.host;
Expand Down
41 changes: 21 additions & 20 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl HostFlags {
}

#[derive(Debug)]
pub struct Cargo {
pub(crate) struct Cargo {
command: BootstrapCommand,
args: Vec<OsString>,
compiler: Compiler,
Expand All @@ -158,7 +158,7 @@ impl Cargo {
/// Calls [`Builder::cargo`] and [`Cargo::configure_linker`] to prepare an invocation of `cargo`
/// to be run.
#[track_caller]
pub fn new(
pub(crate) fn new(
builder: &Builder<'_>,
compiler: Compiler,
mode: Mode,
Expand All @@ -182,30 +182,31 @@ impl Cargo {
cargo
}

pub fn release_build(&mut self, release_build: bool) {
pub(crate) fn release_build(&mut self, release_build: bool) {
self.profile = if release_build { Some("release") } else { None };
}

pub fn profile(&mut self, profile: &'static str) {
#[expect(dead_code, reason = "general-purpose, currently unused")]
pub(crate) fn profile(&mut self, profile: &'static str) {
self.profile = Some(profile);
}

pub fn compiler(&self) -> Compiler {
pub(crate) fn compiler(&self) -> Compiler {
self.compiler
}

pub fn mode(&self) -> Mode {
pub(crate) fn mode(&self) -> Mode {
self.mode
}

pub fn into_cmd(self) -> BootstrapCommand {
pub(crate) fn into_cmd(self) -> BootstrapCommand {
self.into()
}

/// Same as [`Cargo::new`] except this one doesn't configure the linker with
/// [`Cargo::configure_linker`].
#[track_caller]
pub fn new_for_mir_opt_tests(
pub(crate) fn new_for_mir_opt_tests(
builder: &Builder<'_>,
compiler: Compiler,
mode: Mode,
Expand All @@ -220,22 +221,22 @@ impl Cargo {
cargo
}

pub fn rustdocflag(&mut self, arg: &str) -> &mut Cargo {
pub(crate) fn rustdocflag(&mut self, arg: &str) -> &mut Cargo {
self.rustdocflags.arg(arg);
self
}

pub fn rustflag(&mut self, arg: &str) -> &mut Cargo {
pub(crate) fn rustflag(&mut self, arg: &str) -> &mut Cargo {
self.rustflags.arg(arg);
self
}

pub fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Cargo {
pub(crate) fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Cargo {
self.args.push(arg.as_ref().into());
self
}

pub fn args<I, S>(&mut self, args: I) -> &mut Cargo
pub(crate) fn args<I, S>(&mut self, args: I) -> &mut Cargo
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
Expand All @@ -249,7 +250,7 @@ impl Cargo {
/// Add an env var to the cargo command instance. Note that `RUSTFLAGS`/`RUSTDOCFLAGS` must go
/// through [`Cargo::rustdocflags`] and [`Cargo::rustflags`] because inconsistent `RUSTFLAGS`
/// and `RUSTDOCFLAGS` usages will trigger spurious rebuilds.
pub fn env(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Cargo {
pub(crate) fn env(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Cargo {
assert_ne!(key.as_ref(), "RUSTFLAGS");
assert_ne!(key.as_ref(), "RUSTDOCFLAGS");
self.command.env(key.as_ref(), value.as_ref());
Expand All @@ -262,7 +263,7 @@ impl Cargo {
///
/// Note that this only considers the existence of the env. var. configured on this `Cargo`
/// instance. It does not look at the environment of this process.
pub fn append_to_env(
pub(crate) fn append_to_env(
&mut self,
key: impl AsRef<OsStr>,
value: impl AsRef<OsStr>,
Expand All @@ -282,11 +283,11 @@ impl Cargo {
}
}

pub fn add_rustc_lib_path(&mut self, builder: &Builder<'_>) {
pub(crate) fn add_rustc_lib_path(&mut self, builder: &Builder<'_>) {
builder.add_rustc_lib_path(self.compiler, &mut self.command);
}

pub fn current_dir(&mut self, dir: &Path) -> &mut Cargo {
pub(crate) fn current_dir(&mut self, dir: &Path) -> &mut Cargo {
self.command.current_dir(dir);
self
}
Expand All @@ -295,7 +296,7 @@ impl Cargo {
///
/// By default, all nightly features are allowed. Once this is called, it will be restricted to
/// the given set.
pub fn allow_features(&mut self, features: &str) -> &mut Cargo {
pub(crate) fn allow_features(&mut self, features: &str) -> &mut Cargo {
if !self.allow_features.is_empty() {
self.allow_features.push(',');
}
Expand Down Expand Up @@ -554,7 +555,7 @@ impl From<Cargo> for BootstrapCommand {
impl Builder<'_> {
/// Like [`Builder::cargo`], but only passes flags that are valid for all commands.
#[track_caller]
pub fn bare_cargo(
pub(crate) fn bare_cargo(
&self,
compiler: Compiler,
mode: Mode,
Expand Down Expand Up @@ -1538,7 +1539,7 @@ impl Builder<'_> {
}
}

pub fn cargo_profile_var(name: &str, config: &Config, mode: Mode) -> String {
pub(crate) fn cargo_profile_var(name: &str, config: &Config, mode: Mode) -> String {
let profile = match (mode, config.rust_optimize.is_release()) {
// Some std configuration exists in its own profile
(Mode::Std, _) => "DIST",
Expand All @@ -1550,7 +1551,7 @@ pub fn cargo_profile_var(name: &str, config: &Config, mode: Mode) -> String {

/// Applies PGO compile flags to the given Cargo invocation based on the given PGO config.
/// PGO flags are only applied when compiling a stage2 component.
pub fn apply_pgo(
pub(crate) fn apply_pgo(
builder: &Builder<'_>,
cargo: &mut Cargo,
build_compiler: Compiler,
Expand Down
20 changes: 12 additions & 8 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use clap::ValueEnum;
#[cfg(feature = "tracing")]
use tracing::instrument;

pub use self::cargo::{Cargo, apply_pgo, cargo_profile_var};
pub(crate) use self::cargo::{Cargo, apply_pgo, cargo_profile_var};
use crate::core::build_steps::compile::{Std, StdLink, looks_like_codegen_backend};
use crate::core::build_steps::tool::RustcPrivateCompilers;
use crate::core::build_steps::{
Expand Down Expand Up @@ -108,7 +108,7 @@ impl dyn AnyDebug {
/// Historically, steps also participated in command-line processing.
/// That responsibility has been split off into the larger [`CommandLineStep`] trait,
/// which helper steps don't need to implement.
pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
pub(crate) trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
/// Result type of [`Step::run`]. Stored in the step cache for later lookup.
type Output: Clone;

Expand All @@ -118,6 +118,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
fn run(self, builder: &Builder<'_>) -> Self::Output;

/// Returns metadata of the step, for tests.
#[cfg_attr(not(any(test, feature = "tracing")), expect(dead_code))]
fn metadata(&self) -> Option<StepMetadata> {
None
}
Expand All @@ -141,7 +142,7 @@ impl<S: CommandLineStep> Step for S {
/// A blanket impl allows every [`CommandLineStep`] to be used as a [`Step`].
/// This is arguably nicer than having it be a subtrait, because it avoids the
/// need for two separate `impl` blocks per command-line-step type.
pub trait CommandLineStep: 'static + Clone + Debug + PartialEq + Eq + Hash {
pub(crate) trait CommandLineStep: 'static + Clone + Debug + PartialEq + Eq + Hash {
/// Result type of [`Step::run`].
type Output: Clone;

Expand Down Expand Up @@ -190,7 +191,7 @@ pub trait CommandLineStep: 'static + Clone + Debug + PartialEq + Eq + Hash {

/// Metadata that describes an executed step, mostly for testing and tracing.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StepMetadata {
pub(crate) struct StepMetadata {
name: String,
kind: Kind,
target: TargetSelection,
Expand Down Expand Up @@ -248,19 +249,22 @@ impl StepMetadata {
self
}

pub fn get_stage(&self) -> Option<u32> {
#[cfg_attr(not(any(test, feature = "tracing")), expect(dead_code))]
pub(crate) fn get_stage(&self) -> Option<u32> {
self.stage.or(self
.built_by
// For std, its stage corresponds to the stage of the compiler that builds it.
// For everything else, a stage N things gets built by a stage N-1 compiler.
.map(|compiler| if self.name == "std" { compiler.stage } else { compiler.stage + 1 }))
}

pub fn get_name(&self) -> &str {
#[cfg_attr(not(feature = "tracing"), expect(dead_code))]
pub(crate) fn get_name(&self) -> &str {
&self.name
}

pub fn get_target(&self) -> TargetSelection {
#[cfg_attr(not(feature = "tracing"), expect(dead_code))]
pub(crate) fn get_target(&self) -> TargetSelection {
self.target
}
}
Expand Down Expand Up @@ -1565,7 +1569,7 @@ Alternatively, you can set `build.local-rebuild=true` and use a stage0 compiler
/// cache the step, so it is safe (and good!) to call this as often as
/// needed to ensure that all dependencies are built.
#[track_caller]
pub fn ensure<S: Step>(&'a self, step: S) -> S::Output {
pub(crate) fn ensure<S: Step>(&'a self, step: S) -> S::Output {
{
let mut stack = self.stack.borrow_mut();
for stack_step in stack.iter() {
Expand Down
9 changes: 5 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
/// on each field, see the corresponding fields in
/// `bootstrap.example.toml`.
#[derive(Clone)]
pub struct Config {
pub(crate) struct Config {
pub change_id: Option<ChangeId>,
pub bypass_bootstrap_lock: bool,
pub ccache: Option<String>,
Expand Down Expand Up @@ -288,7 +288,6 @@ pub struct Config {
pub windows_rc: Option<PathBuf>,
pub reuse: Option<PathBuf>,
pub cargo_native_static: bool,
pub configure_args: Vec<String>,
pub out: PathBuf,
pub rust_info: channel::GitInfo,

Expand Down Expand Up @@ -517,7 +516,10 @@ impl Config {
profiler: build_profiler,
cargo_native_static: build_cargo_native_static,
low_priority: build_low_priority,
configure_args: build_configure_args,
// Our `./configure` script saves a copy of its command-line arguments as
// `build.configure-args` when generating `bootstrap.toml`.
// This is for debugging only, and bootstrap itself doesn't use these values.
configure_args: _,
local_rebuild: build_local_rebuild,
print_step_timings: build_print_step_timings,
print_step_rusage: build_print_step_rusage,
Expand Down Expand Up @@ -1430,7 +1432,6 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
compiletest_allow_stage0: build_compiletest_allow_stage0.unwrap_or(false),
compiletest_diff_tool: build_compiletest_diff_tool,
config: toml_path,
configure_args: build_configure_args.unwrap_or_default(),
control_flow_guard: rust_control_flow_guard.unwrap_or(false),
datadir: install_datadir.map(PathBuf::from),
deny_warnings,
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use std::fmt::Display;
use std::path::PathBuf;
use std::str::FromStr;

pub use config::*;
use serde::de::Unexpected;
use serde::{Deserialize, Deserializer};
use serde_derive::Deserialize;
Expand All @@ -32,6 +31,7 @@ pub use toml::change_id::ChangeId;
pub use toml::rust::BootstrapOverrideLld;
pub use toml::target::Target;

pub(crate) use self::config::*;
use crate::utils::helpers;

pub(crate) trait Merge {
Expand Down
8 changes: 2 additions & 6 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl Build {
/// line and the filesystem `config`.
///
/// By default all build output will be placed in the current directory.
pub fn new(mut config: Config) -> Build {
pub(crate) fn new(mut config: Config) -> Build {
let src = config.src.clone();
let out = config.out.clone();

Expand Down Expand Up @@ -576,7 +576,7 @@ impl Build {
}

/// Updates the given submodule only if it's initialized already; nothing happens otherwise.
pub fn update_existing_submodule(config: &Config, submodule: &str) {
pub(crate) fn update_existing_submodule(config: &Config, submodule: &str) {
// Avoid running git when there isn't a git checkout.
if !config.submodules() {
return;
Expand Down Expand Up @@ -1851,10 +1851,6 @@ to download LLVM rather than building it.
result
}

pub fn exec_ctx(&self) -> &ExecutionContext {
&self.config.exec_ctx
}

pub fn report_summary(&self, path: &Path, start_time: Instant) {
self.config.exec_ctx.profiler().report_summary(path, start_time);
}
Expand Down
Loading