assemble_rust/rustup/
install.rs

1//! Install component or toolchain with rustup
2
3use log::Level;
4
5use assemble_core::exception::BuildException;
6use assemble_core::lazy_evaluation::{Prop, Provider};
7
8use assemble_core::task::initialize_task::InitializeTask;
9use assemble_core::task::up_to_date::UpToDate;
10use assemble_core::{BuildResult, Executable, Project, Task};
11use assemble_core::{CreateTask, TaskIO};
12use assemble_std::ProjectExec;
13
14use crate::toolchain::Toolchain;
15
16/// The toolchain to install
17#[derive(Debug, CreateTask, TaskIO)]
18pub struct InstallToolchain {
19    /// The toolchain to install
20    #[input]
21    pub toolchain: Prop<Toolchain>,
22}
23
24impl UpToDate for InstallToolchain {}
25
26impl InitializeTask for InstallToolchain {}
27
28impl Task for InstallToolchain {
29    fn task_action(task: &mut Executable<Self>, project: &Project) -> BuildResult {
30        let toolchain = task.toolchain.fallible_get()?;
31
32        debug!("attempting to install toolchain {}", toolchain);
33
34        if !project
35            .exec_with(|exec| {
36                exec.exec("rustup")
37                    .arg("install")
38                    .arg("--no-self-update")
39                    .arg(toolchain.to_string())
40                    .stdout(Level::Debug);
41            })?
42            .success()
43        {
44            warn!("bad result gotten");
45            return Err(BuildException::custom("rustup install failed").into());
46        }
47
48        Ok(())
49    }
50}