Skip to content

Commit

Permalink
Update GCC version (#373)
Browse files Browse the repository at this point in the history
* feat: Update GCC version

* docs: Update changelog
  • Loading branch information
SergioGasquez authored Oct 17, 2023
1 parent 37a9425 commit 3910ea3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

### Changed
- Update GCC version to 13.2 (#373)

### Removed

Expand Down
53 changes: 12 additions & 41 deletions src/toolchain/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
emoji,
error::Error,
host_triple::HostTriple,
targets::Target,
toolchain::{download_file, Installable},
};
use async_trait::async_trait;
Expand All @@ -16,52 +15,35 @@ use std::{
};

const DEFAULT_GCC_REPOSITORY: &str = "https://github.com/espressif/crosstool-NG/releases/download";
const DEFAULT_GCC_RELEASE: &str = "12.2.0_20230208";
pub const ESP32_GCC: &str = "xtensa-esp32-elf";
pub const ESP32S2_GCC: &str = "xtensa-esp32s2-elf";
pub const ESP32S3_GCC: &str = "xtensa-esp32s3-elf";
const DEFAULT_GCC_RELEASE: &str = "13.2.0_20230928";
pub const RISCV_GCC: &str = "riscv32-esp-elf";
pub const XTENSA_GCC: &str = "xtensa-esp-elf";

#[derive(Debug, Clone)]
pub struct Gcc {
/// Host triple.
pub host_triple: HostTriple,
/// GCC Toolchain name.
pub name: String,
/// GCC Toolchain architecture.
pub arch: String,
/// GCC Toolchain path.
pub path: PathBuf,
}

impl Gcc {
/// Gets the binary path.
pub fn get_bin_path(&self) -> String {
format!("{}/{}/bin", &self.path.to_str().unwrap(), &self.name)
format!("{}/{}/bin", &self.path.to_str().unwrap(), &self.arch)
}

/// Create a new instance with default values and proper toolchain name.
pub fn new(target: &Target, host_triple: &HostTriple, toolchain_path: &Path) -> Self {
let name = get_gcc_name(target);
pub fn new(arch: &str, host_triple: &HostTriple, toolchain_path: &Path) -> Self {
let path = toolchain_path
.join(&name)
.join(arch)
.join(format!("esp-{DEFAULT_GCC_RELEASE}"));

Self {
host_triple: host_triple.clone(),
name,
path,
}
}

/// Create a new instance of RISC-V GCC with default values and proper toolchain name.
pub fn new_riscv(host_triple: &HostTriple, toolchain_path: &Path) -> Self {
let name = RISCV_GCC.to_string();
let path = toolchain_path
.join(&name)
.join(format!("esp-{DEFAULT_GCC_RELEASE}"));

Self {
host_triple: host_triple.clone(),
name,
arch: arch.to_string(),
path,
}
}
Expand All @@ -81,7 +63,7 @@ impl Installable for Gcc {
} else {
let gcc_file = format!(
"{}-{}-{}.{}",
self.name,
self.arch,
DEFAULT_GCC_RELEASE,
get_arch(&self.host_triple).unwrap(),
extension
Expand All @@ -92,7 +74,7 @@ impl Installable for Gcc {
);
download_file(
gcc_dist_url,
&format!("{}.{}", &self.name, extension),
&format!("{}.{}", &self.arch, extension),
&self.path.display().to_string(),
true,
false,
Expand All @@ -119,7 +101,7 @@ impl Installable for Gcc {
}

fn name(&self) -> String {
format!("GCC ({})", self.name)
format!("GCC ({})", self.arch)
}
}

Expand All @@ -144,22 +126,11 @@ fn get_artifact_extension(host_triple: &HostTriple) -> &str {
}
}

/// Gets the toolchain name based on the Target
pub fn get_gcc_name(target: &Target) -> String {
let toolchain = match target {
Target::ESP32 => ESP32_GCC,
Target::ESP32S2 => ESP32S2_GCC,
Target::ESP32S3 => ESP32S3_GCC,
Target::ESP32C2 | Target::ESP32C3 | Target::ESP32C6 | Target::ESP32H2 => RISCV_GCC,
};
toolchain.to_string()
}

/// Checks if the toolchain is pressent, if present uninstalls it.
pub fn uninstall_gcc_toolchains(toolchain_path: &Path) -> Result<(), Error> {
info!("{} Uninstalling GCC toolchain", emoji::WRENCH);

let gcc_toolchains = vec![ESP32_GCC, ESP32S2_GCC, ESP32S3_GCC, RISCV_GCC];
let gcc_toolchains = vec![XTENSA_GCC, RISCV_GCC];

for toolchain in gcc_toolchains {
let gcc_path = toolchain_path.join(toolchain);
Expand Down
17 changes: 9 additions & 8 deletions src/toolchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
host_triple::get_host_triple,
targets::Target,
toolchain::{
gcc::Gcc,
gcc::{Gcc, RISCV_GCC, XTENSA_GCC},
llvm::Llvm,
rust::{check_rust_installation, get_rustup_home, RiscVTarget, XtensaRust},
},
Expand Down Expand Up @@ -217,16 +217,17 @@ pub async fn install(args: InstallOpts) -> Result<()> {
}

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));
}
});
if targets
.iter()
.any(|t| t == &Target::ESP32 || t == &Target::ESP32S2 || t == &Target::ESP32S3)
{
let xtensa_gcc = Gcc::new(XTENSA_GCC, &host_triple, &install_path);
to_install.push(Box::new(xtensa_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);
let riscv_gcc = Gcc::new(RISCV_GCC, &host_triple, &install_path);
to_install.push(Box::new(riscv_gcc));
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/toolchain/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
host_triple::HostTriple,
toolchain::{
download_file,
gcc::{ESP32S2_GCC, ESP32S3_GCC, ESP32_GCC, RISCV_GCC},
gcc::{RISCV_GCC, XTENSA_GCC},
github_query,
llvm::CLANG_NAME,
Installable,
Expand Down Expand Up @@ -165,9 +165,7 @@ impl XtensaRust {
let entry_path = entry.unwrap().path();
let entry_name = entry_path.display().to_string();
if !entry_name.contains(RISCV_GCC)
&& !entry_name.contains(ESP32_GCC)
&& !entry_name.contains(ESP32S2_GCC)
&& !entry_name.contains(ESP32S3_GCC)
&& !entry_name.contains(XTENSA_GCC)
&& !entry_name.contains(CLANG_NAME)
{
if entry_path.is_dir() {
Expand Down

0 comments on commit 3910ea3

Please sign in to comment.