mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-29 22:01:07 +00:00
refactor: ♻️ Use struct to store RiscV Target info so we can impl Installaable for it
This commit is contained in:
parent
d63b549540
commit
2ae93f843b
14
src/main.rs
14
src/main.rs
@ -17,10 +17,7 @@ use espup::{
|
||||
},
|
||||
gcc::{get_toolchain_name, install_gcc_targets},
|
||||
llvm::Llvm,
|
||||
rust::{
|
||||
check_rust_installation, install_riscv_target, uninstall_riscv_target, Crate,
|
||||
XtensaRust,
|
||||
},
|
||||
rust::{check_rust_installation, uninstall_riscv_target, Crate, RiscVTarget, XtensaRust},
|
||||
Installable,
|
||||
},
|
||||
update::check_for_update,
|
||||
@ -195,10 +192,11 @@ async fn install(args: InstallOpts) -> Result<()> {
|
||||
to_install.push(Box::new(xtensa_rust.to_owned()));
|
||||
}
|
||||
|
||||
exports.extend(llvm.install()?);
|
||||
|
||||
if targets.contains(&Target::ESP32C3) || targets.contains(&Target::ESP32C2) {
|
||||
install_riscv_target(&args.nightly_version)?;
|
||||
if targets.contains(&Target::ESP32C3) {
|
||||
let riscv_target = RiscVTarget {
|
||||
nightly_version: args.nightly_version.clone(),
|
||||
};
|
||||
to_install.push(Box::new(riscv_target));
|
||||
}
|
||||
|
||||
if let Some(esp_idf_version) = &args.esp_idf_version {
|
||||
|
@ -248,6 +248,47 @@ impl Installable for Crate {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RiscVTarget {
|
||||
/// Nightly version.
|
||||
pub nightly_version: String,
|
||||
}
|
||||
|
||||
impl RiscVTarget {
|
||||
/// Create a crate instance.
|
||||
pub fn new(nightly_version: &str) -> Self {
|
||||
RiscVTarget {
|
||||
nightly_version: nightly_version.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Installable for RiscVTarget {
|
||||
async fn install(&self) -> Result<Vec<String>, Error> {
|
||||
info!("{} Installing RiscV target", emoji::WRENCH);
|
||||
cmd!(
|
||||
"rustup",
|
||||
"component",
|
||||
"add",
|
||||
"rust-src",
|
||||
"--toolchain",
|
||||
&self.nightly_version
|
||||
)
|
||||
.run()?;
|
||||
cmd!(
|
||||
"rustup",
|
||||
"target",
|
||||
"add",
|
||||
"--toolchain",
|
||||
&self.nightly_version,
|
||||
"riscv32imac-unknown-none-elf"
|
||||
)
|
||||
.run()?;
|
||||
|
||||
Ok(vec![]) // No exports
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the artifact extension based on the host architecture.
|
||||
fn get_artifact_extension(host_triple: &HostTriple) -> &str {
|
||||
match host_triple {
|
||||
@ -370,33 +411,6 @@ async fn install_rustup(nightly_version: &str, host_triple: &HostTriple) -> Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Installs the RISC-V target.
|
||||
pub fn install_riscv_target(nightly_version: &str) -> Result<()> {
|
||||
info!("{} Installing RISC-V target", emoji::WRENCH);
|
||||
cmd!(
|
||||
"rustup",
|
||||
"component",
|
||||
"add",
|
||||
"rust-src",
|
||||
"--toolchain",
|
||||
nightly_version
|
||||
)
|
||||
.run()
|
||||
.into_diagnostic()?;
|
||||
cmd!(
|
||||
"rustup",
|
||||
"target",
|
||||
"add",
|
||||
"--toolchain",
|
||||
nightly_version,
|
||||
"riscv32imc-unknown-none-elf",
|
||||
"riscv32imac-unknown-none-elf"
|
||||
)
|
||||
.run()
|
||||
.into_diagnostic()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Installs the desired version of the nightly toolchain.
|
||||
fn install_rust_nightly(version: &str) -> Result<()> {
|
||||
info!("{} Installing {} toolchain", emoji::WRENCH, version);
|
||||
|
Loading…
x
Reference in New Issue
Block a user