Skip to content

Concurrent downloads yml chaneges for ci #4345

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

Closed
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
180 changes: 61 additions & 119 deletions .github/workflows/ci.yaml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum-map = "2.5.0"
env_proxy = { version = "0.4.1", optional = true }
flate2 = { version = "1.1.1", default-features = false, features = ["zlib-rs"] }
fs_at = "0.2.1"
futures = "0.3.31"
git-testament = "0.2"
home = "0.5.4"
itertools = "0.14"
Expand All @@ -78,6 +79,7 @@ serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
sharded-slab = "0.1.1"
strsim = "0.11"
sys-info = "0.9.1"
tar = "0.4.26"
tempfile = "3.8"
termcolor = "1.2"
Expand Down
7 changes: 3 additions & 4 deletions ci/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ rustc -vV
cargo -vV

if [ -n "$INSTALL_BINDGEN" ]; then
if ! curl --proto '=https' --tlsv1.2 -LsSf https://github.com/rust-lang/rust-bindgen/releases/latest/download/bindgen-cli-installer.sh | sh -s -- --no-modify-path \
| grep "everything's installed!";
if ! curl --proto '=https' --tlsv1.2 -LsSf https://github.com/rust-lang/rust-bindgen/releases/latest/download/bindgen-cli-installer.sh | sh -s -- --no-modify-path | grep "everything's installed!";
# Ignoring exit code since the script might fail to write the receipt after a successful installation.
then
cargo install --force --locked bindgen-cli
cargo +1.81.0 install --force --locked bindgen-cli
fi
mkdir "$CARGO_HOME"/bin/bindgen-cli
mv "$CARGO_HOME"/bin/bindgen "$CARGO_HOME"/bin/bindgen-cli/
Expand Down Expand Up @@ -45,7 +44,7 @@ fi
target_cargo() {
cmd="$1"
shift
cargo "${cmd}" --locked --profile "$BUILD_PROFILE" --target "$TARGET" "${FEATURES[@]}" "$@"
cargo +"1.81.0" "${cmd}" --locked --profile "$BUILD_PROFILE" --target "$TARGET" "${FEATURES[@]}" "$@"
}

target_cargo build
Expand Down
39 changes: 35 additions & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use anyhow::{Context, Error, Result, anyhow};
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum, builder::PossibleValue};
use clap_complete::Shell;
use itertools::Itertools;
use tracing::{info, trace, warn};
use tracing::{info, trace, warn, debug};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
use sys_info;

use crate::dist::AutoInstallMode;
use crate::{
Expand Down Expand Up @@ -78,6 +79,10 @@ struct Rustup {
#[arg(short, long, conflicts_with = "verbose")]
quiet: bool,

/// Enable concurrent downloads and I/O operations
#[arg(long)]
concurrent: bool,

/// Release channel (e.g. +stable) or custom toolchain to set override
#[arg(
name = "+toolchain",
Expand Down Expand Up @@ -604,6 +609,34 @@ pub async fn main(

update_console_filter(process, &console_filter, matches.quiet, matches.verbose);

// Configure concurrency mode if specified
if matches.concurrent {
// Set up environment variables to enable concurrent operations
info!("Enabling concurrent downloads and I/O operations");
unsafe {
std::env::set_var("RUSTUP_IO_THREADS", "0"); // Use auto-detected optimal thread count
}

// Based on system memory, set a reasonable RAM budget for I/O operations
if std::env::var("RUSTUP_RAM_BUDGET").is_err() {
if let Ok(mem_info) = sys_info::mem_info() {
let total_ram = mem_info.total as usize * 1024; // Convert to bytes
let ram_budget = total_ram / 10; // Use 10% of system memory
unsafe {
std::env::set_var("RUSTUP_RAM_BUDGET", ram_budget.to_string());
}
debug!("Auto-configured RAM budget to {} MB", ram_budget / (1024 * 1024));
}
}
} else {
// Ensure we use the non-concurrent mode for compatibility
if std::env::var("RUSTUP_IO_THREADS").is_err() {
unsafe {
std::env::set_var("RUSTUP_IO_THREADS", "1"); // Use single-threaded I/O
}
}
}

let cfg = &mut common::set_globals(current_dir, matches.quiet, process)?;

if let Some(t) = &matches.plus_toolchain {
Expand Down Expand Up @@ -1739,6 +1772,7 @@ impl clap::ValueEnum for CompletionCommand {
}
}

// Implementation outside of the ValueEnum trait
impl fmt::Display for CompletionCommand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.to_possible_value() {
Expand Down Expand Up @@ -1766,7 +1800,6 @@ fn output_completion_script(
if let Shell::Zsh = shell {
writeln!(process.stdout().lock(), "#compdef cargo")?;
}

let script = match shell {
Shell::Bash => "/etc/bash_completion.d/cargo",
Shell::Zsh => "/share/zsh/site-functions/_cargo",
Expand All @@ -1778,7 +1811,6 @@ fn output_completion_script(
));
}
};

writeln!(
process.stdout().lock(),
"if command -v rustc >/dev/null 2>&1; then\n\
Expand All @@ -1787,6 +1819,5 @@ fn output_completion_script(
)?;
}
}

Ok(utils::ExitCode(0))
}
Loading