Merge pull request #23 from esp-rs/feature/llvm-argument

Add llvm-version arg
This commit is contained in:
Sergio Gasquez Arcos 2022-10-31 10:50:40 +01:00 committed by GitHub
commit 0764c0aee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 101 deletions

View File

@ -9,13 +9,13 @@ ARG CONTAINER_GROUP=esp
# Ubuntu/Debian # Ubuntu/Debian
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y git python3 python3-pip gcc build-essential curl pkg-config libudev-dev \ && apt-get install -y git python3 python3-pip gcc build-essential curl pkg-config libudev-dev libtinfo5\
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
RUN adduser --disabled-password --gecos "" ${CONTAINER_USER} RUN adduser --disabled-password --gecos "" ${CONTAINER_USER}
# Fedora # Fedora
# RUN dnf -y update \ # RUN dnf -y update \
# && dnf -y install git python3 python3-pip gcc systemd-devel \ # && dnf -y install git python3 python3-pip gcc systemd-devel ncurses-compat-libs \
# && dnf clean all # && dnf clean all
# RUN adduser ${CONTAINER_USER} # RUN adduser ${CONTAINER_USER}
@ -23,7 +23,7 @@ USER ${CONTAINER_USER}
WORKDIR /home/${CONTAINER_USER} WORKDIR /home/${CONTAINER_USER}
# openSUSE Tumbleweed/Leap # openSUSE Tumbleweed/Leap
# RUN zypper install -y git gcc libudev-devel ninja python3 python3-pip make \ # RUN zypper install -y git gcc libudev-devel ninja python3 python3-pip make libncurses5 \
# && zypper clean # && zypper clean
# Install Rust # Install Rust

View File

@ -10,35 +10,35 @@
`espup` is a tool for installing and maintaining the required toolchains for `espup` is a tool for installing and maintaining the required toolchains for
developing applications in Rust for Espressif SoC's. developing applications in Rust for Espressif SoC's.
> **Note**
>
> This application is still under development and should be considered experimental
## Requirements ## Requirements
Before running or installing `espup`, make sure that [`rustup`](https://www.rust-lang.org/tools/install) Before running or installing `espup`, make sure that [`rustup`](https://www.rust-lang.org/tools/install) and the following dependencies are installed.
and the following dependencies are installed.
### Windows ### Windows
- [Python](https://www.python.org/downloads/). Version should be between `3.6` and `3.10`. - [git](https://git-scm.com/download/win).
- [git](https://git-scm.com/download/win) - [Python](https://www.python.org/downloads/): Only required when installing ESP-IDF.
- Toolchain. Select one of the following:
- [Windows x86_64 GNU](https://github.com/esp-rs/rust-build#windows-x86_64-gnu)
- [Windows x86_64 MSVC](https://github.com/esp-rs/rust-build#windows-x86_64-msvc)
### Linux ### Linux
- Ubuntu/Debian - Ubuntu/Debian
```sh ```sh
sudo apt-get install -y git python3 python3-pip gcc build-essential curl pkg-config libudev-dev sudo apt-get install -y git python3 python3-pip gcc build-essential curl pkg-config libudev-dev libtinfo5
``` ```
- `libudev-dev` is only required when installing `cargo-espflash`.
- `python3` and `python3-pip` are only required when installing ESP-IDF.
- `libtinfo5` is required by LLVM 15.
- Fedora - Fedora
```sh ```sh
sudo dnf -y install git python3 python3-pip gcc systemd-devel sudo dnf -y install git python3 python3-pip gcc systemd-devel ncurses-compat-libs
``` ```
- `systemd-devel` is only required when installing `cargo-espflash`.
- `python3` and `python3-pip` are only required when installing ESP-IDF.
- `ncurses-compat-libs` is required by LLVM 15.
- openSUSE Thumbleweed/Leap - openSUSE Thumbleweed/Leap
``` ```
sudo zypper install -y git gcc libudev-devel ninja python3 python3-pip make sudo zypper install -y git gcc libudev-devel ninja python3 python3-pip make libncurses5
``` ```
- `libudev-devel` is only required when installing `cargo-espflash`.
- `python3` and `python3-pip` are only required when installing ESP-IDF.
- `libncurses5` is required by LLVM 15.
## Installation ## Installation
@ -76,12 +76,12 @@ See [Usage](#usage) section for more details.
> before building an application. > before building an application.
### Uninstall ### Uninstall
```sh ```sh
espup uninstall espup uninstall
``` ```
### Update ### Update
```sh ```sh
espup update espup update
``` ```
## Usage ## Usage

View File

@ -86,6 +86,9 @@ pub struct InstallOpts {
// Make it vector and have splliter =" " // Make it vector and have splliter =" "
#[arg(short = 'c', long, default_value = "cargo-espflash")] #[arg(short = 'c', long, default_value = "cargo-espflash")]
pub extra_crates: String, pub extra_crates: String,
/// LLVM version.
#[arg(short = 'x', long, default_value = "15", value_parser = ["15"])]
pub llvm_version: String,
/// Verbosity level of the logs. /// Verbosity level of the logs.
#[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])] #[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])]
pub log_level: String, pub log_level: String,
@ -154,11 +157,7 @@ fn install(args: InstallOpts) -> Result<()> {
} else { } else {
None None
}; };
// Complete LLVM is failing for Windows, aarch64 MacOs, and aarch64 Linux, so we are using always minified. let llvm = LlvmToolchain::new(args.llvm_version, args.profile_minimal, &host_triple);
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
let llvm = LlvmToolchain::new(args.profile_minimal, &host_triple);
#[cfg(any(not(target_arch = "x86_64"), not(target_os = "linux")))]
let llvm = LlvmToolchain::new(true, &host_triple);
debug!( debug!(
"{} Arguments: "{} Arguments:

View File

@ -5,15 +5,12 @@ use crate::{
host_triple::HostTriple, host_triple::HostTriple,
toolchain::{download_file, espidf::get_tool_path}, toolchain::{download_file, espidf::get_tool_path},
}; };
use anyhow::{bail, Ok, Result}; use anyhow::{Ok, Result};
use log::{info, warn}; use log::{info, warn};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
const DEFAULT_LLVM_COMPLETE_REPOSITORY: &str = const DEFAULT_LLVM_REPOSITORY: &str = "https://github.com/espressif/llvm-project/releases/download";
"https://github.com/espressif/llvm-project/releases/download"; const DEFAULT_LLVM_15_VERSION: &str = "esp-15.0.0-20221014";
const DEFAULT_LLVM_MINIFIED_REPOSITORY: &str =
"https://github.com/esp-rs/rust-build/releases/download/llvm-project-14.0-minified";
const DEFAULT_LLVM_VERSION: &str = "esp-14.0.0-20220415";
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct LlvmToolchain { pub struct LlvmToolchain {
@ -23,9 +20,9 @@ pub struct LlvmToolchain {
pub host_triple: HostTriple, pub host_triple: HostTriple,
/// LLVM Toolchain path. /// LLVM Toolchain path.
pub path: PathBuf, pub path: PathBuf,
/// The repository containing LVVM sources. /// The repository containing LLVM sources.
pub repository_url: String, pub repository_url: String,
/// Repository release version to use. /// LLVM Version ["15"].
pub version: String, pub version: String,
} }
@ -33,31 +30,20 @@ impl LlvmToolchain {
/// Gets the name of the LLVM arch based on the host triple. /// Gets the name of the LLVM arch based on the host triple.
fn get_arch(host_triple: &HostTriple) -> Result<&str> { fn get_arch(host_triple: &HostTriple) -> Result<&str> {
match host_triple { match host_triple {
HostTriple::Aarch64AppleDarwin | HostTriple::X86_64AppleDarwin => Ok("macos"), HostTriple::Aarch64AppleDarwin => Ok("macos-arm64"),
HostTriple::X86_64AppleDarwin => Ok("macos"),
HostTriple::X86_64UnknownLinuxGnu => Ok("linux-amd64"), HostTriple::X86_64UnknownLinuxGnu => Ok("linux-amd64"),
HostTriple::Aarch64UnknownLinuxGnu => Ok("linux-arm64"),
HostTriple::X86_64PcWindowsMsvc | HostTriple::X86_64PcWindowsGnu => Ok("win64"), HostTriple::X86_64PcWindowsMsvc | HostTriple::X86_64PcWindowsGnu => Ok("win64"),
_ => bail!(
"{} No LLVM arch found for the host triple: '{}'",
emoji::ERROR,
host_triple
),
}
}
/// 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",
} }
} }
/// Gets the binary path. /// Gets the binary path.
fn get_lib_path(&self) -> String { fn get_lib_path(&self) -> String {
#[cfg(windows)] #[cfg(windows)]
let llvm_path = format!("{}/xtensa-esp32-elf-clang/bin", self.path.to_str().unwrap()); let llvm_path = format!("{}/esp-clang/bin", self.path.to_str().unwrap());
#[cfg(unix)] #[cfg(unix)]
let llvm_path = format!("{}/xtensa-esp32-elf-clang/lib", self.path.to_str().unwrap()); let llvm_path = format!("{}/esp-clang/lib", self.path.to_str().unwrap());
llvm_path llvm_path
} }
@ -75,10 +61,7 @@ impl LlvmToolchain {
info!("{} Installing Xtensa elf Clang", emoji::WRENCH); info!("{} Installing Xtensa elf Clang", emoji::WRENCH);
download_file( download_file(
self.repository_url.clone(), self.repository_url.clone(),
&format!( "idf_tool_xtensa_elf_clang.tar.xz",
"idf_tool_xtensa_elf_clang.{}",
Self::get_artifact_extension(&self.host_triple)
),
self.path.to_str().unwrap(), self.path.to_str().unwrap(),
true, true,
)?; )?;
@ -98,39 +81,25 @@ impl LlvmToolchain {
} }
/// Create a new instance with default values and proper toolchain version. /// Create a new instance with default values and proper toolchain version.
pub fn new(minified: bool, host_triple: &HostTriple) -> Self { pub fn new(version: String, minified: bool, host_triple: &HostTriple) -> Self {
let file_name: String; let mut file_name = format!(
let version = DEFAULT_LLVM_VERSION.to_string(); "llvm-{}-{}.tar.xz",
let repository_url: String; DEFAULT_LLVM_15_VERSION,
Self::get_arch(host_triple).unwrap()
);
if minified { if minified {
file_name = format!( file_name = format!("libs_{}", file_name);
"xtensa-esp32-elf-llvm{}-{}-{}.{}",
get_release_with_underscores(&version),
&version,
host_triple,
Self::get_artifact_extension(host_triple)
);
repository_url = format!("{}/{}", DEFAULT_LLVM_MINIFIED_REPOSITORY, file_name,);
} else {
file_name = format!(
"xtensa-esp32-elf-llvm{}-{}-{}.{}",
get_release_with_underscores(&version),
&version,
Self::get_arch(host_triple).unwrap(),
Self::get_artifact_extension(host_triple)
);
repository_url = format!(
"{}/{}/{}",
DEFAULT_LLVM_COMPLETE_REPOSITORY, &version, file_name
);
} }
let path = format!( 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"), get_tool_path("xtensa-esp32-elf-clang"),
version, DEFAULT_LLVM_15_VERSION,
host_triple host_triple
) ));
.into();
Self { Self {
file_name, file_name,
host_triple: host_triple.clone(), host_triple: host_triple.clone(),
@ -140,23 +109,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()
);
}
}