Skip to content

Commit 76d247c

Browse files
committed
Auto merge of #87297 - ZuseZ4:new_build_flags, r=Mark-Simulacrum
add two new build flags to build clang and enable llvm plugins Based on the discussion here: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Add.20configure.20flag.20to.20build.20clang/near/246439138 It allows building clang (which already is part of the llvm-project) based on the same llvm version which we use to build rustc. It also allows enabling llvm's plugin interface, which is required for https://enzyme.mit.edu/. There is no further integration beside of this basic build support.
2 parents b53a93d + 8f6827f commit 76d247c

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

config.toml.example

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ changelog-seen = 2
6868
# Indicates whether the LLVM assertions are enabled or not
6969
#assertions = false
7070

71+
# Indicates whether the LLVM plugin is enabled or not
72+
#plugins = false
73+
7174
# Indicates whether ccache is used when building LLVM
7275
#ccache = false
7376
# or alternatively ...
@@ -145,6 +148,9 @@ changelog-seen = 2
145148
# Whether to include the Polly optimizer.
146149
#polly = false
147150

151+
# Whether to build the clang compiler.
152+
#clang = false
153+
148154
# =============================================================================
149155
# General build configuration options
150156
# =============================================================================

src/bootstrap/config.rs

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct Config {
9090
// llvm codegen options
9191
pub llvm_skip_rebuild: bool,
9292
pub llvm_assertions: bool,
93+
pub llvm_plugins: bool,
9394
pub llvm_optimize: bool,
9495
pub llvm_thin_lto: bool,
9596
pub llvm_release_debuginfo: bool,
@@ -104,6 +105,7 @@ pub struct Config {
104105
pub llvm_use_linker: Option<String>,
105106
pub llvm_allow_old_toolchain: bool,
106107
pub llvm_polly: bool,
108+
pub llvm_clang: bool,
107109
pub llvm_from_ci: bool,
108110

109111
pub use_lld: bool,
@@ -415,6 +417,7 @@ struct Llvm {
415417
thin_lto: Option<bool>,
416418
release_debuginfo: Option<bool>,
417419
assertions: Option<bool>,
420+
plugins: Option<bool>,
418421
ccache: Option<StringOrBool>,
419422
version_check: Option<bool>,
420423
static_libstdcpp: Option<bool>,
@@ -432,6 +435,7 @@ struct Llvm {
432435
use_linker: Option<String>,
433436
allow_old_toolchain: Option<bool>,
434437
polly: Option<bool>,
438+
clang: Option<bool>,
435439
download_ci_llvm: Option<StringOrBool>,
436440
}
437441

@@ -702,6 +706,7 @@ impl Config {
702706
// Store off these values as options because if they're not provided
703707
// we'll infer default values for them later
704708
let mut llvm_assertions = None;
709+
let mut llvm_plugins = None;
705710
let mut debug = None;
706711
let mut debug_assertions = None;
707712
let mut debug_assertions_std = None;
@@ -724,6 +729,7 @@ impl Config {
724729
}
725730
set(&mut config.ninja_in_file, llvm.ninja);
726731
llvm_assertions = llvm.assertions;
732+
llvm_plugins = llvm.plugins;
727733
llvm_skip_rebuild = llvm_skip_rebuild.or(llvm.skip_rebuild);
728734
set(&mut config.llvm_optimize, llvm.optimize);
729735
set(&mut config.llvm_thin_lto, llvm.thin_lto);
@@ -744,6 +750,7 @@ impl Config {
744750
config.llvm_use_linker = llvm.use_linker.clone();
745751
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.unwrap_or(false);
746752
config.llvm_polly = llvm.polly.unwrap_or(false);
753+
config.llvm_clang = llvm.clang.unwrap_or(false);
747754
config.llvm_from_ci = match llvm.download_ci_llvm {
748755
Some(StringOrBool::String(s)) => {
749756
assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s);
@@ -790,6 +797,8 @@ impl Config {
790797
check_ci_llvm!(llvm.use_linker);
791798
check_ci_llvm!(llvm.allow_old_toolchain);
792799
check_ci_llvm!(llvm.polly);
800+
check_ci_llvm!(llvm.clang);
801+
check_ci_llvm!(llvm.plugins);
793802

794803
// CI-built LLVM can be either dynamic or static.
795804
let ci_llvm = config.out.join(&*config.build.triple).join("ci-llvm");
@@ -952,6 +961,7 @@ impl Config {
952961

953962
config.llvm_skip_rebuild = llvm_skip_rebuild.unwrap_or(false);
954963
config.llvm_assertions = llvm_assertions.unwrap_or(false);
964+
config.llvm_plugins = llvm_plugins.unwrap_or(false);
955965
config.rust_optimize = optimize.unwrap_or(true);
956966

957967
let default = debug == Some(true);

src/bootstrap/configure.py

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def v(*args):
5757
o("profiler", "build.profiler", "build the profiler runtime")
5858
o("full-tools", None, "enable all tools")
5959
o("lld", "rust.lld", "build lld")
60+
o("clang", "llvm.clang", "build clang")
6061
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
6162
o("use-libcxx", "llvm.use-libcxx", "build LLVM with libc++")
6263
o("control-flow-guard", "rust.control-flow-guard", "Enable Control Flow Guard")
@@ -72,6 +73,7 @@ def v(*args):
7273
o("optimize", "rust.optimize", "build optimized rust code")
7374
o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
7475
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
76+
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
7577
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
7678
o("llvm-release-debuginfo", "llvm.release-debuginfo", "build LLVM with debugger metadata")
7779
v("debuginfo-level", "rust.debuginfo-level", "debuginfo level for Rust code")

src/bootstrap/native.rs

+6
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ impl Step for Llvm {
169169
};
170170

171171
let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" };
172+
let plugins = if builder.config.llvm_plugins { "ON" } else { "OFF" };
172173

173174
cfg.out_dir(&out_dir)
174175
.profile(profile)
175176
.define("LLVM_ENABLE_ASSERTIONS", assertions)
177+
.define("LLVM_ENABLE_PLUGINS", plugins)
176178
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
177179
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
178180
.define("LLVM_INCLUDE_EXAMPLES", "OFF")
@@ -265,6 +267,10 @@ impl Step for Llvm {
265267
enabled_llvm_projects.push("polly");
266268
}
267269

270+
if builder.config.llvm_clang {
271+
enabled_llvm_projects.push("clang");
272+
}
273+
268274
// We want libxml to be disabled.
269275
// See https://github.com/rust-lang/rust/pull/50104
270276
cfg.define("LLVM_ENABLE_LIBXML2", "OFF");

0 commit comments

Comments
 (0)