Support passing cflags/cxxflags/ldflags to LLVM build
This may be needed with some host compilers.
This commit is contained in:
parent
0bc0015f20
commit
c6632725c1
4 changed files with 33 additions and 1 deletions
|
@ -90,6 +90,11 @@
|
|||
# with clang-cl, so this is special in that it only compiles LLVM with clang-cl
|
||||
#clang-cl = '/path/to/clang-cl.exe'
|
||||
|
||||
# Pass extra compiler and linker flags to the LLVM CMake build.
|
||||
#cflags = "-fextra-flag"
|
||||
#cxxflags = "-fextra-flag"
|
||||
#ldflags = "-Wl,extra-flag"
|
||||
|
||||
# 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
|
||||
|
|
|
@ -82,6 +82,9 @@ pub struct Config {
|
|||
pub lldb_enabled: bool,
|
||||
pub llvm_tools_enabled: bool,
|
||||
|
||||
pub llvm_cflags: Option<String>,
|
||||
pub llvm_cxxflags: Option<String>,
|
||||
pub llvm_ldflags: Option<String>,
|
||||
pub llvm_use_libcxx: bool,
|
||||
|
||||
// rust codegen options
|
||||
|
@ -254,6 +257,9 @@ struct Llvm {
|
|||
link_shared: Option<bool>,
|
||||
version_suffix: Option<String>,
|
||||
clang_cl: Option<String>,
|
||||
cflags: Option<String>,
|
||||
cxxflags: Option<String>,
|
||||
ldflags: Option<String>,
|
||||
use_libcxx: Option<bool>,
|
||||
}
|
||||
|
||||
|
@ -516,6 +522,10 @@ 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();
|
||||
|
||||
config.llvm_cflags = llvm.cflags.clone();
|
||||
config.llvm_cxxflags = llvm.cxxflags.clone();
|
||||
config.llvm_ldflags = llvm.ldflags.clone();
|
||||
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,10 @@ 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++")
|
||||
|
||||
o("cflags", "llvm.cflags", "build LLVM with these extra compiler flags")
|
||||
o("cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
|
||||
o("ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")
|
||||
|
||||
# Optimization and debugging options. These may be overridden by the release
|
||||
# channel, etc.
|
||||
o("optimize", "rust.optimize", "build optimized rust code")
|
||||
|
|
|
@ -358,7 +358,11 @@ fn configure_cmake(builder: &Builder,
|
|||
}
|
||||
|
||||
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
|
||||
cfg.define("CMAKE_C_FLAGS", builder.cflags(target, GitRepo::Llvm).join(" "));
|
||||
let mut cflags = builder.cflags(target, GitRepo::Llvm).join(" ");
|
||||
if let Some(ref s) = builder.config.llvm_cxxflags {
|
||||
cflags.push_str(&format!(" {}", s));
|
||||
}
|
||||
cfg.define("CMAKE_C_FLAGS", cflags);
|
||||
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
|
||||
if builder.config.llvm_static_stdcpp &&
|
||||
!target.contains("windows") &&
|
||||
|
@ -366,6 +370,9 @@ fn configure_cmake(builder: &Builder,
|
|||
{
|
||||
cxxflags.push_str(" -static-libstdc++");
|
||||
}
|
||||
if let Some(ref s) = builder.config.llvm_cxxflags {
|
||||
cxxflags.push_str(&format!(" {}", s));
|
||||
}
|
||||
cfg.define("CMAKE_CXX_FLAGS", cxxflags);
|
||||
if let Some(ar) = builder.ar(target) {
|
||||
if ar.is_absolute() {
|
||||
|
@ -383,6 +390,12 @@ fn configure_cmake(builder: &Builder,
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(ref s) = builder.config.llvm_ldflags {
|
||||
cfg.define("CMAKE_SHARED_LINKER_FLAGS", s);
|
||||
cfg.define("CMAKE_MODULE_LINKER_FLAGS", s);
|
||||
cfg.define("CMAKE_EXE_LINKER_FLAGS", s);
|
||||
}
|
||||
|
||||
if env::var_os("SCCACHE_ERROR_LOG").is_some() {
|
||||
cfg.env("RUST_LOG", "sccache=warn");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue