mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-30 22:30:53 +00:00
feat: 🔥 Remove llvm 14 argument
This commit is contained in:
parent
010a1ca4f8
commit
51a8f10f03
@ -81,7 +81,7 @@ pub struct InstallOpts {
|
||||
#[arg(short = 'c', long, default_value = "cargo-espflash")]
|
||||
pub extra_crates: String,
|
||||
/// LLVM version.
|
||||
#[arg(short = 'x', long, default_value = "14", value_parser = ["14", "15"])]
|
||||
#[arg(short = 'x', long, default_value = "15", value_parser = ["15"])]
|
||||
pub llvm_version: String,
|
||||
/// Verbosity level of the logs.
|
||||
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
|
||||
@ -148,12 +148,7 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
let mut exports: Vec<String> = Vec::new();
|
||||
let export_file = args.export_file.clone();
|
||||
let rust_toolchain = RustToolchain::new(&args.toolchain_version, &host_triple);
|
||||
|
||||
// Complete LLVM is failing for Windows, aarch64 MacOs, and aarch64 Linux, so we are using always minified.
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
|
||||
let llvm = LlvmToolchain::new(args.llvm_version, args.profile_minimal, &host_triple);
|
||||
#[cfg(any(not(target_arch = "x86_64"), not(target_os = "linux")))]
|
||||
let llvm = LlvmToolchain::new(args.llvm_version, true, &host_triple);
|
||||
|
||||
debug!(
|
||||
"{} Arguments:
|
||||
|
@ -9,14 +9,7 @@ use anyhow::{bail, Ok, Result};
|
||||
use log::{info, warn};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// LLVM 14
|
||||
const DEFAULT_LLVM_14_COMPLETE_REPOSITORY: &str =
|
||||
"https://github.com/espressif/llvm-project/releases/download";
|
||||
const DEFAULT_LLVM_14_MINIFIED_REPOSITORY: &str =
|
||||
"https://github.com/esp-rs/rust-build/releases/download/llvm-project-14.0-minified";
|
||||
const DEFAULT_LLVM_14_VERSION: &str = "esp-14.0.0-20220415";
|
||||
// LLVM 15
|
||||
const DEFAULT_LLVM_15_REPOSITORY: &str =
|
||||
const DEFAULT_LLVM_REPOSITORY: &str =
|
||||
"https://github.com/espressif/llvm-project/releases/download";
|
||||
const DEFAULT_LLVM_15_VERSION: &str = "esp-15.0.0-20221014";
|
||||
|
||||
@ -28,60 +21,31 @@ pub struct LlvmToolchain {
|
||||
pub host_triple: HostTriple,
|
||||
/// LLVM Toolchain path.
|
||||
pub path: PathBuf,
|
||||
/// The repository containing LVVM sources.
|
||||
/// The repository containing LLVM sources.
|
||||
pub repository_url: String,
|
||||
/// LLVM Version ["14", "15"].
|
||||
/// LLVM Version ["15"].
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
impl LlvmToolchain {
|
||||
/// Gets the name of the LLVM arch based on the host triple.
|
||||
fn get_arch<'a>(version: &'a str, host_triple: &'a HostTriple) -> Result<&'a str> {
|
||||
if version == "14" {
|
||||
match host_triple {
|
||||
HostTriple::Aarch64AppleDarwin | HostTriple::X86_64AppleDarwin => Ok("macos"),
|
||||
HostTriple::X86_64UnknownLinuxGnu => Ok("linux-amd64"),
|
||||
HostTriple::X86_64PcWindowsMsvc | HostTriple::X86_64PcWindowsGnu => Ok("win64"),
|
||||
_ => bail!(
|
||||
"{} No LLVM arch found for the host triple: '{}'",
|
||||
emoji::ERROR,
|
||||
host_triple
|
||||
),
|
||||
}
|
||||
} else {
|
||||
// LLVM 15
|
||||
match host_triple {
|
||||
HostTriple::Aarch64AppleDarwin => Ok("macos-arm64"),
|
||||
HostTriple::X86_64AppleDarwin => Ok("macos"),
|
||||
HostTriple::X86_64UnknownLinuxGnu => Ok("linux-amd64"),
|
||||
HostTriple::Aarch64UnknownLinuxGnu => Ok("linux-arm64"),
|
||||
HostTriple::X86_64PcWindowsMsvc | HostTriple::X86_64PcWindowsGnu => Ok("win64"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the artifact extension based on the host triple.
|
||||
fn get_artifact_extension(host_triple: &HostTriple) -> &str {
|
||||
match host_triple {
|
||||
HostTriple::X86_64PcWindowsMsvc | HostTriple::X86_64PcWindowsGnu => "zip",
|
||||
_ => "tar.xz",
|
||||
HostTriple::Aarch64AppleDarwin => Ok("macos-arm64"),
|
||||
HostTriple::X86_64AppleDarwin => Ok("macos"),
|
||||
HostTriple::X86_64UnknownLinuxGnu => Ok("linux-amd64"),
|
||||
HostTriple::Aarch64UnknownLinuxGnu => Ok("linux-arm64"),
|
||||
HostTriple::X86_64PcWindowsMsvc | HostTriple::X86_64PcWindowsGnu => Ok("win64"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the binary path.
|
||||
fn get_lib_path(&self) -> String {
|
||||
#[cfg(windows)]
|
||||
if self.version == "14" {
|
||||
format!("{}/xtensa-esp32-elf-clang/bin", self.path.to_str().unwrap())
|
||||
} else {
|
||||
format!("{}/esp-clang/lib", self.path.to_str().unwrap())
|
||||
}
|
||||
format!("{}/esp-clang/bin", self.path.to_str().unwrap())
|
||||
|
||||
#[cfg(unix)]
|
||||
if self.version == "14" {
|
||||
format!("{}/xtensa-esp32-elf-clang/lib", self.path.to_str().unwrap())
|
||||
} else {
|
||||
format!("{}/esp-clang/lib", self.path.to_str().unwrap())
|
||||
}
|
||||
format!("{}/esp-clang/lib", self.path.to_str().unwrap())
|
||||
}
|
||||
|
||||
/// Installs the LLVM toolchain.
|
||||
@ -98,10 +62,7 @@ impl LlvmToolchain {
|
||||
info!("{} Installing Xtensa elf Clang", emoji::WRENCH);
|
||||
download_file(
|
||||
self.repository_url.clone(),
|
||||
&format!(
|
||||
"idf_tool_xtensa_elf_clang.{}",
|
||||
Self::get_artifact_extension(&self.host_triple)
|
||||
),
|
||||
"idf_tool_xtensa_elf_clang.tar.xz",
|
||||
self.path.to_str().unwrap(),
|
||||
true,
|
||||
)?;
|
||||
@ -122,60 +83,24 @@ impl LlvmToolchain {
|
||||
|
||||
/// Create a new instance with default values and proper toolchain version.
|
||||
pub fn new(version: String, minified: bool, host_triple: &HostTriple) -> Self {
|
||||
let mut file_name: String;
|
||||
let repository_url: String;
|
||||
let path: PathBuf;
|
||||
if version == "14" {
|
||||
if minified {
|
||||
file_name = format!(
|
||||
"xtensa-esp32-elf-llvm{}-{}-{}.{}",
|
||||
get_release_with_underscores(DEFAULT_LLVM_14_VERSION),
|
||||
DEFAULT_LLVM_14_VERSION,
|
||||
host_triple,
|
||||
Self::get_artifact_extension(host_triple)
|
||||
);
|
||||
repository_url = format!("{}/{}", DEFAULT_LLVM_14_MINIFIED_REPOSITORY, file_name,);
|
||||
} else {
|
||||
file_name = format!(
|
||||
"xtensa-esp32-elf-llvm{}-{}-{}.{}",
|
||||
get_release_with_underscores(DEFAULT_LLVM_14_VERSION),
|
||||
DEFAULT_LLVM_14_VERSION,
|
||||
Self::get_arch(&version, host_triple).unwrap(),
|
||||
Self::get_artifact_extension(host_triple)
|
||||
);
|
||||
repository_url = format!(
|
||||
"{}/{}/{}",
|
||||
DEFAULT_LLVM_14_COMPLETE_REPOSITORY, DEFAULT_LLVM_14_VERSION, file_name
|
||||
);
|
||||
}
|
||||
path = PathBuf::from(format!(
|
||||
"{}/{}-{}",
|
||||
get_tool_path("xtensa-esp32-elf-clang"),
|
||||
DEFAULT_LLVM_14_VERSION,
|
||||
host_triple
|
||||
));
|
||||
} else {
|
||||
// version == "15"
|
||||
file_name = format!(
|
||||
"llvm-{}-{}.tar.xz",
|
||||
DEFAULT_LLVM_15_VERSION,
|
||||
Self::get_arch(&version, host_triple).unwrap()
|
||||
);
|
||||
if minified {
|
||||
file_name = format!("libs_{}", file_name);
|
||||
}
|
||||
repository_url = format!(
|
||||
"{}/{}/{}",
|
||||
DEFAULT_LLVM_15_REPOSITORY, DEFAULT_LLVM_15_VERSION, file_name,
|
||||
);
|
||||
path = PathBuf::from(format!(
|
||||
"{}/{}-{}",
|
||||
get_tool_path("xtensa-esp32-elf-clang"),
|
||||
DEFAULT_LLVM_15_VERSION,
|
||||
host_triple
|
||||
));
|
||||
let mut file_name = format!(
|
||||
"llvm-{}-{}.tar.xz",
|
||||
DEFAULT_LLVM_15_VERSION,
|
||||
Self::get_arch(&version, host_triple).unwrap()
|
||||
);
|
||||
if minified {
|
||||
file_name = format!("libs_{}", file_name);
|
||||
}
|
||||
|
||||
let repository_url = format!(
|
||||
"{}/{}/{}",
|
||||
DEFAULT_LLVM_REPOSITORY, DEFAULT_LLVM_15_VERSION, file_name,
|
||||
);
|
||||
let path = PathBuf::from(format!(
|
||||
"{}/{}-{}",
|
||||
get_tool_path("xtensa-esp32-elf-clang"),
|
||||
DEFAULT_LLVM_15_VERSION,
|
||||
host_triple
|
||||
));
|
||||
Self {
|
||||
file_name,
|
||||
host_triple: host_triple.clone(),
|
||||
@ -185,23 +110,3 @@ impl LlvmToolchain {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the parsed version name.
|
||||
fn get_release_with_underscores(version: &str) -> String {
|
||||
let version: Vec<&str> = version.split('-').collect();
|
||||
let llvm_dot_release = version[1];
|
||||
llvm_dot_release.replace('.', "_")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::toolchain::llvm_toolchain::get_release_with_underscores;
|
||||
|
||||
#[test]
|
||||
fn test_get_release_with_underscores() {
|
||||
assert_eq!(
|
||||
get_release_with_underscores("esp-14.0.0-20220415"),
|
||||
"14_0_0".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user