Skip to content
66 changes: 62 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Tool for installing and maintaining ESP Rust environment.
"""
keywords = ["esp", "esp-rs", "embedded", "cli", "xtensa", "espidf"]
categories = ["command-line-utilities", "development-tools", "embedded"]
rust-version = "1.62"

[dependencies]
anyhow = "*"
Expand All @@ -29,6 +30,11 @@ env_logger = "0.9.0"
embuild = { version = "0.30.4", features = ["espidf", "git"] }
strum = { version = "0.24", features = ["derive"] }
strum_macros = "0.24.3"
toml = "0.5.9"
directories-next = "2.0.0"
serde = { version = "1.0.146", features = ["derive"] }
miette = "5.3.0"
regex = "1.6.0"

[target.aarch64-unknown-linux-gnu.dependencies]
openssl = { version = "0.10", features = ["vendored"] }
Expand All @@ -39,5 +45,5 @@ bin-dir = "{ bin }{ binary-ext }"
pkg-fmt = "zip"

[profile.release]
lto = "thin"
lto = "thin"
strip = true
61 changes: 61 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use crate::{host_triple::HostTriple, targets::Target, toolchain::rust_toolchain::RustToolchain};
use directories_next::ProjectDirs;
use miette::{ErrReport, IntoDiagnostic, Result, WrapErr};
use serde::{Deserialize, Serialize};
use std::{
collections::HashSet,
fs::{create_dir_all, read, write},
path::PathBuf,
};

/// Deserialized contents of a configuration file
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct Config {
// /// ESP-IDF version
pub espidf_version: Option<String>,
/// Destination of the generated export file.
pub export_file: PathBuf,
/// Extra crates to installed.
pub extra_crates: HashSet<String>,
/// Host triple
pub host_triple: HostTriple,
/// LLVM toolchain path.
pub llvm_path: PathBuf,
/// Nightly Rust toolchain version.
pub nightly_version: String,
/// List of targets instaled.
pub targets: HashSet<Target>,
/// Xtensa Rust toolchain.
pub xtensa_toolchain: RustToolchain,
}

impl Config {
/// Load the config from config file
pub fn load() -> Result<Self> {
let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap();
let file = dirs.config_dir().join("espup.toml");

let config = if let Ok(data) = read(&file) {
toml::from_slice(&data).into_diagnostic()?
} else {
return Err(ErrReport::msg("No config file found"));
};
Ok(config)
}

/// Save the config to file
pub fn save(&self) -> Result<()> {
let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap();
let file = dirs.config_dir().join("espup.toml");

let serialized = toml::to_string(&self.clone())
.into_diagnostic()
.wrap_err("Failed to serialize config")?;
create_dir_all(file.parent().unwrap())
.into_diagnostic()
.wrap_err("Failed to create config directory")?;
write(&file, serialized)
.into_diagnostic()
.wrap_err_with(|| format!("Failed to write config to {}", file.display()))
}
}
6 changes: 4 additions & 2 deletions src/host_triple.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use crate::emoji;
use anyhow::{Context, Result};
use guess_host_triple::guess_host_triple;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use strum::Display;
use strum_macros::EnumString;

#[derive(Display, Debug, Clone, EnumString)]
#[derive(Display, Debug, Clone, EnumString, Deserialize, Serialize, Default)]
pub enum HostTriple {
/// 64-bit Linux
#[strum(serialize = "x86_64-unknown-linux-gnu")]
X86_64UnknownLinuxGnu = 0,
#[default]
X86_64UnknownLinuxGnu,
/// ARM64 Linux
#[strum(serialize = "aarch64-unknown-linux-gnu")]
Aarch64UnknownLinuxGnu,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod config;
pub mod emoji;
pub mod host_triple;
pub mod targets;
Expand Down
Loading