Skip to content

Commit

Permalink
Provide the option to use libc++ even on all platforms
Browse files Browse the repository at this point in the history
This is the default on platforms which use libc++ as the default C++
library but this option allows using libc++ on others as well.
  • Loading branch information
petrhosek committed Jan 6, 2019
1 parent 36500de commit 7306b87
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
# with clang-cl, so this is special in that it only compiles LLVM with clang-cl
#clang-cl = '/path/to/clang-cl.exe'

# Use libc++ when building LLVM instead of libstdc++. This is the default on
# platforms already use libc++ as the default C++ library, but this option
# allows you to use libc++ even on platforms when it's not. You need to ensure
# that your host compiler ships with libc++.
#use-libcxx = true

# =============================================================================
# General build configuration options
# =============================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ pub fn build_codegen_backend(builder: &Builder,
if builder.config.llvm_link_shared {
cargo.env("LLVM_LINK_SHARED", "1");
}
if builder.config.llvm_use_libcxx {
cargo.env("LLVM_USE_LIBCXX", "1");
}
}
_ => panic!("unknown backend: {}", backend),
}
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub struct Config {
pub lldb_enabled: bool,
pub llvm_tools_enabled: bool,

pub llvm_use_libcxx: bool,

// rust codegen options
pub rust_optimize: bool,
pub rust_codegen_units: Option<u32>,
Expand Down Expand Up @@ -252,6 +254,7 @@ struct Llvm {
link_shared: Option<bool>,
version_suffix: Option<String>,
clang_cl: Option<String>,
use_libcxx: Option<bool>,
}

#[derive(Deserialize, Default, Clone)]
Expand Down Expand Up @@ -513,6 +516,7 @@ impl Config {
config.llvm_link_jobs = llvm.link_jobs;
config.llvm_version_suffix = llvm.version_suffix.clone();
config.llvm_clang_cl = llvm.clang_cl.clone();
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
}

if let Some(ref rust) = toml.rust {
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def v(*args):
o("lld", "rust.lld", "build lld")
o("lldb", "rust.lldb", "build lldb")
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
o("use-libcxx", "llvm.use_libcxx", "build LLVM with libc++")

# Optimization and debugging options. These may be overridden by the release
# channel, etc.
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ fn main() {
}

let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");

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

0 comments on commit 7306b87

Please sign in to comment.