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 <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed May 22, 2024
1 parent e875391 commit 374e943
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
22 changes: 0 additions & 22 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ 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") {
Expand All @@ -338,9 +337,6 @@ fn main() {
|| 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 {
Expand All @@ -355,24 +351,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 374e943

Please sign in to comment.