From ca535c9ba2a7752853a8e92c7f55c4fee11c42ab Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 23 Dec 2024 18:36:55 +0800 Subject: [PATCH] Use `lld` instead of `lld-link` when using `clang` --- src/compiler/clang.rs | 21 +++++++++++++-------- src/compiler/clang_cl.rs | 15 ++++++++++++--- src/compiler/common.rs | 9 +-------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/compiler/clang.rs b/src/compiler/clang.rs index b804be1..335287c 100644 --- a/src/compiler/clang.rs +++ b/src/compiler/clang.rs @@ -1,4 +1,5 @@ use std::env; +use std::ffi::OsStr; use std::path::{Path, PathBuf}; use std::process::Command; @@ -9,7 +10,7 @@ use serde::Deserialize; use crate::compiler::common::{ adjust_canonicalization, default_build_target_from_config, get_rustflags, http_agent, - setup_cmake_env, setup_env_path, setup_llvm_tools, setup_target_compiler_and_linker_env, + setup_cmake_env, setup_env_path, setup_target_compiler_and_linker_env, }; const MSVC_SYSROOT_REPOSITORY: &str = "trcrsired/windows-msvc-sysroot"; @@ -62,7 +63,7 @@ impl Clang { let sysroot_dir = adjust_canonicalization(msvc_sysroot_dir.to_slash_lossy().to_string()); let clang_flags = format!( - "--target={target_no_vendor} -fuse-ld=lld-link -I{dir}/include -I{dir}/include/c++/stl -L{dir}/lib/{target_unknown_vendor}", + "--target={target_no_vendor} -fuse-ld=lld -I{dir}/include -I{dir}/include/c++/stl -L{dir}/lib/{target_unknown_vendor}", dir = sysroot_dir, ); cmd.env( @@ -84,8 +85,6 @@ impl Clang { let mut rustflags = get_rustflags(&workdir, target)?.unwrap_or_default(); rustflags.flags.extend([ - "-C".to_string(), - "linker-flavor=lld-link".to_string(), "-C".to_string(), "link-arg=-defaultlib:oldnames".to_string(), ]); @@ -263,18 +262,16 @@ set(CMAKE_SYSTEM_PROCESSOR {processor}) set(CMAKE_C_COMPILER clang CACHE FILEPATH "") set(CMAKE_CXX_COMPILER clang++ CACHE FILEPATH "") -set(CMAKE_LINKER lld-link CACHE FILEPATH "") set(CMAKE_RC_COMPILER llvm-rc CACHE FILEPATH "") set(COMPILE_FLAGS --target={target_no_vendor} - -fuse-ld=lld-link + -fuse-ld=lld -I{dir}/include -I{dir}/include/c++/stl) set(LINK_FLAGS - /manifest:no - -libpath:"{dir}/lib/{target_unknown_vendor}") + -L"{dir}/lib/{target_unknown_vendor}") "#, dir = sysroot_dir, ); @@ -293,3 +290,11 @@ struct GitHubReleaseAsset { browser_download_url: String, name: String, } + +fn setup_llvm_tools(env_path: &OsStr, cache_dir: &Path) -> Result<()> { + use crate::compiler::common::symlink_llvm_tool; + + symlink_llvm_tool("rust-lld", "lld", env_path, cache_dir)?; + symlink_llvm_tool("llvm-ar", "llvm-dlltool", env_path, cache_dir)?; + Ok(()) +} diff --git a/src/compiler/clang_cl.rs b/src/compiler/clang_cl.rs index 05cc84f..7c955a8 100644 --- a/src/compiler/clang_cl.rs +++ b/src/compiler/clang_cl.rs @@ -14,7 +14,7 @@ use xwin::util::ProgressTarget; use crate::compiler::common::{ adjust_canonicalization, default_build_target_from_config, get_rustflags, http_agent, - setup_cmake_env, setup_env_path, setup_llvm_tools, setup_target_compiler_and_linker_env, + setup_cmake_env, setup_env_path, setup_target_compiler_and_linker_env, }; use crate::options::XWinOptions; @@ -398,7 +398,7 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${{CMAKE_CURRENT_LIST_DIR}}/override.cmake") } #[cfg(target_os = "macos")] -pub fn setup_clang_cl_symlink(env_path: &OsStr, cache_dir: &Path) -> Result<()> { +fn setup_clang_cl_symlink(env_path: &OsStr, cache_dir: &Path) -> Result<()> { // Try PATH first, but skip system clang let clang = which_in("clang", Some(env_path), env::current_dir()?) .ok() @@ -442,7 +442,7 @@ pub fn setup_clang_cl_symlink(env_path: &OsStr, cache_dir: &Path) -> Result<()> } #[cfg(not(target_os = "macos"))] -pub fn setup_clang_cl_symlink(env_path: &OsStr, cache_dir: &Path) -> Result<()> { +fn setup_clang_cl_symlink(env_path: &OsStr, cache_dir: &Path) -> Result<()> { if let Ok(clang) = which_in("clang", Some(env_path), env::current_dir()?) { #[cfg(windows)] { @@ -464,3 +464,12 @@ pub fn setup_clang_cl_symlink(env_path: &OsStr, cache_dir: &Path) -> Result<()> } Ok(()) } + +fn setup_llvm_tools(env_path: &OsStr, cache_dir: &Path) -> Result<()> { + use crate::compiler::common::symlink_llvm_tool; + + symlink_llvm_tool("rust-lld", "lld-link", env_path, cache_dir)?; + symlink_llvm_tool("llvm-ar", "llvm-lib", env_path, cache_dir)?; + symlink_llvm_tool("llvm-ar", "llvm-dlltool", env_path, cache_dir)?; + Ok(()) +} diff --git a/src/compiler/common.rs b/src/compiler/common.rs index b7e8c1a..864891f 100644 --- a/src/compiler/common.rs +++ b/src/compiler/common.rs @@ -29,13 +29,6 @@ pub fn setup_env_path(cache_dir: &Path) -> Result { Ok(env::join_paths(env_paths)?) } -pub fn setup_llvm_tools(env_path: &OsStr, cache_dir: &Path) -> Result<()> { - symlink_llvm_tool("rust-lld", "lld-link", env_path, cache_dir)?; - symlink_llvm_tool("llvm-ar", "llvm-lib", env_path, cache_dir)?; - symlink_llvm_tool("llvm-ar", "llvm-dlltool", env_path, cache_dir)?; - Ok(()) -} - pub fn setup_target_compiler_and_linker_env( cmd: &mut Command, env_target: &str, @@ -76,7 +69,7 @@ pub fn rustc_target_bin_dir() -> Result { } /// Symlink Rust provided llvm tool component -fn symlink_llvm_tool( +pub fn symlink_llvm_tool( tool: &str, link_name: &str, env_path: &OsStr,