Skip to content

Commit

Permalink
skip the linkage of libstdc++ in rustc_llvm
Browse files Browse the repository at this point in the history
Since we already statically link to libLLVM.so (which includes libstdc++),
we shouldn't need to link libstdc++ again for rustc_llvm.

Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed May 22, 2024
1 parent e875391 commit fa101f5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
36 changes: 0 additions & 36 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,26 +327,8 @@ fn main() {
}
}

let llvm_static_stdcpp = tracked_env_var_os("LLVM_STATIC_STDCPP");
let llvm_use_libcxx = tracked_env_var_os("LLVM_USE_LIBCXX");

let stdcppname = if target.contains("openbsd") {
if target.contains("sparc64") { "estdc++" } else { "c++" }
} else if target.contains("darwin")
|| target.contains("freebsd")
|| target.contains("windows-gnullvm")
|| target.contains("aix")
{
"c++"
} else if target.contains("netbsd") && llvm_static_stdcpp.is_some() {
// NetBSD uses a separate library when relocation is required
"stdc++_p"
} else if llvm_use_libcxx.is_some() {
"c++"
} else {
"stdc++"
};

// RISC-V GCC erroneously requires libatomic for sub-word
// atomic operations. Some BSD uses Clang as its system
// compiler and provides no libatomic in its base system so
Expand All @@ -355,24 +337,6 @@ fn main() {
println!("cargo:rustc-link-lib=atomic");
}

// C++ runtime library
if !target.contains("msvc") {
if let Some(s) = llvm_static_stdcpp {
assert!(!cxxflags.contains("stdlib=libc++"));
let path = PathBuf::from(s);
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
if target.contains("windows") {
println!("cargo:rustc-link-lib=static:-bundle={stdcppname}");
} else {
println!("cargo:rustc-link-lib=static={stdcppname}");
}
} else if cxxflags.contains("stdlib=libc++") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib={stdcppname}");
}
}

// libc++abi and libunwind have to be specified explicitly on AIX.
if target.contains("aix") {
println!("cargo:rustc-link-lib=c++abi");
Expand Down
17 changes: 0 additions & 17 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,23 +1201,6 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
cargo.env("LLVM_LINKER_FLAGS", llvm_linker_flags);
}

// Building with a static libstdc++ is only supported on linux right now,
// not for MSVC or macOS
if builder.config.llvm_static_stdcpp
&& !target.contains("freebsd")
&& !target.is_msvc()
&& !target.contains("apple")
&& !target.contains("solaris")
{
let file = compiler_file(
builder,
&builder.cxx(target).unwrap(),
target,
CLang::Cxx,
"libstdc++.a",
);
cargo.env("LLVM_STATIC_STDCPP", file);
}
if builder.llvm_link_shared() {
cargo.env("LLVM_LINK_SHARED", "1");
}
Expand Down

0 comments on commit fa101f5

Please sign in to comment.