From ee5404c69ecd5ea1500bd14b854a2b08d1196d21 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Thu, 9 Feb 2023 14:01:07 +0000 Subject: Add additional options to `x setup` --- src/bootstrap/builder.rs | 2 +- src/bootstrap/flags.rs | 13 +++-- src/bootstrap/setup.rs | 120 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 114 insertions(+), 21 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index b4fc1d4f28d..98998bfe5f2 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -793,7 +793,7 @@ impl<'a> Builder<'a> { run::CollectLicenseMetadata, run::GenerateCopyright, ), - Kind::Setup => describe!(setup::Profile), + Kind::Setup => describe!(setup::Profile, setup::Hook, setup::Link, setup::Vscode), Kind::Clean => describe!(clean::CleanAll, clean::Rustc, clean::Std), // special-cased in Build::build() Kind::Format => vec![], diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 52c3dc0bf75..30d96dd2d28 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -542,7 +542,8 @@ Arguments: Kind::Setup => { subcommand_help.push_str(&format!( "\n -x.py setup creates a `config.toml` which changes the defaults for x.py itself. +x.py setup creates a `config.toml` which changes the defaults for x.py itself, +as well as setting up a git pre-push hook, VS code config and toolchain link. Arguments: This subcommand accepts a 'profile' to use for builds. For example: @@ -552,7 +553,13 @@ Arguments: The profile is optional and you will be prompted interactively if it is not given. The following profiles are available: -{}", +{} + + To only set up the git hook, VS code or toolchain link, you may use + ./x.py setup hook + ./x.py setup vscode + ./x.py setup link +", Profile::all_for_help(" ").trim_end() )); } @@ -625,7 +632,7 @@ Arguments: } Kind::Setup => { let profile = if paths.len() > 1 { - eprintln!("\nerror: At most one profile can be passed to setup\n"); + eprintln!("\nerror: At most one option can be passed to setup\n"); usage(1, &opts, verbose, &subcommand_help) } else if let Some(path) = paths.pop() { let profile_string = t!(path.into_os_string().into_string().map_err( diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs index 2b613ad50ee..28ae6e75789 100644 --- a/src/bootstrap/setup.rs +++ b/src/bootstrap/setup.rs @@ -21,6 +21,7 @@ pub enum Profile { Library, Tools, User, + None, } /// A list of historical hashes of `src/etc/vscode_settings.json`. @@ -40,7 +41,7 @@ impl Profile { pub fn all() -> impl Iterator { use Profile::*; // N.B. these are ordered by how they are displayed, not alphabetically - [Library, Compiler, Codegen, Tools, User].iter().copied() + [Library, Compiler, Codegen, Tools, User, None].iter().copied() } pub fn purpose(&self) -> String { @@ -51,6 +52,7 @@ impl Profile { Codegen => "Contribute to the compiler, and also modify LLVM or codegen", Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)", User => "Install Rust from source", + None => "Do not modify `config.toml`" } .to_string() } @@ -70,6 +72,7 @@ impl Profile { Profile::Library => "library", Profile::Tools => "tools", Profile::User => "user", + Profile::None => "none", } } } @@ -86,6 +89,7 @@ impl FromStr for Profile { "tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => { Ok(Profile::Tools) } + "none" => Ok(Profile::None), _ => Err(format!("unknown profile: '{}'", s)), } } @@ -143,17 +147,8 @@ impl Step for Profile { } pub fn setup(config: &Config, profile: Profile) { - let stage_path = - ["build", config.build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string()); - - if !rustup_installed() && profile != Profile::User { - eprintln!("`rustup` is not installed; cannot link `stage1` toolchain"); - } else if stage_dir_exists(&stage_path[..]) && !config.dry_run() { - attempt_toolchain_link(&stage_path[..]); - } - - let suggestions = match profile { - Profile::Codegen | Profile::Compiler => &["check", "build", "test"][..], + let suggestions: &[&str] = match profile { + Profile::Codegen | Profile::Compiler | Profile::None => &["check", "build", "test"], Profile::Tools => &[ "check", "build", @@ -166,11 +161,6 @@ pub fn setup(config: &Config, profile: Profile) { Profile::User => &["dist", "build"], }; - if !config.dry_run() { - t!(install_git_hook_maybe(&config)); - t!(create_vscode_settings_maybe(&config)); - } - println!(); println!("To get started, try one of the following commands:"); @@ -189,6 +179,9 @@ pub fn setup(config: &Config, profile: Profile) { } fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) { + if profile == Profile::None { + return; + } if path.exists() { eprintln!(); eprintln!( @@ -216,6 +209,41 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) { println!("`x.py` will now use the configuration at {}", include_path.display()); } +/// Creates a toolchain link for stage1 using `rustup` +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub struct Link; +impl Step for Link { + type Output = (); + const DEFAULT: bool = true; + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.alias("link") + } + fn make_run(run: RunConfig<'_>) { + if run.builder.config.dry_run() { + return; + } + if let [cmd] = &run.paths[..] { + if cmd.assert_single_path().path.as_path().as_os_str() == "link" { + run.builder.ensure(Link); + } + } + } + fn run(self, builder: &Builder<'_>) -> Self::Output { + let config = &builder.config; + if config.dry_run() { + return; + } + let stage_path = + ["build", config.build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string()); + + if !rustup_installed() { + eprintln!("`rustup` is not installed; cannot link `stage1` toolchain"); + } else if stage_dir_exists(&stage_path[..]) && !config.dry_run() { + attempt_toolchain_link(&stage_path[..]); + } + } +} + fn rustup_installed() -> bool { Command::new("rustup") .arg("--version") @@ -393,6 +421,35 @@ fn prompt_user(prompt: &str) -> io::Result> { } } +/// Installs `src/etc/pre-push.sh` as a Git hook +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub struct Hook; + +impl Step for Hook { + type Output = (); + const DEFAULT: bool = true; + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.alias("hook") + } + fn make_run(run: RunConfig<'_>) { + if run.builder.config.dry_run() { + return; + } + if let [cmd] = &run.paths[..] { + if cmd.assert_single_path().path.as_path().as_os_str() == "hook" { + run.builder.ensure(Hook); + } + } + } + fn run(self, builder: &Builder<'_>) -> Self::Output { + let config = &builder.config; + if config.dry_run() { + return; + } + t!(install_git_hook_maybe(&config)); + } +} + // install a git hook to automatically run tidy, if they want fn install_git_hook_maybe(config: &Config) -> io::Result<()> { let git = t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| { @@ -431,6 +488,35 @@ undesirable, simply delete the `pre-push` file from .git/hooks." Ok(()) } +/// Sets up or displays `src/etc/vscode_settings.json` +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub struct Vscode; + +impl Step for Vscode { + type Output = (); + const DEFAULT: bool = true; + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.alias("vscode") + } + fn make_run(run: RunConfig<'_>) { + if run.builder.config.dry_run() { + return; + } + if let [cmd] = &run.paths[..] { + if cmd.assert_single_path().path.as_path().as_os_str() == "vscode" { + run.builder.ensure(Vscode); + } + } + } + fn run(self, builder: &Builder<'_>) -> Self::Output { + let config = &builder.config; + if config.dry_run() { + return; + } + t!(create_vscode_settings_maybe(&config)); + } +} + /// Create a `.vscode/settings.json` file for rustc development, or just print it fn create_vscode_settings_maybe(config: &Config) -> io::Result<()> { let (current_hash, historical_hashes) = SETTINGS_HASHES.split_last().unwrap(); -- cgit 1.4.1-3-g733a5 From c7f443a6e3320b4cb70da5af08810f1dd60e146c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 21 Feb 2023 10:12:06 +1100 Subject: Enable --cfg=parallel_compiler in rustdoc. --- src/bootstrap/tool.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index d30532ef3c6..3c9a154da9a 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -595,7 +595,7 @@ impl Step for Rustdoc { features.push("jemalloc".to_string()); } - let cargo = prepare_tool_cargo( + let mut cargo = prepare_tool_cargo( builder, build_compiler, Mode::ToolRustc, @@ -606,6 +606,10 @@ impl Step for Rustdoc { features.as_slice(), ); + if builder.config.rustc_parallel { + cargo.rustflag("--cfg=parallel_compiler"); + } + let msg = tooling_output( Mode::ToolRustc, "rustdoc", -- cgit 1.4.1-3-g733a5 From a5d27316fe49feb36c332f16dd82da959de664fb Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Tue, 21 Feb 2023 10:04:19 +0100 Subject: Revert "port over symlink_file function from Build to Config and create symlink for legacy rustfmt path" This reverts commit 41c6c5d4996728b5a635319ef9b077a3d0ccc480. --- src/bootstrap/download.rs | 19 +------------------ src/bootstrap/lib.rs | 11 ++++++++++- src/bootstrap/native.rs | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/download.rs b/src/bootstrap/download.rs index d6592d2d771..d1e2149d3f9 100644 --- a/src/bootstrap/download.rs +++ b/src/bootstrap/download.rs @@ -2,7 +2,7 @@ use std::{ env, ffi::{OsStr, OsString}, fs::{self, File}, - io::{self, BufRead, BufReader, ErrorKind}, + io::{BufRead, BufReader, ErrorKind}, path::{Path, PathBuf}, process::{Command, Stdio}, }; @@ -26,14 +26,6 @@ impl Config { self.verbose > 0 } - pub fn symlink_file, Q: AsRef>(&self, src: P, link: Q) -> io::Result<()> { - #[cfg(unix)] - use std::os::unix::fs::symlink as symlink_file; - #[cfg(windows)] - use std::os::windows::fs::symlink_file; - if !self.dry_run() { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) } - } - pub(crate) fn create(&self, path: &Path, s: &str) { if self.dry_run() { return; @@ -338,15 +330,6 @@ impl Config { let bin_root = self.out.join(host.triple).join("rustfmt"); let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host)); let rustfmt_stamp = bin_root.join(".rustfmt-stamp"); - - #[cfg(not(windows))] - { - let legacy_rustfmt = self.initial_rustc.with_file_name(exe("rustfmt", host)); - if !legacy_rustfmt.exists() { - t!(self.symlink_file(&rustfmt_path, &legacy_rustfmt)); - } - } - if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) { return Some(rustfmt_path); } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index f753720b353..f4abdf1cc57 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -20,6 +20,7 @@ use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet}; use std::env; use std::fs::{self, File}; +use std::io; use std::io::ErrorKind; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; @@ -1406,7 +1407,7 @@ impl Build { src = t!(fs::canonicalize(src)); } else { let link = t!(fs::read_link(src)); - t!(self.config.symlink_file(link, dst)); + t!(self.symlink_file(link, dst)); return; } } @@ -1524,6 +1525,14 @@ impl Build { iter.map(|e| t!(e)).collect::>().into_iter() } + fn symlink_file, Q: AsRef>(&self, src: P, link: Q) -> io::Result<()> { + #[cfg(unix)] + use std::os::unix::fs::symlink as symlink_file; + #[cfg(windows)] + use std::os::windows::fs::symlink_file; + if !self.config.dry_run() { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) } + } + /// Returns if config.ninja is enabled, and checks for ninja existence, /// exiting with a nicer error message if not. fn ninja(&self) -> bool { diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index d6e63fb937e..21157b02a78 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -516,7 +516,7 @@ impl Step for Llvm { let lib_llvm = out_dir.join("build").join("lib").join(lib_name); if !lib_llvm.exists() { - t!(builder.build.config.symlink_file("libLLVM.dylib", &lib_llvm)); + t!(builder.symlink_file("libLLVM.dylib", &lib_llvm)); } } -- cgit 1.4.1-3-g733a5 From 6ca499bf2b3da83d60062da649805c36c03ce194 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Tue, 21 Feb 2023 14:41:11 +0100 Subject: Revert "Copy `bin/*` and `lib/*.dylib` files to `stage0-sysroot`" This reverts commit 6990ab9ad2cde9b67073ffac29ffecc2be8e722f. --- src/bootstrap/compile.rs | 66 ------------------------------------------------ 1 file changed, 66 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index f0fcdf0d5a0..348d22a9ce6 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -459,72 +459,6 @@ impl Step for StdLink { let libdir = builder.sysroot_libdir(target_compiler, target); let hostdir = builder.sysroot_libdir(target_compiler, compiler.host); add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target)); - - if compiler.stage == 0 { - // special handling for stage0, to make `rustup toolchain link` and `x dist --stage 0` - // work for stage0-sysroot - let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot"); - - let host_lib_dir = builder.initial_rustc.ancestors().nth(2).unwrap().join("lib"); - let host_bin_dir = builder.out.join(&builder.initial_rustc.parent().unwrap()); - let host_codegen_backends = - host_lib_dir.join("rustlib").join(&compiler.host.triple).join("codegen-backends"); - let sysroot_bin_dir = sysroot.join("bin"); - let sysroot_lib_dir = sysroot.join("lib"); - let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler); - - // Create the `bin` directory in stage0-sysroot - t!(fs::create_dir_all(&sysroot_bin_dir)); - - // copy bin files from `builder.initial_rustc/./` to `stage0-sysroot/bin` - if let Ok(files) = fs::read_dir(&host_bin_dir) { - for file in files { - let file = t!(file); - if file.file_name() == "rustfmt" { - // This is when `rustc` and `cargo` are set in `config.toml` - if !file.path().starts_with(&builder.out) { - builder.copy( - &file.path().into_boxed_path(), - &sysroot_bin_dir.join(file.file_name()), - ); - } else { - builder.copy( - &builder - .out - .join(&compiler.host.triple) - .join("rustfmt/bin/rustfmt"), - &sysroot_bin_dir.join(file.file_name()), - ); - } - } else { - builder.copy( - &file.path().into_boxed_path(), - &sysroot_bin_dir.join(file.file_name()), - ); - } - } - } - - // copy dylib files from `builder.initial_rustc/../lib/*` while excluding the `rustlib` directory to `stage0-sysroot/lib` - if let Ok(files) = fs::read_dir(&host_lib_dir) { - for file in files { - let file = t!(file); - let path = file.path(); - if path.is_file() - && is_dylib(&file.file_name().into_string().unwrap()) - && !path.starts_with(sysroot_lib_dir.join("rustlib").into_boxed_path()) - { - builder.copy(&path, &sysroot_lib_dir.join(path.file_name().unwrap())); - } - } - } - - t!(fs::create_dir_all(&sysroot_codegen_backends)); - // copy `codegen-backends` from `host_lib_dir/rustlib/codegen_backends` to `stage0-sysroot/lib/rustlib/host-triple/codegen-backends` if it exists. - if host_codegen_backends.exists() { - builder.cp_r(&host_codegen_backends, &sysroot_codegen_backends); - } - } } } -- cgit 1.4.1-3-g733a5 From 49516b3f5705c201a915c1b0c690d0f112da6c6a Mon Sep 17 00:00:00 2001 From: ozkanonur Date: Thu, 23 Feb 2023 21:35:41 +0300 Subject: support `x fmt` for sub and outside of rust directories Signed-off-by: ozkanonur --- src/bootstrap/format.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/format.rs b/src/bootstrap/format.rs index 615794958d0..ae72a42973c 100644 --- a/src/bootstrap/format.rs +++ b/src/bootstrap/format.rs @@ -218,7 +218,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) { WalkBuilder::new(first) } } else { - WalkBuilder::new(first) + WalkBuilder::new(src.join(first)) }; for path in &paths[1..] { @@ -229,7 +229,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) { walker.add(path); } } else { - walker.add(path); + walker.add(src.join(path)); } } -- cgit 1.4.1-3-g733a5 From 34813e205157f0235e5cf8847079f13ac6acd078 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 15 Dec 2022 14:49:11 +0800 Subject: Test that the compiler/library builds with -Zmir-opt-level=3 -Zvalidate-mir --- config.toml.example | 3 +++ src/bootstrap/builder.rs | 7 +++++++ src/bootstrap/config.rs | 3 +++ src/ci/run.sh | 1 + 4 files changed, 14 insertions(+) (limited to 'src/bootstrap') diff --git a/config.toml.example b/config.toml.example index df4478bb0cb..69eb228a2d5 100644 --- a/config.toml.example +++ b/config.toml.example @@ -666,6 +666,9 @@ changelog-seen = 2 # LTO entirely. #lto = "thin-local" +# Build compiler with the optimization enabled and -Zvalidate-mir, currently only for `std` +#validate-mir-opts = 3 + # ============================================================================= # Options for specific targets # diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 952c70cec1c..fe92ee3c18e 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1915,6 +1915,13 @@ impl<'a> Builder<'a> { } } + if matches!(mode, Mode::Std) { + if let Some(mir_opt_level) = self.config.rust_validate_mir_opts { + rustflags.arg("-Zvalidate-mir"); + rustflags.arg(&format!("-Zmir-opt-level={}", mir_opt_level)); + } + } + Cargo { command: cargo, rustflags, rustdocflags, allow_features } } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 56f96734bbb..4a563bc396d 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -173,6 +173,7 @@ pub struct Config { pub rust_profile_use: Option, pub rust_profile_generate: Option, pub rust_lto: RustcLto, + pub rust_validate_mir_opts: Option, pub llvm_profile_use: Option, pub llvm_profile_generate: bool, pub llvm_libunwind_default: Option, @@ -770,6 +771,7 @@ define_config! { // ignored; this is set from an env var set by bootstrap.py download_rustc: Option = "download-rustc", lto: Option = "lto", + validate_mir_opts: Option = "validate-mir-opts", } } @@ -1149,6 +1151,7 @@ impl Config { .as_deref() .map(|value| RustcLto::from_str(value).unwrap()) .unwrap_or_default(); + config.rust_validate_mir_opts = rust.validate_mir_opts; } else { config.rust_profile_use = flags.rust_profile_use; config.rust_profile_generate = flags.rust_profile_generate; diff --git a/src/ci/run.sh b/src/ci/run.sh index 93dccb54c4e..1f451fc479c 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -58,6 +58,7 @@ RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-manage-submodules" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-locked-deps" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-cargo-native-static" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1" +RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.validate-mir-opts=3" # Only produce xz tarballs on CI. gz tarballs will be generated by the release # process by recompressing the existing xz ones. This decreases the storage -- cgit 1.4.1-3-g733a5