mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-27 04:40:27 +00:00
Untar gcc files and add exports
This commit is contained in:
parent
09e352407e
commit
0e9099f069
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
/target
|
||||
/tests_projects
|
||||
Commands.sh
|
||||
|
@ -10,7 +10,7 @@ use dirs::home_dir;
|
||||
use json::JsonValue;
|
||||
use crate::shell::run_command;
|
||||
|
||||
pub fn get_tools_path() -> String {
|
||||
pub fn get_espressif_base_path() -> String {
|
||||
env::var("IDF_TOOLS_PATH").unwrap_or_else(|_e|
|
||||
home_dir().unwrap().display().to_string() + "/.espressif"
|
||||
)
|
||||
@ -18,17 +18,17 @@ pub fn get_tools_path() -> String {
|
||||
|
||||
// TODO: Use &str like get_dist_path
|
||||
pub fn get_tool_path(tool_name:String) -> String {
|
||||
let tools_path = get_tools_path();
|
||||
let tools_path = get_espressif_base_path();
|
||||
format!("{}/tools/{}", tools_path, tool_name)
|
||||
}
|
||||
|
||||
pub fn get_dist_path(tool_name:&str) -> String {
|
||||
let tools_path = get_tools_path();
|
||||
let tools_path = get_espressif_base_path();
|
||||
format!("{}/dist/{}", tools_path, tool_name)
|
||||
}
|
||||
|
||||
pub fn get_python_env_path(idf_version: String, python_version: String) -> String {
|
||||
let tools_path = get_tools_path();
|
||||
let tools_path = get_espressif_base_path();
|
||||
format!("{}/python_env/idf{}_py{}_env", tools_path, idf_version, python_version)
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ pub fn get_selected_idf_path() -> String {
|
||||
}
|
||||
|
||||
fn get_json_path() -> String {
|
||||
let idf_json_path = format!("{}/esp_idf.json", get_tools_path());
|
||||
let idf_json_path = format!("{}/esp_idf.json", get_espressif_base_path());
|
||||
return idf_json_path;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ fn load_json() -> json::JsonValue {
|
||||
let json_path = get_json_path();
|
||||
if !Path::new(&json_path).exists() {
|
||||
println!("Configuration file not found, creating new one: {}", json_path);
|
||||
bootstrap_json(json_path.clone(), get_tools_path());
|
||||
bootstrap_json(json_path.clone(), get_espressif_base_path());
|
||||
}
|
||||
|
||||
let content = fs::read_to_string(json_path)
|
||||
|
@ -14,7 +14,7 @@ use std::process::Stdio;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::config::get_selected_idf_path;
|
||||
use crate::config::get_tools_path;
|
||||
use crate::config::get_espressif_base_path;
|
||||
use crate::config::{
|
||||
get_dist_path, get_git_path, get_python_env_path, get_tool_path, update_property,
|
||||
};
|
||||
@ -252,7 +252,7 @@ fn get_install_runner(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn install_espidf(targets: String, version: String) -> Result<()> {
|
||||
pub fn install_espidf(targets: &str, version: String) -> Result<()> {
|
||||
let espidf_path = get_esp_idf_directory("frameworks/esp-idf".to_string());
|
||||
println!("ESP-IDF Path: {}", espidf_path);
|
||||
|
||||
@ -325,7 +325,7 @@ pub fn install_espidf(targets: String, version: String) -> Result<()> {
|
||||
println!("Installing esp-idf for {} with {}/install.sh", targets, espidf_path);
|
||||
let install_script_path = format!("{}/install.sh", espidf_path);
|
||||
let mut arguments: Vec<String> = [].to_vec();
|
||||
arguments.push(targets);
|
||||
arguments.push(targets.to_string());
|
||||
match run_command(install_script_path, arguments, "".to_string()) {
|
||||
Ok(_) => {
|
||||
println!("ESP-IDF installation succeeded");
|
||||
@ -439,7 +439,7 @@ fn get_shell() -> String {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_initializer() -> String {
|
||||
format!("{}/Initialize-Idf.ps1", get_tools_path())
|
||||
format!("{}/Initialize-Idf.ps1", get_espressif_base_path())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
157
src/main.rs
157
src/main.rs
@ -149,7 +149,7 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
&llvm_version,
|
||||
arch
|
||||
);
|
||||
|
||||
let mut exports: Vec<String> = Vec::new();
|
||||
check_rust_installation(&args.nightly_version);
|
||||
// TODO: Move to a function
|
||||
|
||||
@ -270,45 +270,53 @@ fn install(args: InstallOpts) -> Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Insall riscv target in nigthly if installing esp32c3
|
||||
|
||||
if args.espidf_version.is_some() {
|
||||
idf::install_espidf(args.build_target, args.espidf_version.unwrap())?;
|
||||
} else {
|
||||
println!("No esp-idf version provided. Installing gcc for targets");
|
||||
install_gcc_targets(targets)?;
|
||||
// TODO: Install gcc for targets
|
||||
}
|
||||
|
||||
// TODO: Install extra crates
|
||||
match args.extra_crates {
|
||||
// args.extra_crates.contains("cargo") => {
|
||||
// println!("Installing cargo");
|
||||
// install_cargo();
|
||||
// }
|
||||
// "mingw" => {
|
||||
// // match arch {
|
||||
// // "x86_64-pc-windows-gnu" => {
|
||||
// // install_mingw(toolchain);
|
||||
// // }
|
||||
// // _ => { println!("Ok"); }
|
||||
// // }
|
||||
// },
|
||||
_ => {
|
||||
println!("No extra tools selected");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Clear cache
|
||||
|
||||
// TODO: Set environment
|
||||
println!("Updating environment variables:");
|
||||
let libclang_path = format!(
|
||||
"{}/lib",
|
||||
get_tool_path("xtensa-esp32-elf-clang".to_string())
|
||||
);
|
||||
println!("export LIBCLANG_PATH=\"{}\"", &libclang_path);
|
||||
exports.push(format!("export LIBCLANG_PATH=\"{}\"", &libclang_path));
|
||||
|
||||
// TODO: Insall riscv target in nigthly if installing esp32c3
|
||||
|
||||
if args.espidf_version.is_some() {
|
||||
idf::install_espidf(&args.build_target, args.espidf_version.unwrap())?;
|
||||
exports.push(format!(
|
||||
"export IDF_TOOLS_PATH=\"{}\"",
|
||||
config::get_espressif_base_path()
|
||||
));
|
||||
exports.push(format!(". ./{}/export.sh\"", "TODO:UPDATE"));
|
||||
} else {
|
||||
println!("No esp-idf version provided. Installing gcc for targets");
|
||||
exports.extend(install_gcc_targets(targets)?.iter().cloned());
|
||||
}
|
||||
|
||||
// TODO: Install extra crates
|
||||
// match args.extra_crates {
|
||||
// // args.extra_crates.contains("cargo") => {
|
||||
// // println!("Installing cargo");
|
||||
// // install_cargo();
|
||||
// // }
|
||||
// // "mingw" => {
|
||||
// // // match arch {
|
||||
// // // "x86_64-pc-windows-gnu" => {
|
||||
// // // install_mingw(toolchain);
|
||||
// // // }
|
||||
// // // _ => { println!("Ok"); }
|
||||
// // // }
|
||||
// // },
|
||||
// _ => {
|
||||
// println!("No extra tools selected");
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO: Clear cache
|
||||
|
||||
// TODO: Set environment
|
||||
println!("Updating environment variables:");
|
||||
for e in exports.iter() {
|
||||
println!("{}", e);
|
||||
}
|
||||
|
||||
// #[cfg(windows)]
|
||||
// println!("PATH+=\";{}\"", libclang_bin);
|
||||
@ -438,47 +446,72 @@ fn get_gcc_arch(arch: &str) -> &str {
|
||||
}
|
||||
}
|
||||
|
||||
fn install_gcc_targets(targets: Vec<Chip>) -> Result<()> {
|
||||
fn install_gcc_targets(targets: Vec<Chip>) -> Result<Vec<String>> {
|
||||
let mut exports: Vec<String> = Vec::new();
|
||||
for target in targets {
|
||||
match target {
|
||||
Chip::Esp32 => install_gcc("xtensa-esp32-elf"),
|
||||
Chip::Esp32s2 => install_gcc("xtensa-esp32s2-elf"),
|
||||
Chip::Esp32s3 => install_gcc("xtensa-esp32s3-elf"),
|
||||
Chip::Esp32c3 => install_gcc("riscv32-esp-elf"),
|
||||
Chip::Esp32 => {
|
||||
install_gcc("xtensa-esp32-elf");
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("xtensa-esp32-elf/bin".to_string())
|
||||
));
|
||||
}
|
||||
Chip::Esp32s2 => {
|
||||
install_gcc("xtensa-esp32s2-elf");
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("xtensa-esp32s2-elf/bin".to_string())
|
||||
));
|
||||
}
|
||||
Chip::Esp32s3 => {
|
||||
install_gcc("xtensa-esp32s3-elf");
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("xtensa-esp32s3-elf/bin".to_string())
|
||||
));
|
||||
}
|
||||
Chip::Esp32c3 => {
|
||||
install_gcc("riscv32-esp-elf");
|
||||
exports.push(format!(
|
||||
"export PATH={}:$PATH",
|
||||
get_tool_path("riscv32-esp-elf/bin".to_string())
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
println!("Unknown target")
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok(exports)
|
||||
}
|
||||
|
||||
fn install_gcc(gcc_target: &str) {
|
||||
let gcc_path = get_tool_path(gcc_target.to_string());
|
||||
println!("gcc path: {}", gcc_path);
|
||||
if Path::new(&gcc_path).exists() {
|
||||
println!("Previous installation of GCC for target: {}", gcc_path);
|
||||
// return Ok(());
|
||||
} else {
|
||||
fs::create_dir_all(&gcc_path).unwrap();
|
||||
let gcc_file = format!(
|
||||
"{}-gcc8_4_0-esp-2021r2-patch3-{}.tar.xz",
|
||||
gcc_target,get_gcc_arch(guess_host_triple::guess_host_triple().unwrap())
|
||||
);
|
||||
println!("Downloading GCC for target: {}", gcc_file);
|
||||
let gcc_dist_url = format!(
|
||||
"https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/{}",
|
||||
gcc_file
|
||||
);
|
||||
match prepare_package_strip_prefix(&gcc_dist_url, gcc_path, "") {
|
||||
Ok(_) => {
|
||||
println!("Package {} ready", gcc_file);
|
||||
}
|
||||
Err(_e) => {
|
||||
println!("Unable to prepare {}", gcc_file);
|
||||
}
|
||||
// if Path::new(&gcc_path).exists() {
|
||||
// println!("Previous installation of GCC for target: {}", gcc_path);
|
||||
// // return Ok(());
|
||||
// } else {
|
||||
// fs::create_dir_all(&gcc_path).unwrap();
|
||||
let gcc_file = format!(
|
||||
"{}-gcc8_4_0-esp-2021r2-patch3-{}.tar.gz",
|
||||
gcc_target,
|
||||
get_gcc_arch(guess_host_triple::guess_host_triple().unwrap())
|
||||
);
|
||||
let gcc_dist_url = format!(
|
||||
"https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2-patch3/{}",
|
||||
gcc_file
|
||||
);
|
||||
match prepare_package_strip_prefix(&gcc_dist_url, gcc_path, "") {
|
||||
Ok(_) => {
|
||||
println!("Package {} ready", gcc_file);
|
||||
}
|
||||
Err(_e) => {
|
||||
println!("Unable to prepare {}", gcc_file);
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
// TODO: Create test for this function
|
||||
fn parse_targets(build_target: &str) -> Result<Vec<Chip>> {
|
||||
|
@ -285,9 +285,15 @@ pub fn prepare_package_strip_prefix(
|
||||
}
|
||||
let resp = reqwest::blocking::get(package_url).unwrap();
|
||||
let content_br = BufReader::new(resp);
|
||||
let tarfile = XzDecoder::new(content_br);
|
||||
let mut archive = Archive::new(tarfile);
|
||||
archive.unpack(&tools_path)?;
|
||||
if package_url.contains(".xz") {
|
||||
let tarfile = XzDecoder::new(content_br);
|
||||
let mut archive = Archive::new(tarfile);
|
||||
archive.unpack(&tools_path)?;
|
||||
} else {
|
||||
let tarfile = GzDecoder::new(content_br);
|
||||
let mut archive = Archive::new(tarfile);
|
||||
archive.unpack(&tools_path)?;
|
||||
}
|
||||
if !strip_prefix.is_empty(){
|
||||
let extracted_folder = format!("{}{}", &tools_path, strip_prefix);
|
||||
println!("Renaming: {} to {}", &extracted_folder, &output_directory);
|
||||
|
Loading…
x
Reference in New Issue
Block a user