Merge pull request #34 from esp-rs/feature/mod-refactor

Feature/mod refactor
This commit is contained in:
Sergio Gasquez Arcos 2022-10-31 11:05:59 +01:00 committed by GitHub
commit 37335b4371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 20 deletions

View File

@ -1,4 +1,4 @@
use crate::{host_triple::HostTriple, targets::Target, toolchain::rust_toolchain::XtensaRust};
use crate::{host_triple::HostTriple, targets::Target, toolchain::rust::XtensaRust};
use directories_next::ProjectDirs;
use miette::{ErrReport, IntoDiagnostic, Result, WrapErr};
use serde::{Deserialize, Serialize};

View File

@ -15,9 +15,9 @@ use espup::{
espidf::{
get_dist_path, get_install_path, get_tool_path, EspIdfRepo, DEFAULT_GIT_REPOSITORY,
},
gcc_toolchain::{get_toolchain_name, install_gcc_targets},
llvm_toolchain::LlvmToolchain,
rust_toolchain::{check_rust_installation, install_riscv_target, RustCrate, XtensaRust},
gcc::{get_toolchain_name, install_gcc_targets},
llvm::Llvm,
rust::{check_rust_installation, install_riscv_target, Crate, XtensaRust},
},
};
use log::{debug, info, warn};
@ -145,8 +145,7 @@ fn install(args: InstallOpts) -> Result<()> {
info!("{} Installing esp-rs", emoji::DISC);
let targets: HashSet<Target> = parse_targets(&args.targets).unwrap();
let host_triple = get_host_triple(args.default_host)?;
let mut extra_crates: HashSet<RustCrate> =
args.extra_crates.split(',').map(RustCrate::new).collect();
let mut extra_crates: HashSet<Crate> = args.extra_crates.split(',').map(Crate::new).collect();
let mut exports: Vec<String> = Vec::new();
let export_file = args.export_file.clone();
let xtensa_rust = if targets.contains(&Target::ESP32)
@ -157,7 +156,7 @@ fn install(args: InstallOpts) -> Result<()> {
} else {
None
};
let llvm = LlvmToolchain::new(args.llvm_version, args.profile_minimal, &host_triple);
let llvm = Llvm::new(args.llvm_version, args.profile_minimal, &host_triple);
debug!(
"{} Arguments:
@ -202,7 +201,7 @@ fn install(args: InstallOpts) -> Result<()> {
if let Some(espidf_version) = &args.espidf_version {
let repo = EspIdfRepo::new(espidf_version, args.profile_minimal, &targets);
exports.extend(repo.install()?);
extra_crates.insert(RustCrate::new("ldproxy"));
extra_crates.insert(Crate::new("ldproxy"));
} else {
exports.extend(install_gcc_targets(&targets, &host_triple)?);
}

View File

@ -4,7 +4,7 @@ use crate::{
emoji,
targets::Target,
toolchain::{
gcc_toolchain::{get_toolchain_name, get_ulp_toolchain_name},
gcc::{get_toolchain_name, get_ulp_toolchain_name},
get_home_dir,
},
};

View File

@ -19,7 +19,7 @@ const DEFAULT_GCC_RELEASE: &str = "esp-2021r2-patch5";
const DEFAULT_GCC_VERSION: &str = "8_4_0";
#[derive(Debug, Clone)]
pub struct GccToolchain {
pub struct Gcc {
/// Host triple.
pub host_triple: HostTriple,
/// Repository release version to use.
@ -32,7 +32,7 @@ pub struct GccToolchain {
pub version: String,
}
impl GccToolchain {
impl Gcc {
/// Gets the binary path.
pub fn get_bin_path(&self) -> String {
let toolchain_path = format!(
@ -144,7 +144,7 @@ pub fn install_gcc_targets(
info!("{} Installing gcc for build targets", emoji::WRENCH);
let mut exports: Vec<String> = Vec::new();
for target in targets {
let gcc = GccToolchain::new(target, host_triple);
let gcc = Gcc::new(target, host_triple);
gcc.install()?;
#[cfg(windows)]

View File

@ -13,7 +13,7 @@ const DEFAULT_LLVM_REPOSITORY: &str = "https://github.com/espressif/llvm-project
const DEFAULT_LLVM_15_VERSION: &str = "esp-15.0.0-20221014";
#[derive(Debug, Clone, Default)]
pub struct LlvmToolchain {
pub struct Llvm {
/// LLVM Toolchain file name.
pub file_name: String,
/// Host triple.
@ -26,7 +26,7 @@ pub struct LlvmToolchain {
pub version: String,
}
impl LlvmToolchain {
impl Llvm {
/// Gets the name of the LLVM arch based on the host triple.
fn get_arch(host_triple: &HostTriple) -> Result<&str> {
match host_triple {

View File

@ -12,9 +12,9 @@ use tar::Archive;
use xz2::read::XzDecoder;
pub mod espidf;
pub mod gcc_toolchain;
pub mod llvm_toolchain;
pub mod rust_toolchain;
pub mod gcc;
pub mod llvm;
pub mod rust;
/// Returns the path to the home directory.
pub fn get_home_dir() -> String {

View File

@ -157,12 +157,12 @@ impl XtensaRust {
}
#[derive(Hash, Eq, PartialEq, Debug, Clone, Serialize, Deserialize, Default)]
pub struct RustCrate {
pub struct Crate {
/// Crate name.
pub name: String,
}
impl RustCrate {
impl Crate {
/// Installs a crate.
pub fn install(&self) -> Result<()> {
#[cfg(unix)]
@ -180,7 +180,7 @@ impl RustCrate {
/// Create a crate instance.
pub fn new(name: &str) -> Self {
RustCrate {
Crate {
name: name.to_string(),
}
}