mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-27 04:40:27 +00:00
Add chip.rs
This commit is contained in:
parent
418407eff2
commit
26f38bab5b
898
Cargo.lock
generated
898
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -33,13 +33,14 @@ winapi = { version = "*", features = [
|
||||
] }
|
||||
zip = "*"
|
||||
xz2 = "0.1.6"
|
||||
espflash = "1.6.0"
|
||||
console = "0.15.1"
|
||||
tempfile = "3.3.0"
|
||||
clap-verbosity-flag = "1.0.1"
|
||||
log = "0.4.17"
|
||||
env_logger = "0.9.0"
|
||||
embuild = "0.30.3"
|
||||
strum = { version = "0.24", features = ["derive"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winreg = "0.10.1"
|
||||
|
31
src/chip.rs
Normal file
31
src/chip.rs
Normal file
@ -0,0 +1,31 @@
|
||||
//! ESP32 chip variants support.
|
||||
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, EnumString)]
|
||||
pub enum Chip {
|
||||
/// Xtensa LX7 based dual core
|
||||
#[strum(serialize = "esp32")]
|
||||
ESP32 = 0,
|
||||
/// Xtensa LX7 based single core
|
||||
#[strum(serialize = "esp32s2")]
|
||||
ESP32S2,
|
||||
/// Xtensa LX7 based single core
|
||||
#[strum(serialize = "esp32s3")]
|
||||
ESP32S3,
|
||||
/// RISC-V based single core
|
||||
#[strum(serialize = "esp32c3")]
|
||||
ESP32C3,
|
||||
}
|
||||
|
||||
impl Chip {
|
||||
/// The name of the gcc toolchain.
|
||||
pub fn gcc_toolchain(&self) -> &'static str {
|
||||
match self {
|
||||
Self::ESP32 => "xtensa-esp32-elf",
|
||||
Self::ESP32S2 => "xtensa-esp32s2-elf",
|
||||
Self::ESP32S3 => "xtensa-esp32s3-elf",
|
||||
Self::ESP32C3 => "riscv32-esp-elf",
|
||||
}
|
||||
}
|
||||
}
|
19
src/main.rs
19
src/main.rs
@ -1,18 +1,19 @@
|
||||
use crate::chip::*;
|
||||
use crate::toolchain::*;
|
||||
use crate::utils::*;
|
||||
use clap::Parser;
|
||||
use espflash::Chip;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
mod emoji;
|
||||
mod toolchain;
|
||||
mod utils;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
||||
use embuild::cmd;
|
||||
use log::{info, warn};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
mod chip;
|
||||
mod emoji;
|
||||
mod toolchain;
|
||||
mod utils;
|
||||
#[derive(Parser)]
|
||||
struct Opts {
|
||||
#[clap(subcommand)]
|
||||
@ -204,7 +205,7 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
let libclang_path = format!("{}/lib", get_tool_path("xtensa-esp32-elf-clang"));
|
||||
exports.push(format!("export LIBCLANG_PATH=\"{}\"", &libclang_path));
|
||||
|
||||
if targets.contains(&Chip::Esp32c3) {
|
||||
if targets.contains(&Chip::ESP32C3) {
|
||||
install_riscv_target(&args.nightly_version)?;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::chip::Chip;
|
||||
use crate::emoji;
|
||||
use crate::utils::*;
|
||||
use anyhow::{bail, Result};
|
||||
use embuild::cmd;
|
||||
use espflash::Chip;
|
||||
use log::{debug, info, warn};
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
@ -125,39 +125,13 @@ pub fn install_extra_crate(crate_name: &str) -> Result<()> {
|
||||
pub fn install_gcc_targets(targets: Vec<Chip>) -> Result<Vec<String>> {
|
||||
let mut exports: Vec<String> = Vec::new();
|
||||
for target in targets {
|
||||
match target {
|
||||
Chip::Esp32 => {
|
||||
install_gcc("xtensa-esp32-elf")?;
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("xtensa-esp32-elf/bin")
|
||||
));
|
||||
}
|
||||
Chip::Esp32s2 => {
|
||||
install_gcc("xtensa-esp32s2-elf")?;
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("xtensa-esp32s2-elf/bin")
|
||||
));
|
||||
}
|
||||
Chip::Esp32s3 => {
|
||||
install_gcc("xtensa-esp32s3-elf")?;
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("xtensa-esp32s3-elf/bin")
|
||||
));
|
||||
}
|
||||
Chip::Esp32c3 => {
|
||||
install_gcc("riscv32-esp-elf")?;
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("riscv32-esp-elf/bin")
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
bail!("{} Unknown target: {:#?}", emoji::ERROR, target)
|
||||
}
|
||||
}
|
||||
let gcc_target = target.gcc_toolchain();
|
||||
install_gcc(gcc_target)?;
|
||||
#[cfg(unix)]
|
||||
exports.push(format!(
|
||||
"export PATH={}/bin:$PATH",
|
||||
get_tool_path(gcc_target)
|
||||
));
|
||||
}
|
||||
Ok(exports)
|
||||
}
|
||||
|
18
src/utils.rs
18
src/utils.rs
@ -1,8 +1,8 @@
|
||||
use crate::chip::Chip;
|
||||
use crate::emoji;
|
||||
use crate::InstallOpts;
|
||||
use anyhow::{bail, Result};
|
||||
use dirs::home_dir;
|
||||
use espflash::Chip;
|
||||
use flate2::bufread::GzDecoder;
|
||||
use log::{debug, info};
|
||||
use std::env;
|
||||
@ -18,10 +18,10 @@ pub fn parse_targets(build_target: &str) -> Result<Vec<Chip>, String> {
|
||||
debug!("{} Parsing targets: {}", emoji::DEBUG, build_target);
|
||||
let mut chips: Vec<Chip> = Vec::new();
|
||||
if build_target.contains("all") {
|
||||
chips.push(Chip::Esp32);
|
||||
chips.push(Chip::Esp32s2);
|
||||
chips.push(Chip::Esp32s3);
|
||||
chips.push(Chip::Esp32c3);
|
||||
chips.push(Chip::ESP32);
|
||||
chips.push(Chip::ESP32S2);
|
||||
chips.push(Chip::ESP32S3);
|
||||
chips.push(Chip::ESP32C3);
|
||||
return Ok(chips);
|
||||
}
|
||||
let targets: Vec<&str> = if build_target.contains(' ') || build_target.contains(',') {
|
||||
@ -31,10 +31,10 @@ pub fn parse_targets(build_target: &str) -> Result<Vec<Chip>, String> {
|
||||
};
|
||||
for target in targets {
|
||||
match target {
|
||||
"esp32" => chips.push(Chip::Esp32),
|
||||
"esp32s2" => chips.push(Chip::Esp32s2),
|
||||
"esp32s3" => chips.push(Chip::Esp32s3),
|
||||
"esp32c3" => chips.push(Chip::Esp32c3),
|
||||
"esp32" => chips.push(Chip::ESP32),
|
||||
"esp32s2" => chips.push(Chip::ESP32S2),
|
||||
"esp32s3" => chips.push(Chip::ESP32S3),
|
||||
"esp32c3" => chips.push(Chip::ESP32C3),
|
||||
_ => {
|
||||
return Err(format!("Unknown target: {}", target));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user