From 65dc49efb681fb4cdf929e2817ab689327b73285 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Fri, 20 Oct 2023 12:39:20 +0000 Subject: [PATCH 1/2] feat: Add symlink to LLVM in $HOME/.espup/esp-clang --- src/toolchain/llvm.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/toolchain/llvm.rs b/src/toolchain/llvm.rs index 7998c6e5..74ad36f1 100644 --- a/src/toolchain/llvm.rs +++ b/src/toolchain/llvm.rs @@ -8,9 +8,13 @@ use crate::{ toolchain::{download_file, rust::RE_EXTENDED_SEMANTIC_VERSION, Installable}, }; use async_trait::async_trait; +#[cfg(unix)] +use directories::BaseDirs; use log::{info, warn}; use miette::Result; use regex::Regex; +#[cfg(unix)] +use std::{fs::create_dir_all, os::unix::fs::symlink}; use std::{ fs::remove_dir_all, path::{Path, PathBuf}, @@ -186,7 +190,26 @@ impl Installable for Llvm { ); } #[cfg(unix)] - exports.push(format!("export LIBCLANG_PATH=\"{}\"", self.get_lib_path())); + if cfg!(unix) { + exports.push(format!("export LIBCLANG_PATH=\"{}\"", self.get_lib_path())); + let espup_dir = BaseDirs::new().unwrap().home_dir().join(".espup"); + + if !espup_dir.exists() { + create_dir_all(espup_dir.display().to_string()) + .map_err(|_| Error::CreateDirectory(espup_dir.display().to_string()))?; + } + let llvm_symlink_path = espup_dir.join("esp-clang"); + if llvm_symlink_path.exists() { + remove_dir_all(&llvm_symlink_path) + .map_err(|_| Error::RemoveDirectory(llvm_symlink_path.display().to_string()))?; + } + info!( + "Creating symlink between {} and {}", + self.get_lib_path(), + llvm_symlink_path.display() + ); + symlink(self.get_lib_path(), llvm_symlink_path)?; + } if self.extended { #[cfg(windows)] From 117b37977d977314f5bf9623ada141952f0ec328 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Fri, 27 Oct 2023 09:13:55 +0000 Subject: [PATCH 2/2] feat: Remove symlink folder --- src/toolchain/llvm.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/toolchain/llvm.rs b/src/toolchain/llvm.rs index 74ad36f1..1a436059 100644 --- a/src/toolchain/llvm.rs +++ b/src/toolchain/llvm.rs @@ -139,6 +139,15 @@ impl Llvm { ); set_environment_variable("PATH", &updated_path)?; } + #[cfg(unix)] + if cfg!(unix) { + let espup_dir = BaseDirs::new().unwrap().home_dir().join(".espup"); + + if espup_dir.exists() { + remove_dir_all(espup_dir.display().to_string()) + .map_err(|_| Error::RemoveDirectory(espup_dir.display().to_string()))?; + } + } let path = toolchain_path.join(CLANG_NAME); remove_dir_all(&path) .map_err(|_| Error::RemoveDirectory(path.display().to_string()))?;