Auto merge of #118724 - onur-ozkan:refactor-x-install, r=Mark-Simulacrum

speed up `x install` by skipping archiving and compression

Performing archiving and compression on `x install` is nothing more than a waste of time and resources. Additionally, for systems like gentoo(which uses `x install`) this should be highly beneficial.

[benchmark report](https://github.com/rust-lang/rust/pull/118724#issuecomment-1848964908)

Resolves #109308

r? Mark-Simulacrum (I think you want to review this, feel free to change it if otherwise.)
This commit is contained in:
bors 2024-02-25 12:19:55 +00:00
commit 26cd5d862e
5 changed files with 37 additions and 4 deletions

View File

@ -131,4 +131,9 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<ChangeInfo> {
severity: ChangeSeverity::Warning, severity: ChangeSeverity::Warning,
summary: "The \"codegen\"/\"llvm\" profile has been removed and replaced with \"compiler\", use it instead for the same behavior.", summary: "The \"codegen\"/\"llvm\" profile has been removed and replaced with \"compiler\", use it instead for the same behavior.",
}, },
ChangeInfo {
change_id: 118724,
severity: ChangeSeverity::Info,
summary: "`x install` now skips providing tarball sources (under 'build/dist' path) to speed up the installation process.",
},
]; ];

View File

@ -3,8 +3,8 @@
process::Command, process::Command,
}; };
use crate::core::build_steps::dist::distdir;
use crate::core::builder::Builder; use crate::core::builder::Builder;
use crate::core::{build_steps::dist::distdir, builder::Kind};
use crate::utils::channel; use crate::utils::channel;
use crate::utils::helpers::t; use crate::utils::helpers::t;
@ -325,7 +325,22 @@ fn run(self, build_cli: impl FnOnce(&Tarball<'a>, &mut Command)) -> GeneratedTar
assert!(!formats.is_empty(), "dist.compression-formats can't be empty"); assert!(!formats.is_empty(), "dist.compression-formats can't be empty");
cmd.arg("--compression-formats").arg(formats.join(",")); cmd.arg("--compression-formats").arg(formats.join(","));
} }
cmd.args(["--compression-profile", &self.builder.config.dist_compression_profile]);
// For `x install` tarball files aren't needed, so we can speed up the process by not producing them.
let compression_profile = if self.builder.kind == Kind::Install {
self.builder.verbose("Forcing dist.compression-profile = 'no-op' for `x install`.");
// "no-op" indicates that the rust-installer won't produce compressed tarball sources.
"no-op"
} else {
assert!(
self.builder.config.dist_compression_profile != "no-op",
"dist.compression-profile = 'no-op' can only be used for `x install`"
);
&self.builder.config.dist_compression_profile
};
cmd.args(&["--compression-profile", compression_profile]);
self.builder.run(&mut cmd); self.builder.run(&mut cmd);
// Ensure there are no symbolic links in the tarball. In particular, // Ensure there are no symbolic links in the tarball. In particular,

View File

@ -1,11 +1,12 @@
use anyhow::{Context, Error}; use anyhow::{Context, Error};
use flate2::{read::GzDecoder, write::GzEncoder}; use flate2::{read::GzDecoder, write::GzEncoder};
use rayon::prelude::*; use rayon::prelude::*;
use std::{convert::TryFrom, fmt, io::Read, io::Write, path::Path, str::FromStr}; use std::{fmt, io::Read, io::Write, path::Path, str::FromStr};
use xz2::{read::XzDecoder, write::XzEncoder}; use xz2::{read::XzDecoder, write::XzEncoder};
#[derive(Default, Debug, Copy, Clone)] #[derive(Default, Debug, Copy, Clone)]
pub enum CompressionProfile { pub enum CompressionProfile {
NoOp,
Fast, Fast,
#[default] #[default]
Balanced, Balanced,
@ -20,6 +21,7 @@ fn from_str(input: &str) -> Result<Self, Error> {
"fast" => Self::Fast, "fast" => Self::Fast,
"balanced" => Self::Balanced, "balanced" => Self::Balanced,
"best" => Self::Best, "best" => Self::Best,
"no-op" => Self::NoOp,
other => anyhow::bail!("invalid compression profile: {other}"), other => anyhow::bail!("invalid compression profile: {other}"),
}) })
} }
@ -31,6 +33,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
CompressionProfile::Fast => f.write_str("fast"), CompressionProfile::Fast => f.write_str("fast"),
CompressionProfile::Balanced => f.write_str("balanced"), CompressionProfile::Balanced => f.write_str("balanced"),
CompressionProfile::Best => f.write_str("best"), CompressionProfile::Best => f.write_str("best"),
CompressionProfile::NoOp => f.write_str("no-op"),
} }
} }
} }
@ -78,10 +81,16 @@ pub(crate) fn encode(
CompressionProfile::Fast => flate2::Compression::fast(), CompressionProfile::Fast => flate2::Compression::fast(),
CompressionProfile::Balanced => flate2::Compression::new(6), CompressionProfile::Balanced => flate2::Compression::new(6),
CompressionProfile::Best => flate2::Compression::best(), CompressionProfile::Best => flate2::Compression::best(),
CompressionProfile::NoOp => panic!(
"compression profile 'no-op' should not call `CompressionFormat::encode`."
),
}, },
)), )),
CompressionFormat::Xz => { CompressionFormat::Xz => {
let encoder = match profile { let encoder = match profile {
CompressionProfile::NoOp => panic!(
"compression profile 'no-op' should not call `CompressionFormat::encode`."
),
CompressionProfile::Fast => { CompressionProfile::Fast => {
xz2::stream::MtStreamBuilder::new().threads(6).preset(1).encoder().unwrap() xz2::stream::MtStreamBuilder::new().threads(6).preset(1).encoder().unwrap()
} }

View File

@ -1,5 +1,5 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::{self, Parser}; use clap::Parser;
#[derive(Parser)] #[derive(Parser)]
struct CommandLine { struct CommandLine {

View File

@ -38,6 +38,10 @@ pub struct Tarballer {
impl Tarballer { impl Tarballer {
/// Generates the actual tarballs /// Generates the actual tarballs
pub fn run(self) -> Result<()> { pub fn run(self) -> Result<()> {
if let CompressionProfile::NoOp = self.compression_profile {
return Ok(());
}
let tarball_name = self.output.clone() + ".tar"; let tarball_name = self.output.clone() + ".tar";
let encoder = CombinedEncoder::new( let encoder = CombinedEncoder::new(
self.compression_formats self.compression_formats