1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-11-27 08:27:34 +02:00

Speed up rust crate installs in workflow by using cargo-binstall (#2915)

When cargo xtask install-tools --binstall is used, precompiled binaries
are fetched if available.
Triggers a regular (compilation) install if binary releases do not
exist.

This is now configured to be used by the CI to speed up the build and
deploy workflows where possible.

Currently binary packages exist for:
- mdbook
- mdbook-pandoc
This commit is contained in:
michael-kerscher
2025-09-19 13:28:03 +02:00
committed by GitHub
parent 8b4849854a
commit f4a11a4fc5
2 changed files with 17 additions and 6 deletions

View File

@@ -5,8 +5,11 @@ description: Install mdbook with the dependencies we need.
runs: runs:
using: composite using: composite
steps: steps:
- name: Ensure cargo-binstall is installed
uses: cargo-bins/cargo-binstall@main
- name: Install mdbook - name: Install mdbook
run: cargo xtask install-tools run: cargo xtask install-tools --binstall
shell: bash shell: bash
- name: Install dependencies for mdbook-pandoc - name: Install dependencies for mdbook-pandoc

View File

@@ -42,7 +42,11 @@ struct Cli {
#[derive(Subcommand)] #[derive(Subcommand)]
enum Task { enum Task {
/// Installs the tools the project depends on. /// Installs the tools the project depends on.
InstallTools, InstallTools {
/// Use cargo-binstall for faster installation.
#[arg(long)]
binstall: bool,
},
/// Runs the web driver tests in the tests directory. /// Runs the web driver tests in the tests directory.
WebTests { WebTests {
/// Optional 'book html' directory - if set, will also refresh the list /// Optional 'book html' directory - if set, will also refresh the list
@@ -79,7 +83,7 @@ enum Task {
fn execute_task() -> Result<()> { fn execute_task() -> Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
match cli.task { match cli.task {
Task::InstallTools => install_tools(), Task::InstallTools { binstall } => install_tools(binstall),
Task::WebTests { dir } => run_web_tests(dir), Task::WebTests { dir } => run_web_tests(dir),
Task::RustTests => run_rust_tests(), Task::RustTests => run_rust_tests(),
Task::Serve { language, output } => start_web_server(language, output), Task::Serve { language, output } => start_web_server(language, output),
@@ -105,9 +109,13 @@ fn run_command(cmd: &mut Command) -> Result<()> {
Ok(()) Ok(())
} }
fn install_tools() -> Result<()> { fn install_tools(binstall: bool) -> Result<()> {
println!("Installing project tools..."); println!("Installing project tools...");
let cargo = env!("CARGO");
let install_command = if binstall { "binstall" } else { "install" };
const PINNED_NIGHTLY: &str = "nightly-2025-09-01"; const PINNED_NIGHTLY: &str = "nightly-2025-09-01";
// Install rustup components // Install rustup components
@@ -121,7 +129,6 @@ fn install_tools() -> Result<()> {
run_command(&mut cmd)?; run_command(&mut cmd)?;
} }
let cargo = env!("CARGO");
// The --locked flag is important for reproducible builds. // The --locked flag is important for reproducible builds.
let tools = [ let tools = [
("mdbook", "0.4.52"), ("mdbook", "0.4.52"),
@@ -134,12 +141,13 @@ fn install_tools() -> Result<()> {
for (tool, version) in tools { for (tool, version) in tools {
let mut cmd = Command::new(cargo); let mut cmd = Command::new(cargo);
cmd.args(["install", tool, "--version", version, "--locked"]); cmd.args([install_command, tool, "--version", version, "--locked"]);
run_command(&mut cmd)?; run_command(&mut cmd)?;
} }
// Install local tools from the workspace. // Install local tools from the workspace.
let workspace_dir = Path::new(env!("CARGO_WORKSPACE_DIR")); let workspace_dir = Path::new(env!("CARGO_WORKSPACE_DIR"));
// cargo-binstall does not support --path, so we always use cargo install here.
let local_tools = ["mdbook-exerciser", "mdbook-course"]; let local_tools = ["mdbook-exerciser", "mdbook-course"];
for tool in local_tools { for tool in local_tools {
let mut cmd = Command::new(cargo); let mut cmd = Command::new(cargo);