Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ features = ['unprefixed_malloc_on_supported_platforms']

[features]
# tidy-alphabetical-start
check_only = ['rustc_driver_impl/check_only']
jemalloc = ['dep:tikv-jemalloc-sys']
llvm = ['rustc_driver_impl/llvm']
max_level_info = ['rustc_driver_impl/max_level_info']
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ serde_json = "1"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
# tidy-alphabetical-end

[features]
check_only = ["rustc_llvm/check_only"]
1 change: 1 addition & 0 deletions compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ ctrlc = "3.4.4"

[features]
# tidy-alphabetical-start
check_only = ['rustc_interface/check_only']
llvm = ['rustc_interface/llvm']
max_level_info = ['rustc_log/max_level_info']
rustc_randomized_layouts = [
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ rustc_abi = { path = "../rustc_abi" }

[features]
# tidy-alphabetical-start
check_only = ['rustc_codegen_llvm?/check_only']
llvm = ['dep:rustc_codegen_llvm']
# tidy-alphabetical-end
4 changes: 4 additions & 0 deletions compiler/rustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ libc = "0.2.73"
# pinned `cc` in `rustc_codegen_ssa` if you update `cc` here.
cc = "=1.2.16"
# tidy-alphabetical-end

[features]
# Used by ./x.py check --compile-time-deps to skip building C++ code
Copy link
Member

Choose a reason for hiding this comment

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

Why is this only set with compile-time-deps? A regular check build also doesn't need the LLVM libraries, does it?

Copy link
Member Author

Choose a reason for hiding this comment

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

To not change existing behavior for ./x.py check. If this is also set for ./x.py check, that will no longer check if all C++ source files compile.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, fair... I never change those files so it's kind of unnecessary, but then the same is true for the Rust files in rustc_llvm. But those ofc check a lot faster than they build whereas the C++ files always do a full build :/

Copy link
Member Author

Choose a reason for hiding this comment

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

With #146596 you may be able to disable the LLVM backend entirely for stage 1 builds if ./x.py miri were to use the bootstrap compiler for building the build scripts of the standard library.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, funky. But most of the time I do need codegen as well (even Miri does, for build scripts and proc macros -- not sure if those can just use a different stage).

Copy link
Member Author

Choose a reason for hiding this comment

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

When bootstrap builds the standard library it uses different stages for build scripts and for the standard library itself. This does use a wrapper around rustc though.

check_only = []
4 changes: 4 additions & 0 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ fn output(cmd: &mut Command) -> String {
}

fn main() {
if cfg!(feature = "check_only") {
return;
}

for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
println!("cargo:rustc-check-cfg=cfg(llvm_component,values(\"{component}\"))");
}
Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ impl Step for Std {
return;
}

if run.builder.config.compile_time_deps {
// libstd doesn't have any important build scripts and can't have any proc macros
return;
}

let crates = std_crates_for_run_make(&run);
run.builder.ensure(Std {
build_compiler: prepare_compiler_for_check(run.builder, run.target, Mode::Std),
Expand Down Expand Up @@ -250,6 +255,13 @@ fn prepare_compiler_for_check(
match mode {
Mode::ToolBootstrap => builder.compiler(0, host),
Mode::ToolStd => {
if builder.config.compile_time_deps {
// When --compile-time-deps is passed, we can't use any rustc
// other than the bootstrap compiler. Luckily build scripts and
// proc macros for tools are unlikely to need nightly.
return builder.compiler(0, host);
}

// These tools require the local standard library to be checked
let build_compiler = builder.compiler(builder.top_stage, host);

Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,14 @@ Select which editor you would like to set up [default: None]: ";
"b5dd299b93dca3ceeb9b335f929293cb3d4bf4977866fbe7ceeac2a8a9f99088",
"631c837b0e98ae35fd48b0e5f743b1ca60adadf2d0a2b23566ba25df372cf1a9",
"080955765db84bb6cbf178879f489c4e2369397626a6ecb3debedb94a9d0b3ce",
"f501475c6654187091c924ae26187fa5791d74d4a8ab3fb61fbbe4c0275aade1",
],
EditorKind::Helix => &[
"2d3069b8cf1b977e5d4023965eb6199597755e6c96c185ed5f2854f98b83d233",
"6736d61409fbebba0933afd2e4c44ff2f97c1cb36cf0299a7f4a7819b8775040",
"f252dcc30ca85a193a699581e5e929d5bd6c19d40d7a7ade5e257a9517a124a5",
"198c195ed0c070d15907b279b8b4ea96198ca71b939f5376454f3d636ab54da5",
"1c43ead340b20792b91d02b08494ee68708e7e09f56b6766629b4b72079208f1",
],
EditorKind::Vim | EditorKind::VsCode => &[
"ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8",
Expand All @@ -607,12 +609,14 @@ Select which editor you would like to set up [default: None]: ";
"e53e9129ca5ee5dcbd6ec8b68c2d87376474eb154992deba3c6d9ab1703e0717",
"f954316090936c7e590c253ca9d524008375882fa13c5b41d7e2547a896ff893",
"701b73751efd7abd6487f2c79348dab698af7ac4427b79fa3d2087c867144b12",
"a61df796c0c007cb6512127330564e49e57d558dec715703916a928b072a1054",
],
EditorKind::Zed => &[
"bbce727c269d1bd0c98afef4d612eb4ce27aea3c3a8968c5f10b31affbc40b6c",
"a5380cf5dd9328731aecc5dfb240d16dac46ed272126b9728006151ef42f5909",
"2e96bf0d443852b12f016c8fc9840ab3d0a2b4fe0b0fb3a157e8d74d5e7e0e26",
"4fadd4c87389a601a27db0d3d74a142fa3a2e656ae78982e934dbe24bee32ad6",
"f0bb3d23ab1a49175ab0ef5c4071af95bb03d01d460776cdb716d91333443382",
],
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ impl Builder<'_> {
// Make cargo emit diagnostics relative to the rustc src dir.
cargo.arg(format!("-Zroot-dir={}", self.src.display()));

if self.config.compile_time_deps {
// Build only build scripts and proc-macros for rust-analyzer when requested.
cargo.arg("-Zunstable-options");
cargo.arg("--compile-time-deps");
}

// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
// Force cargo to output binaries with disambiguating hashes in the name
let mut metadata = if compiler.stage == 0 {
Expand Down
10 changes: 10 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct Config {
pub include_default_paths: bool,
pub rustc_error_format: Option<String>,
pub json_output: bool,
pub compile_time_deps: bool,
pub test_compare_mode: bool,
pub color: Color,
pub patch_binaries_for_nix: Option<bool>,
Expand Down Expand Up @@ -421,6 +422,7 @@ impl Config {
jobs: flags_jobs,
warnings: flags_warnings,
json_output: flags_json_output,
compile_time_deps: flags_compile_time_deps,
color: flags_color,
bypass_bootstrap_lock: flags_bypass_bootstrap_lock,
rust_profile_generate: flags_rust_profile_generate,
Expand Down Expand Up @@ -468,6 +470,7 @@ impl Config {
config.include_default_paths = flags_include_default_paths;
config.rustc_error_format = flags_rustc_error_format;
config.json_output = flags_json_output;
config.compile_time_deps = flags_compile_time_deps;
config.on_fail = flags_on_fail;
config.cmd = flags_cmd;
config.incremental = flags_incremental;
Expand Down Expand Up @@ -1064,6 +1067,13 @@ impl Config {
_ => {}
}

if config.compile_time_deps && !matches!(config.cmd, Subcommand::Check { .. }) {
eprintln!(
"WARNING: Can't use --compile-time-deps with any subcommand other than check."
);
exit!(1);
}

// CI should always run stage 2 builds, unless it specifically states otherwise
#[cfg(not(test))]
if flags_stage.is_none() && config.is_running_on_ci {
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/config/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ pub struct Flags {
#[arg(global = true, long)]
/// use message-format=json
pub json_output: bool,
#[arg(global = true, long)]
/// only build proc-macros and build scripts (for rust-analyzer)
pub compile_time_deps: bool,

#[arg(global = true, long, value_name = "STYLE")]
#[arg(value_enum, default_value_t = Color::Auto)]
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ impl Build {
if self.config.rust_randomize_layout && check("rustc_randomized_layouts") {
features.push("rustc_randomized_layouts");
}
if self.config.compile_time_deps && kind == Kind::Check {
features.push("check_only");
}

// If debug logging is on, then we want the default for tracing:
// https://github.com/tokio-rs/tracing/blob/3dd5c03d907afdf2c39444a29931833335171554/tracing/src/level_filters.rs#L26
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "The --extra-checks flag now supports prefixing any check with `auto:` to only run it if relevant files are modified",
},
ChangeInfo {
change_id: 143785,
severity: ChangeSeverity::Info,
summary: "A --compile-time-deps flag has been added to reduce the time it takes rust-analyzer to start",
},
];
Loading
Loading