From 9c0234d118b1d5769edd078a2aea258bd7b8d58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20L=C3=B6thberg?= Date: Thu, 27 Jun 2024 15:05:44 +0200 Subject: [PATCH] Download both the release artifacts in extended mode for LLVM >= 17 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Espressif-provided LLVM toolchain no longer has the libs-only tarball as a strict subset of the full tarball. Instead the "full" tarball now contains a clang with libclang built in. To work around this we now need to get _both_ tarballs if we're in extended LLVM mode. Cf. https://github.com/espressif/llvm-project/issues/99 Signed-off-by: Johannes Löthberg --- CHANGELOG.md | 1 + src/toolchain/llvm.rs | 61 +++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e7db79..2965414 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed +- Make both `libclang.so` available again when installing the extended LLVM for LLVM versions >= 17 (#432) ### Changed diff --git a/src/toolchain/llvm.rs b/src/toolchain/llvm.rs index ed79d92..f37a5e0 100644 --- a/src/toolchain/llvm.rs +++ b/src/toolchain/llvm.rs @@ -32,8 +32,10 @@ pub const CLANG_NAME: &str = "xtensa-esp32-elf-clang"; pub struct Llvm { // /// If `true`, full LLVM, instead of only libraries, are installed. extended: bool, - /// LLVM Toolchain file name. - pub file_name: String, + /// LLVM libs-only toolchain file name. + pub file_name_libs: String, + /// LLVM "full" toolchain file name. + pub file_name_full: Option, /// Host triple. pub host_triple: HostTriple, /// LLVM Toolchain path. @@ -124,21 +126,31 @@ impl Llvm { "llvm-" }; - let mut file_name = format!( - "{}{}-{}.tar.xz", - name, - version, - Self::get_arch(host_triple, &version) - ); - if !extended { - if version != DEFAULT_LLVM_17_VERSION { - file_name = format!("libs_{file_name}"); - } else { - file_name = format!("libs-{}", file_name); - } - } + let (file_name_libs, file_name_full) = { + let file_name_full = format!( + "{}{}-{}.tar.xz", + name, + version, + Self::get_arch(host_triple, &version) + ); - let repository_url = format!("{DEFAULT_LLVM_REPOSITORY}/{version}/{file_name}"); + let file_name_libs = if version != DEFAULT_LLVM_17_VERSION { + format!("libs_{file_name_full}") + } else { + format!("libs-{file_name_full}") + }; + + ( + file_name_libs, + if version == DEFAULT_LLVM_15_VERSION || version == DEFAULT_LLVM_16_VERSION { + None + } else { + extended.then_some(file_name_full) + }, + ) + }; + + let repository_url = format!("{DEFAULT_LLVM_REPOSITORY}/{version}"); #[cfg(unix)] let path = toolchain_path.join(CLANG_NAME).join(&version); #[cfg(windows)] @@ -146,7 +158,8 @@ impl Llvm { Ok(Self { extended, - file_name, + file_name_libs, + file_name_full, host_triple: host_triple.clone(), path, repository_url, @@ -248,13 +261,23 @@ impl Installable for Llvm { } else { info!("Installing Xtensa LLVM"); download_file( - self.repository_url.clone(), - "idf_tool_xtensa_elf_clang.tar.xz", + format!("{}/{}", self.repository_url, self.file_name_libs), + "idf_tool_xtensa_elf_clang.libs.tar.xz", self.path.to_str().unwrap(), true, false, ) .await?; + if let Some(file_name_full) = &self.file_name_full { + download_file( + format!("{}/{}", self.repository_url, file_name_full), + "idf_tool_xtensa_elf_clang.full.tar.xz", + self.path.to_str().unwrap(), + true, + false, + ) + .await?; + } } // Set environment variables. #[cfg(windows)]