Skip to content

Commit

Permalink
Merge pull request #34 from esp-rs/feature/mod-refactor
Browse files Browse the repository at this point in the history
Feature/mod refactor
  • Loading branch information
SergioGasquez authored Oct 31, 2022
2 parents 0764c0a + cf2e364 commit 37335b4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)?);
}
Expand Down
2 changes: 1 addition & 1 deletion src/toolchain/espidf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/toolchain/gcc_toolchain.rs → src/toolchain/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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!(
Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions src/toolchain/llvm_toolchain.rs → src/toolchain/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/toolchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/toolchain/rust_toolchain.rs → src/toolchain/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -180,7 +180,7 @@ impl RustCrate {

/// Create a crate instance.
pub fn new(name: &str) -> Self {
RustCrate {
Crate {
name: name.to_string(),
}
}
Expand Down

0 comments on commit 37335b4

Please sign in to comment.