Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up x install by skipping archiving and compression #118724

Merged
merged 3 commits into from
Feb 25, 2024
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
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 @@ -131,4 +131,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning,
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.",
},
];
19 changes: 17 additions & 2 deletions src/bootstrap/src/utils/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{
process::Command,
};

use crate::core::build_steps::dist::distdir;
use crate::core::builder::Builder;
use crate::core::{build_steps::dist::distdir, builder::Kind};
use crate::utils::channel;
use crate::utils::helpers::t;

Expand Down Expand Up @@ -325,7 +325,22 @@ impl<'a> Tarball<'a> {
assert!(!formats.is_empty(), "dist.compression-formats can't be empty");
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);

// Ensure there are no symbolic links in the tarball. In particular,
Expand Down
11 changes: 10 additions & 1 deletion src/tools/rust-installer/src/compression.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use anyhow::{Context, Error};
use flate2::{read::GzDecoder, write::GzEncoder};
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};

#[derive(Default, Debug, Copy, Clone)]
pub enum CompressionProfile {
NoOp,
Fast,
#[default]
Balanced,
Expand All @@ -20,6 +21,7 @@ impl FromStr for CompressionProfile {
"fast" => Self::Fast,
"balanced" => Self::Balanced,
"best" => Self::Best,
"no-op" => Self::NoOp,
other => anyhow::bail!("invalid compression profile: {other}"),
})
}
Expand All @@ -31,6 +33,7 @@ impl fmt::Display for CompressionProfile {
CompressionProfile::Fast => f.write_str("fast"),
CompressionProfile::Balanced => f.write_str("balanced"),
CompressionProfile::Best => f.write_str("best"),
CompressionProfile::NoOp => f.write_str("no-op"),
}
}
}
Expand Down Expand Up @@ -78,10 +81,16 @@ impl CompressionFormat {
CompressionProfile::Fast => flate2::Compression::fast(),
CompressionProfile::Balanced => flate2::Compression::new(6),
CompressionProfile::Best => flate2::Compression::best(),
CompressionProfile::NoOp => panic!(
"compression profile 'no-op' should not call `CompressionFormat::encode`."
),
},
)),
CompressionFormat::Xz => {
let encoder = match profile {
CompressionProfile::NoOp => panic!(
"compression profile 'no-op' should not call `CompressionFormat::encode`."
),
CompressionProfile::Fast => {
xz2::stream::MtStreamBuilder::new().threads(6).preset(1).encoder().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-installer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use clap::{self, Parser};
use clap::Parser;

#[derive(Parser)]
struct CommandLine {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/rust-installer/src/tarballer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ actor! {
impl Tarballer {
/// Generates the actual tarballs
pub fn run(self) -> Result<()> {
if let CompressionProfile::NoOp = self.compression_profile {
return Ok(());
}

let tarball_name = self.output.clone() + ".tar";
let encoder = CombinedEncoder::new(
self.compression_formats
Expand Down
Loading