mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-26 20:30:28 +00:00
Rust 2024 edition (#497)
* build: Bump rust edition and msrv * style: Format code * feat: Add unsafe blocks * feat: Add unsafe blocks for Windows
This commit is contained in:
parent
edc9d64134
commit
1b09495209
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@ -74,7 +74,7 @@ jobs:
|
||||
- name: Setup Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: 1.81.0
|
||||
toolchain: 1.85.0
|
||||
- name: Enable caching
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Cargo check
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "espup"
|
||||
version = "0.15.0"
|
||||
authors = ["Sergio Gasquez Arcos <sergio.gasquez@gmail.com>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT OR Apache-2.0"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/esp-rs/espup"
|
||||
@ -11,7 +11,7 @@ Tool for installing and maintaining Espressif Rust ecosystem.
|
||||
"""
|
||||
keywords = ["cli", "embedded", "esp", "esp-rs", "xtensa"]
|
||||
categories = ["command-line-utilities", "development-tools", "embedded"]
|
||||
rust-version = "1.81.0"
|
||||
rust-version = "1.85.0"
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1.88"
|
||||
|
@ -1,7 +1,7 @@
|
||||
# espup
|
||||
|
||||
[](https://crates.io/crates/espup)
|
||||

|
||||

|
||||
[](https://github.com/esp-rs/espup/actions/workflows/ci.yaml)
|
||||
[](https://github.com/esp-rs/espup/actions/workflows/audit.yaml)
|
||||
[](https://matrix.to/#/#esp-rs:matrix.org)
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Command line interface.
|
||||
|
||||
use crate::targets::{parse_targets, Target};
|
||||
use crate::targets::{Target, parse_targets};
|
||||
use clap::Parser;
|
||||
use clap_complete::Shell;
|
||||
use std::{collections::HashSet, path::PathBuf};
|
||||
|
14
src/env.rs
14
src/env.rs
@ -11,8 +11,8 @@ use std::{
|
||||
};
|
||||
#[cfg(windows)]
|
||||
use winreg::{
|
||||
enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE},
|
||||
RegKey,
|
||||
enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE},
|
||||
};
|
||||
|
||||
#[cfg(windows)]
|
||||
@ -26,7 +26,7 @@ pub fn set_env_variable(key: &str, value: &str) -> Result<(), Error> {
|
||||
use std::ptr;
|
||||
use winapi::shared::minwindef::*;
|
||||
use winapi::um::winuser::{
|
||||
SendMessageTimeoutA, HWND_BROADCAST, SMTO_ABORTIFHUNG, WM_SETTINGCHANGE,
|
||||
HWND_BROADCAST, SMTO_ABORTIFHUNG, SendMessageTimeoutA, WM_SETTINGCHANGE,
|
||||
};
|
||||
|
||||
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
||||
@ -61,7 +61,9 @@ pub fn delete_env_variable(key: &str) -> Result<(), Error> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
env::remove_var(key);
|
||||
unsafe {
|
||||
env::remove_var(key);
|
||||
}
|
||||
|
||||
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
||||
let environment_key = hkcu.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)?;
|
||||
@ -164,7 +166,9 @@ pub fn print_post_install_msg(export_file: &Path) -> Result<(), Error> {
|
||||
"\tA file was created at '{}' showing the injected environment variables",
|
||||
export_file.display()
|
||||
);
|
||||
println!("\tIf you get still get errors, try manually adding the environment variables by running '{}'", export_file.display()
|
||||
println!(
|
||||
"\tIf you get still get errors, try manually adding the environment variables by running '{}'",
|
||||
export_file.display()
|
||||
);
|
||||
}
|
||||
#[cfg(unix)]
|
||||
@ -182,7 +186,7 @@ pub fn print_post_install_msg(export_file: &Path) -> Result<(), Error> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::env::{create_export_file, get_export_file, DEFAULT_EXPORT_FILE};
|
||||
use crate::env::{DEFAULT_EXPORT_FILE, create_export_file, get_export_file};
|
||||
use directories::BaseDirs;
|
||||
use std::{
|
||||
env::current_dir,
|
||||
|
@ -24,12 +24,14 @@ pub enum Error {
|
||||
|
||||
#[diagnostic(code(espup::ivalid_destination))]
|
||||
#[error(
|
||||
"Invalid export file destination: '{0}'. Please, use an absolute or releative path (including the file and its extension)")]
|
||||
"Invalid export file destination: '{0}'. Please, use an absolute or releative path (including the file and its extension)"
|
||||
)]
|
||||
InvalidDestination(String),
|
||||
|
||||
#[diagnostic(code(espup::toolchain::rust::invalid_version))]
|
||||
#[error(
|
||||
"Invalid toolchain version '{0}'. Verify that the format is correct: '<major>.<minor>.<patch>.<subpatch>' or '<major>.<minor>.<patch>', and that the release exists in https://github.com/esp-rs/rust-build/releases")]
|
||||
"Invalid toolchain version '{0}'. Verify that the format is correct: '<major>.<minor>.<patch>.<subpatch>' or '<major>.<minor>.<patch>', and that the release exists in https://github.com/esp-rs/rust-build/releases"
|
||||
)]
|
||||
InvalidVersion(String),
|
||||
|
||||
#[error(transparent)]
|
||||
|
@ -42,7 +42,7 @@ pub fn get_host_triple(host_triple_arg: Option<String>) -> Result<HostTriple, Er
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::host_triple::{get_host_triple, HostTriple};
|
||||
use crate::host_triple::{HostTriple, get_host_triple};
|
||||
|
||||
#[test]
|
||||
fn test_get_host_triple() {
|
||||
|
@ -36,7 +36,7 @@ pub mod logging {
|
||||
pub mod update {
|
||||
use log::warn;
|
||||
use std::time::Duration;
|
||||
use update_informer::{registry, Check};
|
||||
use update_informer::{Check, registry};
|
||||
|
||||
/// Check crates.io for a new version of the application
|
||||
pub fn check_for_update(name: &str, version: &str) {
|
||||
|
@ -3,12 +3,12 @@ use espup::{
|
||||
cli::{CompletionsOpts, InstallOpts, UninstallOpts},
|
||||
logging::initialize_logger,
|
||||
toolchain::{
|
||||
InstallMode,
|
||||
gcc::uninstall_gcc_toolchains,
|
||||
install as toolchain_install,
|
||||
llvm::Llvm,
|
||||
remove_dir,
|
||||
rust::{get_rustup_home, XtensaRust},
|
||||
InstallMode,
|
||||
rust::{XtensaRust, get_rustup_home},
|
||||
},
|
||||
update::check_for_update,
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ pub fn parse_targets(targets_str: &str) -> Result<HashSet<Target>, Error> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::targets::{parse_targets, Target};
|
||||
use crate::targets::{Target, parse_targets};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
|
@ -5,7 +5,7 @@ use crate::env::{get_windows_path_var, set_env_variable};
|
||||
use crate::{
|
||||
error::Error,
|
||||
host_triple::HostTriple,
|
||||
toolchain::{download_file, Installable},
|
||||
toolchain::{Installable, download_file},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use log::{debug, info, warn};
|
||||
@ -110,9 +110,13 @@ impl Installable for Gcc {
|
||||
&self.get_bin_path()
|
||||
));
|
||||
if self.arch == RISCV_GCC {
|
||||
env::set_var("RISCV_GCC", self.get_bin_path());
|
||||
unsafe {
|
||||
env::set_var("RISCV_GCC", self.get_bin_path());
|
||||
}
|
||||
} else {
|
||||
env::set_var("XTENSA_GCC", self.get_bin_path());
|
||||
unsafe {
|
||||
env::set_var("XTENSA_GCC", self.get_bin_path());
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(unix)]
|
||||
|
@ -5,7 +5,7 @@ use crate::env::{delete_env_variable, get_windows_path_var, set_env_variable};
|
||||
use crate::{
|
||||
error::Error,
|
||||
host_triple::HostTriple,
|
||||
toolchain::{download_file, rust::RE_EXTENDED_SEMANTIC_VERSION, Installable},
|
||||
toolchain::{Installable, download_file, rust::RE_EXTENDED_SEMANTIC_VERSION},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
#[cfg(unix)]
|
||||
@ -335,8 +335,10 @@ impl Installable for Llvm {
|
||||
"$Env:PATH = \"{};\" + $Env:PATH",
|
||||
self.get_lib_path()
|
||||
));
|
||||
env::set_var("LIBCLANG_BIN_PATH", self.get_lib_path());
|
||||
env::set_var("LIBCLANG_PATH", libclang_dll);
|
||||
unsafe {
|
||||
env::set_var("LIBCLANG_BIN_PATH", self.get_lib_path());
|
||||
env::set_var("LIBCLANG_PATH", libclang_dll);
|
||||
}
|
||||
}
|
||||
#[cfg(unix)]
|
||||
if cfg!(unix) {
|
||||
@ -365,7 +367,9 @@ impl Installable for Llvm {
|
||||
#[cfg(windows)]
|
||||
if cfg!(windows) {
|
||||
exports.push(format!("$Env:CLANG_PATH = \"{}\"", self.get_bin_path()));
|
||||
env::set_var("CLANG_PATH", self.get_bin_path());
|
||||
unsafe {
|
||||
env::set_var("CLANG_PATH", self.get_bin_path());
|
||||
}
|
||||
}
|
||||
#[cfg(unix)]
|
||||
exports.push(format!("export CLANG_PATH=\"{}\"", self.get_bin_path()));
|
||||
|
@ -11,7 +11,7 @@ use crate::{
|
||||
toolchain::{
|
||||
gcc::{Gcc, RISCV_GCC, XTENSA_GCC},
|
||||
llvm::Llvm,
|
||||
rust::{check_rust_installation, get_rustup_home, RiscVTarget, XtensaRust},
|
||||
rust::{RiscVTarget, XtensaRust, check_rust_installation, get_rustup_home},
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
@ -22,14 +22,14 @@ use reqwest::{blocking::Client, header};
|
||||
use retry::{delay::Fixed, retry};
|
||||
use std::{
|
||||
env,
|
||||
fs::{create_dir_all, remove_file, File},
|
||||
io::{copy, Write},
|
||||
fs::{File, create_dir_all, remove_file},
|
||||
io::{Write, copy},
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{self, AtomicUsize},
|
||||
};
|
||||
use tar::Archive;
|
||||
use tokio::{fs::remove_dir_all, sync::mpsc};
|
||||
use tokio_retry::{strategy::FixedInterval, Retry};
|
||||
use tokio_retry::{Retry, strategy::FixedInterval};
|
||||
use tokio_stream::StreamExt;
|
||||
use xz2::read::XzDecoder;
|
||||
use zip::ZipArchive;
|
||||
|
@ -4,11 +4,10 @@ use crate::{
|
||||
error::Error,
|
||||
host_triple::HostTriple,
|
||||
toolchain::{
|
||||
download_file,
|
||||
Installable, download_file,
|
||||
gcc::{RISCV_GCC, XTENSA_GCC},
|
||||
github_query,
|
||||
llvm::CLANG_NAME,
|
||||
Installable,
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
@ -208,10 +207,10 @@ impl Installable for XtensaRust {
|
||||
let output = String::from_utf8_lossy(&rustc_version.stdout);
|
||||
if rustc_version.status.success() && output.contains(&self.version) {
|
||||
warn!(
|
||||
"Previous installation of Xtensa Rust {} exists in: '{}'. Reusing this installation",
|
||||
&self.version,
|
||||
&self.toolchain_destination.display()
|
||||
);
|
||||
"Previous installation of Xtensa Rust {} exists in: '{}'. Reusing this installation",
|
||||
&self.version,
|
||||
&self.toolchain_destination.display()
|
||||
);
|
||||
return Ok(vec![]);
|
||||
} else {
|
||||
if !rustc_version.status.success() {
|
||||
@ -359,7 +358,8 @@ impl RiscVTarget {
|
||||
impl Installable for RiscVTarget {
|
||||
async fn install(&self) -> Result<Vec<String>, Error> {
|
||||
info!(
|
||||
"Installing RISC-V Rust targets ('riscv32imc-unknown-none-elf', 'riscv32imac-unknown-none-elf' and 'riscv32imafc-unknown-none-elf') for '{}' toolchain", &self.stable_version
|
||||
"Installing RISC-V Rust targets ('riscv32imc-unknown-none-elf', 'riscv32imac-unknown-none-elf' and 'riscv32imafc-unknown-none-elf') for '{}' toolchain",
|
||||
&self.stable_version
|
||||
);
|
||||
|
||||
if !Command::new("rustup")
|
||||
@ -449,7 +449,7 @@ pub async fn check_rust_installation() -> Result<(), Error> {
|
||||
mod tests {
|
||||
use crate::{
|
||||
logging::initialize_logger,
|
||||
toolchain::rust::{get_cargo_home, get_rustup_home, XtensaRust},
|
||||
toolchain::rust::{XtensaRust, get_cargo_home, get_rustup_home},
|
||||
};
|
||||
use directories::BaseDirs;
|
||||
use std::env;
|
||||
@ -475,7 +475,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_cargo_home() {
|
||||
// No CARGO_HOME set
|
||||
env::remove_var("CARGO_HOME");
|
||||
unsafe {
|
||||
env::remove_var("CARGO_HOME");
|
||||
}
|
||||
assert_eq!(
|
||||
get_cargo_home(),
|
||||
BaseDirs::new().unwrap().home_dir().join(".cargo")
|
||||
@ -483,14 +485,18 @@ mod tests {
|
||||
// CARGO_HOME set
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let cargo_home = temp_dir.path().to_path_buf();
|
||||
env::set_var("CARGO_HOME", cargo_home.to_str().unwrap());
|
||||
unsafe {
|
||||
env::set_var("CARGO_HOME", cargo_home.to_str().unwrap());
|
||||
}
|
||||
assert_eq!(get_cargo_home(), cargo_home);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_rustup_home() {
|
||||
// No RUSTUP_HOME set
|
||||
env::remove_var("RUSTUP_HOME");
|
||||
unsafe {
|
||||
env::remove_var("RUSTUP_HOME");
|
||||
}
|
||||
assert_eq!(
|
||||
get_rustup_home(),
|
||||
BaseDirs::new().unwrap().home_dir().join(".rustup")
|
||||
@ -498,7 +504,9 @@ mod tests {
|
||||
// RUSTUP_HOME set
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let rustup_home = temp_dir.path().to_path_buf();
|
||||
env::set_var("RUSTUP_HOME", rustup_home.to_str().unwrap());
|
||||
unsafe {
|
||||
env::set_var("RUSTUP_HOME", rustup_home.to_str().unwrap());
|
||||
}
|
||||
assert_eq!(get_rustup_home(), rustup_home);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user