mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-03 07:34:57 +00:00
Rework update subcommand (#285)
* feat: ✨ Refactor update and install subcomands * feat: ✨ Refactor update and install subcomands * Create issue_handler.yml * build(deps): bump serde_json from 1.0.96 to 1.0.99 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.96 to 1.0.99. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.96...v1.0.99) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump clap from 4.3.3 to 4.3.8 Bumps [clap](https://github.com/clap-rs/clap) from 4.3.3 to 4.3.8. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.3.3...v4.3.8) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump openssl from 0.10.54 to 0.10.55 Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.54 to 0.10.55. - [Release notes](https://github.com/sfackler/rust-openssl/releases) - [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.54...openssl-v0.10.55) --- updated-dependencies: - dependency-name: openssl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump strum from 0.24.1 to 0.25.0 Bumps [strum](https://github.com/Peternator7/strum) from 0.24.1 to 0.25.0. - [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md) - [Commits](https://github.com/Peternator7/strum/commits) --- updated-dependencies: - dependency-name: strum dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update readme (#289) * docs: 📝 Update readme * docs: Udpate readme * build(deps): bump tokio from 1.28.2 to 1.29.1 (#290) Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.28.2 to 1.29.1. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.28.2...tokio-1.29.1) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump async-trait from 0.1.68 to 0.1.69 (#291) Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.68 to 0.1.69. - [Release notes](https://github.com/dtolnay/async-trait/releases) - [Commits](https://github.com/dtolnay/async-trait/compare/0.1.68...0.1.69) --- updated-dependencies: - dependency-name: async-trait dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump update-informer from 1.0.0 to 1.1.0 (#292) Bumps [update-informer](https://github.com/mgrachev/update-informer) from 1.0.0 to 1.1.0. - [Release notes](https://github.com/mgrachev/update-informer/releases) - [Changelog](https://github.com/mgrachev/update-informer/blob/main/CHANGELOG.md) - [Commits](https://github.com/mgrachev/update-informer/compare/v1.0.0...v1.1.0) --- updated-dependencies: - dependency-name: update-informer dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump clap from 4.3.8 to 4.3.10 (#293) Bumps [clap](https://github.com/clap-rs/clap) from 4.3.8 to 4.3.10. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.3.8...v4.3.10) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump clap from 4.3.10 to 4.3.11 Bumps [clap](https://github.com/clap-rs/clap) from 4.3.10 to 4.3.11. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.3.10...v4.3.11) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump serde_json from 1.0.99 to 1.0.100 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.99 to 1.0.100. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.99...v1.0.100) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump async-trait from 0.1.69 to 0.1.71 Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.69 to 0.1.71. - [Release notes](https://github.com/dtolnay/async-trait/releases) - [Commits](https://github.com/dtolnay/async-trait/compare/0.1.69...0.1.71) --- updated-dependencies: - dependency-name: async-trait dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump clap_complete from 4.3.1 to 4.3.2 Bumps [clap_complete](https://github.com/clap-rs/clap) from 4.3.1 to 4.3.2. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.3.1...clap_complete-v4.3.2) --- updated-dependencies: - dependency-name: clap_complete dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump regex from 1.8.4 to 1.9.1 Bumps [regex](https://github.com/rust-lang/regex) from 1.8.4 to 1.9.1. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.8.4...1.9.1) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump thiserror from 1.0.40 to 1.0.43 Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.40 to 1.0.43. - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](https://github.com/dtolnay/thiserror/compare/1.0.40...1.0.43) --- updated-dependencies: - dependency-name: thiserror dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump tar from 0.4.38 to 0.4.39 Bumps [tar](https://github.com/alexcrichton/tar-rs) from 0.4.38 to 0.4.39. - [Commits](https://github.com/alexcrichton/tar-rs/compare/0.4.38...0.4.39) --- updated-dependencies: - dependency-name: tar dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump miette from 5.9.0 to 5.10.0 Bumps [miette](https://github.com/zkat/miette) from 5.9.0 to 5.10.0. - [Release notes](https://github.com/zkat/miette/releases) - [Changelog](https://github.com/zkat/miette/blob/main/CHANGELOG.md) - [Commits](https://github.com/zkat/miette/compare/miette-derive-v5.9.0...miette-derive-v5.10.0) --- updated-dependencies: - dependency-name: miette dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump serde_json from 1.0.100 to 1.0.103 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.100 to 1.0.103. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.100...v1.0.103) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump assert_cmd from 2.0.11 to 2.0.12 Bumps [assert_cmd](https://github.com/assert-rs/assert_cmd) from 2.0.11 to 2.0.12. - [Changelog](https://github.com/assert-rs/assert_cmd/blob/master/CHANGELOG.md) - [Commits](https://github.com/assert-rs/assert_cmd/compare/v2.0.11...v2.0.12) --- updated-dependencies: - dependency-name: assert_cmd dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump clap from 4.3.11 to 4.3.14 Bumps [clap](https://github.com/clap-rs/clap) from 4.3.11 to 4.3.14. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.3.11...v4.3.14) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump clap from 4.3.14 to 4.3.19 Bumps [clap](https://github.com/clap-rs/clap) from 4.3.14 to 4.3.19. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.3.14...v4.3.19) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump thiserror from 1.0.43 to 1.0.44 Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.43 to 1.0.44. - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](https://github.com/dtolnay/thiserror/compare/1.0.43...1.0.44) --- updated-dependencies: - dependency-name: thiserror dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump async-trait from 0.1.71 to 0.1.72 Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.71 to 0.1.72. - [Release notes](https://github.com/dtolnay/async-trait/releases) - [Commits](https://github.com/dtolnay/async-trait/compare/0.1.71...0.1.72) --- updated-dependencies: - dependency-name: async-trait dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump tempfile from 3.6.0 to 3.7.0 Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.6.0 to 3.7.0. - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](https://github.com/Stebalien/tempfile/compare/v3.6.0...v3.7.0) --- updated-dependencies: - dependency-name: tempfile dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump serde_json from 1.0.103 to 1.0.104 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.103 to 1.0.104. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.103...v1.0.104) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Ignore shebang of install.sh files (#312) * fix: Remove -c argument * feat: Split arguments and add checking result * build(deps): bump tar from 0.4.39 to 0.4.40 Bumps [tar](https://github.com/alexcrichton/tar-rs) from 0.4.39 to 0.4.40. - [Commits](https://github.com/alexcrichton/tar-rs/compare/0.4.39...0.4.40) --- updated-dependencies: - dependency-name: tar dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump openssl from 0.10.55 to 0.10.56 Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.55 to 0.10.56. - [Release notes](https://github.com/sfackler/rust-openssl/releases) - [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.55...openssl-v0.10.56) --- updated-dependencies: - dependency-name: openssl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump regex from 1.9.1 to 1.9.3 Bumps [regex](https://github.com/rust-lang/regex) from 1.9.1 to 1.9.3. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.9.1...1.9.3) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump tempfile from 3.7.0 to 3.7.1 Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.7.0 to 3.7.1. - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](https://github.com/Stebalien/tempfile/compare/v3.7.0...v3.7.1) --- updated-dependencies: - dependency-name: tempfile dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
a865da6478
commit
0a64e7813c
61
src/cli.rs
Normal file
61
src/cli.rs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
use crate::{
|
||||||
|
targets::{parse_targets, Target},
|
||||||
|
toolchain::rust::XtensaRust,
|
||||||
|
};
|
||||||
|
use clap::Parser;
|
||||||
|
use clap_complete::Shell;
|
||||||
|
use std::{collections::HashSet, path::PathBuf};
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct CompletionsOpts {
|
||||||
|
/// Verbosity level of the logs.
|
||||||
|
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
||||||
|
pub log_level: String,
|
||||||
|
/// Shell to generate completions for.
|
||||||
|
pub shell: Shell,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct InstallOpts {
|
||||||
|
/// Target triple of the host.
|
||||||
|
#[arg(short = 'd', long, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])]
|
||||||
|
pub default_host: Option<String>,
|
||||||
|
/// Relative or full path for the export file that will be generated. If no path is provided, the file will be generated under home directory (https://docs.rs/dirs/latest/dirs/fn.home_dir.html).
|
||||||
|
#[arg(short = 'f', long)]
|
||||||
|
pub export_file: Option<PathBuf>,
|
||||||
|
/// Extends the LLVM installation.
|
||||||
|
///
|
||||||
|
/// This will install the whole LLVM instead of only installing the libs.
|
||||||
|
#[arg(short = 'e', long)]
|
||||||
|
pub extended_llvm: bool,
|
||||||
|
/// Verbosity level of the logs.
|
||||||
|
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
||||||
|
pub log_level: String,
|
||||||
|
/// Xtensa Rust toolchain name.
|
||||||
|
#[arg(short = 'a', long, default_value = "esp")]
|
||||||
|
pub name: String,
|
||||||
|
/// Nightly Rust toolchain version.
|
||||||
|
#[arg(short = 'n', long, default_value = "nightly")]
|
||||||
|
pub nightly_version: String,
|
||||||
|
/// Only install toolchains required for STD applications.
|
||||||
|
///
|
||||||
|
/// With this option, espup will skip GCC installation (it will be handled by esp-idf-sys), hence you won't be able to build no_std applications.
|
||||||
|
#[arg(short = 's', long)]
|
||||||
|
pub std: bool,
|
||||||
|
/// Comma or space separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all].
|
||||||
|
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
|
||||||
|
pub targets: HashSet<Target>,
|
||||||
|
/// Xtensa Rust toolchain version.
|
||||||
|
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
|
||||||
|
pub toolchain_version: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct UninstallOpts {
|
||||||
|
/// Verbosity level of the logs.
|
||||||
|
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
||||||
|
pub log_level: String,
|
||||||
|
/// Xtensa Rust toolchain name.
|
||||||
|
#[arg(short = 'a', long, default_value = "esp")]
|
||||||
|
pub name: String,
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
pub mod cli;
|
||||||
pub mod emoji;
|
pub mod emoji;
|
||||||
pub mod env;
|
pub mod env;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
233
src/main.rs
233
src/main.rs
@ -1,27 +1,20 @@
|
|||||||
use clap::{CommandFactory, Parser};
|
use clap::{CommandFactory, Parser};
|
||||||
use clap_complete::Shell;
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use espup::env::set_environment_variable;
|
use espup::env::set_environment_variable;
|
||||||
use espup::{
|
use espup::{
|
||||||
|
cli::{CompletionsOpts, InstallOpts, UninstallOpts},
|
||||||
emoji,
|
emoji,
|
||||||
env::{create_export_file, export_environment, get_export_file},
|
|
||||||
error::Error,
|
error::Error,
|
||||||
host_triple::get_host_triple,
|
|
||||||
logging::initialize_logger,
|
logging::initialize_logger,
|
||||||
targets::{parse_targets, Target},
|
|
||||||
toolchain::{
|
toolchain::{
|
||||||
gcc::{uninstall_gcc_toolchains, Gcc},
|
gcc::uninstall_gcc_toolchains, install as toolchain_install, llvm::Llvm,
|
||||||
llvm::Llvm,
|
rust::get_rustup_home,
|
||||||
rust::{check_rust_installation, get_rustup_home, RiscVTarget, XtensaRust},
|
|
||||||
Installable,
|
|
||||||
},
|
},
|
||||||
update::check_for_update,
|
update::check_for_update,
|
||||||
};
|
};
|
||||||
use log::{debug, info, warn};
|
use log::info;
|
||||||
use miette::Result;
|
use miette::Result;
|
||||||
use std::{collections::HashSet, env, fs::remove_dir_all, path::PathBuf};
|
use std::{env, fs::remove_dir_all};
|
||||||
use tokio::sync::mpsc;
|
|
||||||
use tokio_retry::{strategy::FixedInterval, Retry};
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(about, version)]
|
#[command(about, version)]
|
||||||
@ -40,77 +33,7 @@ pub enum SubCommand {
|
|||||||
/// Uninstalls Espressif Rust ecosystem.
|
/// Uninstalls Espressif Rust ecosystem.
|
||||||
Uninstall(UninstallOpts),
|
Uninstall(UninstallOpts),
|
||||||
/// Updates Xtensa Rust toolchain.
|
/// Updates Xtensa Rust toolchain.
|
||||||
Update(UpdateOpts),
|
Update(Box<InstallOpts>),
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct CompletionsOpts {
|
|
||||||
/// Verbosity level of the logs.
|
|
||||||
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
|
||||||
pub log_level: String,
|
|
||||||
/// Shell to generate completions for.
|
|
||||||
pub shell: Shell,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct InstallOpts {
|
|
||||||
/// Target triple of the host.
|
|
||||||
#[arg(short = 'd', long, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])]
|
|
||||||
pub default_host: Option<String>,
|
|
||||||
/// Relative or full path for the export file that will be generated. If no path is provided, the file will be generated under home directory (https://docs.rs/dirs/latest/dirs/fn.home_dir.html).
|
|
||||||
#[arg(short = 'f', long)]
|
|
||||||
pub export_file: Option<PathBuf>,
|
|
||||||
/// Extends the LLVM installation.
|
|
||||||
///
|
|
||||||
/// This will install the whole LLVM instead of only installing the libs.
|
|
||||||
#[arg(short = 'e', long)]
|
|
||||||
pub extended_llvm: bool,
|
|
||||||
/// Verbosity level of the logs.
|
|
||||||
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
|
||||||
pub log_level: String,
|
|
||||||
/// Xtensa Rust toolchain name.
|
|
||||||
#[arg(short = 'a', long, default_value = "esp")]
|
|
||||||
pub name: String,
|
|
||||||
/// Nightly Rust toolchain version.
|
|
||||||
#[arg(short = 'n', long, default_value = "nightly")]
|
|
||||||
pub nightly_version: String,
|
|
||||||
/// Only install toolchains required for STD applications.
|
|
||||||
///
|
|
||||||
/// With this option, espup will skip GCC installation (it will be handled by esp-idf-sys), hence you won't be able to build no_std applications.
|
|
||||||
#[arg(short = 's', long)]
|
|
||||||
pub std: bool,
|
|
||||||
/// Comma or space separated list of targets [esp32,esp32c2,esp32c3,esp32c6,esp32h2,esp32s2,esp32s3,all].
|
|
||||||
#[arg(short = 't', long, default_value = "all", value_parser = parse_targets)]
|
|
||||||
pub targets: HashSet<Target>,
|
|
||||||
/// Xtensa Rust toolchain version.
|
|
||||||
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
|
|
||||||
pub toolchain_version: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct UpdateOpts {
|
|
||||||
/// Target triple of the host.
|
|
||||||
#[arg(short = 'd', long, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])]
|
|
||||||
pub default_host: Option<String>,
|
|
||||||
/// Verbosity level of the logs.
|
|
||||||
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
|
||||||
pub log_level: String,
|
|
||||||
/// Xtensa Rust toolchain name.
|
|
||||||
#[arg(short = 'a', long, default_value = "esp")]
|
|
||||||
pub name: String,
|
|
||||||
/// Xtensa Rust toolchain version.
|
|
||||||
#[arg(short = 'v', long, value_parser = XtensaRust::parse_version)]
|
|
||||||
pub toolchain_version: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct UninstallOpts {
|
|
||||||
/// Verbosity level of the logs.
|
|
||||||
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
|
||||||
pub log_level: String,
|
|
||||||
/// Xtensa Rust toolchain name.
|
|
||||||
#[arg(short = 'a', long, default_value = "esp")]
|
|
||||||
pub name: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates Xtensa Rust toolchain.
|
/// Updates Xtensa Rust toolchain.
|
||||||
@ -142,122 +65,8 @@ async fn install(args: InstallOpts) -> Result<()> {
|
|||||||
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
info!("{} Installing the Espressif Rust ecosystem", emoji::DISC);
|
info!("{} Installing the Espressif Rust ecosystem", emoji::DISC);
|
||||||
|
toolchain_install(args).await?;
|
||||||
let export_file = get_export_file(args.export_file)?;
|
|
||||||
let mut exports: Vec<String> = Vec::new();
|
|
||||||
let host_triple = get_host_triple(args.default_host)?;
|
|
||||||
let xtensa_rust_version = if let Some(toolchain_version) = &args.toolchain_version {
|
|
||||||
toolchain_version.clone()
|
|
||||||
} else {
|
|
||||||
XtensaRust::get_latest_version().await?
|
|
||||||
};
|
|
||||||
let install_path = get_rustup_home().join("toolchains").join(args.name);
|
|
||||||
let llvm: Llvm = Llvm::new(
|
|
||||||
&install_path,
|
|
||||||
&host_triple,
|
|
||||||
args.extended_llvm,
|
|
||||||
&xtensa_rust_version,
|
|
||||||
)?;
|
|
||||||
let targets = args.targets;
|
|
||||||
let xtensa_rust = if targets.contains(&Target::ESP32)
|
|
||||||
|| targets.contains(&Target::ESP32S2)
|
|
||||||
|| targets.contains(&Target::ESP32S3)
|
|
||||||
{
|
|
||||||
Some(XtensaRust::new(
|
|
||||||
&xtensa_rust_version,
|
|
||||||
&host_triple,
|
|
||||||
&install_path,
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"{} Arguments:
|
|
||||||
- Export file: {:?}
|
|
||||||
- Host triple: {}
|
|
||||||
- LLVM Toolchain: {:?}
|
|
||||||
- Nightly version: {:?}
|
|
||||||
- Rust Toolchain: {:?}
|
|
||||||
- Targets: {:?}
|
|
||||||
- Toolchain path: {:?}
|
|
||||||
- Toolchain version: {:?}",
|
|
||||||
emoji::INFO,
|
|
||||||
&export_file,
|
|
||||||
host_triple,
|
|
||||||
&llvm,
|
|
||||||
&args.nightly_version,
|
|
||||||
xtensa_rust,
|
|
||||||
targets,
|
|
||||||
&install_path,
|
|
||||||
args.toolchain_version,
|
|
||||||
);
|
|
||||||
|
|
||||||
check_rust_installation().await?;
|
|
||||||
|
|
||||||
// Build up a vector of installable applications, all of which implement the
|
|
||||||
// `Installable` async trait.
|
|
||||||
let mut to_install = Vec::<Box<dyn Installable + Send + Sync>>::new();
|
|
||||||
|
|
||||||
if let Some(ref xtensa_rust) = xtensa_rust {
|
|
||||||
to_install.push(Box::new(xtensa_rust.to_owned()));
|
|
||||||
}
|
|
||||||
|
|
||||||
to_install.push(Box::new(llvm));
|
|
||||||
|
|
||||||
if targets.iter().any(|t| t.is_riscv()) {
|
|
||||||
let riscv_target = RiscVTarget::new(&args.nightly_version);
|
|
||||||
to_install.push(Box::new(riscv_target));
|
|
||||||
}
|
|
||||||
|
|
||||||
if !args.std {
|
|
||||||
targets.iter().for_each(|target| {
|
|
||||||
if target.is_xtensa() {
|
|
||||||
let gcc = Gcc::new(target, &host_triple, &install_path);
|
|
||||||
to_install.push(Box::new(gcc));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// All RISC-V targets use the same GCC toolchain
|
|
||||||
// ESP32S2 and ESP32S3 also install the RISC-V toolchain for their ULP coprocessor
|
|
||||||
if targets.iter().any(|t| t != &Target::ESP32) {
|
|
||||||
let riscv_gcc = Gcc::new_riscv(&host_triple, &install_path);
|
|
||||||
to_install.push(Box::new(riscv_gcc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// With a list of applications to install, install them all in parallel.
|
|
||||||
let installable_items = to_install.len();
|
|
||||||
let (tx, mut rx) = mpsc::channel::<Result<Vec<String>, Error>>(installable_items);
|
|
||||||
for app in to_install {
|
|
||||||
let tx = tx.clone();
|
|
||||||
let retry_strategy = FixedInterval::from_millis(50).take(3);
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let res = Retry::spawn(retry_strategy, || async {
|
|
||||||
let res = app.install().await;
|
|
||||||
if res.is_err() {
|
|
||||||
warn!(
|
|
||||||
"{} Installation for '{}' failed, retrying",
|
|
||||||
emoji::WARN,
|
|
||||||
app.name()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
res
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
tx.send(res).await.unwrap();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the results of the install tasks as they complete.
|
|
||||||
for _ in 0..installable_items {
|
|
||||||
let names = rx.recv().await.unwrap()?;
|
|
||||||
exports.extend(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
create_export_file(&export_file, &exports)?;
|
|
||||||
|
|
||||||
info!("{} Installation successfully completed!", emoji::CHECK);
|
info!("{} Installation successfully completed!", emoji::CHECK);
|
||||||
export_environment(&export_file)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,34 +99,12 @@ async fn uninstall(args: UninstallOpts) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Updates Xtensa Rust toolchain.
|
/// Updates Xtensa Rust toolchain.
|
||||||
async fn update(args: UpdateOpts) -> Result<()> {
|
async fn update(args: InstallOpts) -> Result<()> {
|
||||||
initialize_logger(&args.log_level);
|
initialize_logger(&args.log_level);
|
||||||
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
info!("{} Updating Espressif Rust ecosystem", emoji::DISC);
|
info!("{} Updating Espressif Rust ecosystem", emoji::DISC);
|
||||||
|
toolchain_install(args).await?;
|
||||||
let host_triple = get_host_triple(args.default_host)?;
|
|
||||||
let install_path = get_rustup_home().join("toolchains").join(args.name);
|
|
||||||
let xtensa_rust: XtensaRust = if let Some(toolchain_version) = args.toolchain_version {
|
|
||||||
XtensaRust::new(&toolchain_version, &host_triple, &install_path)
|
|
||||||
} else {
|
|
||||||
let latest_version = XtensaRust::get_latest_version().await?;
|
|
||||||
XtensaRust::new(&latest_version, &host_triple, &install_path)
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"{} Arguments:
|
|
||||||
- Host triple: {}
|
|
||||||
- Install path: {:#?}
|
|
||||||
- Toolchain version: {:#?}",
|
|
||||||
emoji::INFO,
|
|
||||||
host_triple,
|
|
||||||
install_path,
|
|
||||||
xtensa_rust,
|
|
||||||
);
|
|
||||||
|
|
||||||
xtensa_rust.install().await?;
|
|
||||||
|
|
||||||
info!("{} Update successfully completed!", emoji::CHECK);
|
info!("{} Update successfully completed!", emoji::CHECK);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -327,7 +114,7 @@ async fn main() -> Result<()> {
|
|||||||
match Cli::parse().subcommand {
|
match Cli::parse().subcommand {
|
||||||
SubCommand::Completions(args) => completions(args).await,
|
SubCommand::Completions(args) => completions(args).await,
|
||||||
SubCommand::Install(args) => install(*args).await,
|
SubCommand::Install(args) => install(*args).await,
|
||||||
SubCommand::Update(args) => update(args).await,
|
SubCommand::Update(args) => update(*args).await,
|
||||||
SubCommand::Uninstall(args) => uninstall(args).await,
|
SubCommand::Uninstall(args) => uninstall(args).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
//! Different toolchains source and installation tools.
|
//! Different toolchains source and installation tools.
|
||||||
|
|
||||||
use crate::{emoji, error::Error};
|
use crate::{
|
||||||
|
cli::InstallOpts,
|
||||||
|
emoji,
|
||||||
|
env::{create_export_file, export_environment, get_export_file},
|
||||||
|
error::Error,
|
||||||
|
host_triple::get_host_triple,
|
||||||
|
targets::Target,
|
||||||
|
toolchain::{
|
||||||
|
gcc::Gcc,
|
||||||
|
llvm::Llvm,
|
||||||
|
rust::{check_rust_installation, get_rustup_home, RiscVTarget, XtensaRust},
|
||||||
|
},
|
||||||
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use flate2::bufread::GzDecoder;
|
use flate2::bufread::GzDecoder;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
@ -14,6 +26,8 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
use tokio_retry::{strategy::FixedInterval, Retry};
|
||||||
use xz2::read::XzDecoder;
|
use xz2::read::XzDecoder;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
@ -128,6 +142,124 @@ pub async fn download_file(
|
|||||||
Ok(format!("{output_directory}/{file_name}"))
|
Ok(format!("{output_directory}/{file_name}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Installs or updates the Espressif Rust ecosystem.
|
||||||
|
pub async fn install(args: InstallOpts) -> Result<()> {
|
||||||
|
let export_file = get_export_file(args.export_file)?;
|
||||||
|
let mut exports: Vec<String> = Vec::new();
|
||||||
|
let host_triple = get_host_triple(args.default_host)?;
|
||||||
|
let xtensa_rust_version = if let Some(toolchain_version) = &args.toolchain_version {
|
||||||
|
toolchain_version.clone()
|
||||||
|
} else {
|
||||||
|
XtensaRust::get_latest_version().await?
|
||||||
|
};
|
||||||
|
let install_path = get_rustup_home().join("toolchains").join(args.name);
|
||||||
|
let llvm: Llvm = Llvm::new(
|
||||||
|
&install_path,
|
||||||
|
&host_triple,
|
||||||
|
args.extended_llvm,
|
||||||
|
&xtensa_rust_version,
|
||||||
|
)?;
|
||||||
|
let targets = args.targets;
|
||||||
|
let xtensa_rust = if targets.contains(&Target::ESP32)
|
||||||
|
|| targets.contains(&Target::ESP32S2)
|
||||||
|
|| targets.contains(&Target::ESP32S3)
|
||||||
|
{
|
||||||
|
Some(XtensaRust::new(
|
||||||
|
&xtensa_rust_version,
|
||||||
|
&host_triple,
|
||||||
|
&install_path,
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"{} Arguments:
|
||||||
|
- Export file: {:?}
|
||||||
|
- Host triple: {}
|
||||||
|
- LLVM Toolchain: {:?}
|
||||||
|
- Nightly version: {:?}
|
||||||
|
- Rust Toolchain: {:?}
|
||||||
|
- Targets: {:?}
|
||||||
|
- Toolchain path: {:?}
|
||||||
|
- Toolchain version: {:?}",
|
||||||
|
emoji::INFO,
|
||||||
|
&export_file,
|
||||||
|
host_triple,
|
||||||
|
&llvm,
|
||||||
|
&args.nightly_version,
|
||||||
|
xtensa_rust,
|
||||||
|
targets,
|
||||||
|
&install_path,
|
||||||
|
args.toolchain_version,
|
||||||
|
);
|
||||||
|
|
||||||
|
check_rust_installation().await?;
|
||||||
|
|
||||||
|
// Build up a vector of installable applications, all of which implement the
|
||||||
|
// `Installable` async trait.
|
||||||
|
let mut to_install = Vec::<Box<dyn Installable + Send + Sync>>::new();
|
||||||
|
|
||||||
|
if let Some(ref xtensa_rust) = xtensa_rust {
|
||||||
|
to_install.push(Box::new(xtensa_rust.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
to_install.push(Box::new(llvm));
|
||||||
|
|
||||||
|
if targets.iter().any(|t| t.is_riscv()) {
|
||||||
|
let riscv_target = RiscVTarget::new(&args.nightly_version);
|
||||||
|
to_install.push(Box::new(riscv_target));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !args.std {
|
||||||
|
targets.iter().for_each(|target| {
|
||||||
|
if target.is_xtensa() {
|
||||||
|
let gcc = Gcc::new(target, &host_triple, &install_path);
|
||||||
|
to_install.push(Box::new(gcc));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// All RISC-V targets use the same GCC toolchain
|
||||||
|
// ESP32S2 and ESP32S3 also install the RISC-V toolchain for their ULP coprocessor
|
||||||
|
if targets.iter().any(|t| t != &Target::ESP32) {
|
||||||
|
let riscv_gcc = Gcc::new_riscv(&host_triple, &install_path);
|
||||||
|
to_install.push(Box::new(riscv_gcc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// With a list of applications to install, install them all in parallel.
|
||||||
|
let installable_items = to_install.len();
|
||||||
|
let (tx, mut rx) = mpsc::channel::<Result<Vec<String>, Error>>(installable_items);
|
||||||
|
for app in to_install {
|
||||||
|
let tx = tx.clone();
|
||||||
|
let retry_strategy = FixedInterval::from_millis(50).take(3);
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let res = Retry::spawn(retry_strategy, || async {
|
||||||
|
let res = app.install().await;
|
||||||
|
if res.is_err() {
|
||||||
|
warn!(
|
||||||
|
"{} Installation for '{}' failed, retrying",
|
||||||
|
emoji::WARN,
|
||||||
|
app.name()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
res
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
tx.send(res).await.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the results of the install tasks as they complete.
|
||||||
|
for _ in 0..installable_items {
|
||||||
|
let names = rx.recv().await.unwrap()?;
|
||||||
|
exports.extend(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
create_export_file(&export_file, &exports)?;
|
||||||
|
export_environment(&export_file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Queries the GitHub API and returns the JSON response.
|
/// Queries the GitHub API and returns the JSON response.
|
||||||
pub fn github_query(url: &str) -> Result<serde_json::Value, Error> {
|
pub fn github_query(url: &str) -> Result<serde_json::Value, Error> {
|
||||||
info!("{} Querying GitHub API: '{}'", emoji::INFO, url);
|
info!("{} Querying GitHub API: '{}'", emoji::INFO, url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user