Skip to content

Commit 7306b87

Browse files
committed
Provide the option to use libc++ even on all platforms
This is the default on platforms which use libc++ as the default C++ library but this option allows using libc++ on others as well.
1 parent 36500de commit 7306b87

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

config.toml.example

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
# with clang-cl, so this is special in that it only compiles LLVM with clang-cl
9191
#clang-cl = '/path/to/clang-cl.exe'
9292

93+
# Use libc++ when building LLVM instead of libstdc++. This is the default on
94+
# platforms already use libc++ as the default C++ library, but this option
95+
# allows you to use libc++ even on platforms when it's not. You need to ensure
96+
# that your host compiler ships with libc++.
97+
#use-libcxx = true
98+
9399
# =============================================================================
94100
# General build configuration options
95101
# =============================================================================

src/bootstrap/compile.rs

+3
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ pub fn build_codegen_backend(builder: &Builder,
752752
if builder.config.llvm_link_shared {
753753
cargo.env("LLVM_LINK_SHARED", "1");
754754
}
755+
if builder.config.llvm_use_libcxx {
756+
cargo.env("LLVM_USE_LIBCXX", "1");
757+
}
755758
}
756759
_ => panic!("unknown backend: {}", backend),
757760
}

src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub struct Config {
8282
pub lldb_enabled: bool,
8383
pub llvm_tools_enabled: bool,
8484

85+
pub llvm_use_libcxx: bool,
86+
8587
// rust codegen options
8688
pub rust_optimize: bool,
8789
pub rust_codegen_units: Option<u32>,
@@ -252,6 +254,7 @@ struct Llvm {
252254
link_shared: Option<bool>,
253255
version_suffix: Option<String>,
254256
clang_cl: Option<String>,
257+
use_libcxx: Option<bool>,
255258
}
256259

257260
#[derive(Deserialize, Default, Clone)]
@@ -513,6 +516,7 @@ impl Config {
513516
config.llvm_link_jobs = llvm.link_jobs;
514517
config.llvm_version_suffix = llvm.version_suffix.clone();
515518
config.llvm_clang_cl = llvm.clang_cl.clone();
519+
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
516520
}
517521

518522
if let Some(ref rust) = toml.rust {

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def v(*args):
6262
o("lld", "rust.lld", "build lld")
6363
o("lldb", "rust.lldb", "build lldb")
6464
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
65+
o("use-libcxx", "llvm.use_libcxx", "build LLVM with libc++")
6566

6667
# Optimization and debugging options. These may be overridden by the release
6768
# channel, etc.

src/librustc_llvm/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ fn main() {
232232
}
233233

234234
let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
235+
let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");
235236

236237
let stdcppname = if target.contains("openbsd") {
237238
// llvm-config on OpenBSD doesn't mention stdlib=libc++
@@ -241,6 +242,8 @@ fn main() {
241242
} else if target.contains("netbsd") && llvm_static_stdcpp.is_some() {
242243
// NetBSD uses a separate library when relocation is required
243244
"stdc++_pic"
245+
} else if llvm_use_libcxx.is_some() {
246+
"c++"
244247
} else {
245248
"stdc++"
246249
};

0 commit comments

Comments
 (0)