Skip to content

Commit 0ddccf1

Browse files
authored
Rollup merge of rust-lang#57370 - petrhosek:llvm-flags, r=alexcrichton
Support passing cflags/cxxflags/ldflags to LLVM build This may be needed with some host compilers.
2 parents a319b86 + c663272 commit 0ddccf1

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

config.toml.example

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
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+
# Pass extra compiler and linker flags to the LLVM CMake build.
94+
#cflags = "-fextra-flag"
95+
#cxxflags = "-fextra-flag"
96+
#ldflags = "-Wl,extra-flag"
97+
9398
# Use libc++ when building LLVM instead of libstdc++. This is the default on
9499
# platforms already use libc++ as the default C++ library, but this option
95100
# allows you to use libc++ even on platforms when it's not. You need to ensure

src/bootstrap/config.rs

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

85+
pub llvm_cflags: Option<String>,
86+
pub llvm_cxxflags: Option<String>,
87+
pub llvm_ldflags: Option<String>,
8588
pub llvm_use_libcxx: bool,
8689

8790
// rust codegen options
@@ -254,6 +257,9 @@ struct Llvm {
254257
link_shared: Option<bool>,
255258
version_suffix: Option<String>,
256259
clang_cl: Option<String>,
260+
cflags: Option<String>,
261+
cxxflags: Option<String>,
262+
ldflags: Option<String>,
257263
use_libcxx: Option<bool>,
258264
}
259265

@@ -516,6 +522,10 @@ impl Config {
516522
config.llvm_link_jobs = llvm.link_jobs;
517523
config.llvm_version_suffix = llvm.version_suffix.clone();
518524
config.llvm_clang_cl = llvm.clang_cl.clone();
525+
526+
config.llvm_cflags = llvm.cflags.clone();
527+
config.llvm_cxxflags = llvm.cxxflags.clone();
528+
config.llvm_ldflags = llvm.ldflags.clone();
519529
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
520530
}
521531

src/bootstrap/configure.py

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def v(*args):
6464
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
6565
o("use-libcxx", "llvm.use_libcxx", "build LLVM with libc++")
6666

67+
o("cflags", "llvm.cflags", "build LLVM with these extra compiler flags")
68+
o("cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
69+
o("ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")
70+
6771
# Optimization and debugging options. These may be overridden by the release
6872
# channel, etc.
6973
o("optimize", "rust.optimize", "build optimized rust code")

src/bootstrap/native.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,21 @@ fn configure_cmake(builder: &Builder,
358358
}
359359

360360
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
361-
cfg.define("CMAKE_C_FLAGS", builder.cflags(target, GitRepo::Llvm).join(" "));
361+
let mut cflags = builder.cflags(target, GitRepo::Llvm).join(" ");
362+
if let Some(ref s) = builder.config.llvm_cxxflags {
363+
cflags.push_str(&format!(" {}", s));
364+
}
365+
cfg.define("CMAKE_C_FLAGS", cflags);
362366
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
363367
if builder.config.llvm_static_stdcpp &&
364368
!target.contains("windows") &&
365369
!target.contains("netbsd")
366370
{
367371
cxxflags.push_str(" -static-libstdc++");
368372
}
373+
if let Some(ref s) = builder.config.llvm_cxxflags {
374+
cxxflags.push_str(&format!(" {}", s));
375+
}
369376
cfg.define("CMAKE_CXX_FLAGS", cxxflags);
370377
if let Some(ar) = builder.ar(target) {
371378
if ar.is_absolute() {
@@ -383,6 +390,12 @@ fn configure_cmake(builder: &Builder,
383390
}
384391
}
385392

393+
if let Some(ref s) = builder.config.llvm_ldflags {
394+
cfg.define("CMAKE_SHARED_LINKER_FLAGS", s);
395+
cfg.define("CMAKE_MODULE_LINKER_FLAGS", s);
396+
cfg.define("CMAKE_EXE_LINKER_FLAGS", s);
397+
}
398+
386399
if env::var_os("SCCACHE_ERROR_LOG").is_some() {
387400
cfg.env("RUST_LOG", "sccache=warn");
388401
}

0 commit comments

Comments
 (0)