Skip to content

Commit 5e032e5

Browse files
committed
Add a bootstrap option for LLVM with zstd. Defaults to true on Linux and false elsewhere.
1 parent aa3ab81 commit 5e032e5

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

config.example.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,11 @@
713713
# option will override this if set.
714714
#llvm-libunwind = 'no'
715715

716+
# Global default for llvm-libzstd for all targets. See the target-specific
717+
# documentation for llvm-libzstd below. Note that the target-specific
718+
# option will override this if set.
719+
#llvm-libzstd = false
720+
716721
# Enable Windows Control Flow Guard checks in the standard library.
717722
# This only applies from stage 1 onwards, and only for Windows targets.
718723
#control-flow-guard = false
@@ -816,6 +821,9 @@
816821
# it must link to `libgcc_eh.a` to get a working output, and this option have no effect.
817822
#llvm-libunwind = 'no' if Linux, 'in-tree' if Fuchsia
818823

824+
# Enable LLVM to use zstd for compression.
825+
#llvm-libzstd = if linux { true } else { false }
826+
819827
# Build the sanitizer runtimes for this target.
820828
# This option will override the same option under [build] section.
821829
#sanitizers = build.sanitizers (bool)

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,13 @@ fn configure_llvm(builder: &Builder<'_>, target: TargetSelection, cfg: &mut cmak
818818
// Libraries for ELF section compression.
819819
if !target.is_windows() {
820820
cfg.define("LLVM_ENABLE_ZLIB", "ON");
821-
cfg.define("LLVM_ENABLE_ZSTD", "ON");
822-
cfg.define("LLVM_USE_STATIC_ZSTD", "TRUE");
823821
} else {
824822
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
825-
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
823+
}
824+
825+
if builder.config.llvm_libzstd(target) {
826+
cfg.define("LLVM_ENABLE_ZSTD", "FORCE_ON");
827+
cfg.define("LLVM_USE_STATIC_ZSTD", "TRUE");
826828
}
827829

828830
if let Some(ref linker) = builder.config.llvm_use_linker {

src/bootstrap/src/core/config/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ pub struct Config {
280280
pub llvm_profile_use: Option<String>,
281281
pub llvm_profile_generate: bool,
282282
pub llvm_libunwind_default: Option<LlvmLibunwind>,
283+
pub llvm_libzstd_default: Option<bool>,
283284
pub enable_bolt_settings: bool,
284285

285286
pub reproducible_artifacts: Vec<String>,
@@ -550,6 +551,7 @@ pub struct Target {
550551
/// Some(path to FileCheck) if one was specified.
551552
pub llvm_filecheck: Option<PathBuf>,
552553
pub llvm_libunwind: Option<LlvmLibunwind>,
554+
pub llvm_libzstd: Option<bool>,
553555
pub cc: Option<PathBuf>,
554556
pub cxx: Option<PathBuf>,
555557
pub ar: Option<PathBuf>,
@@ -1106,6 +1108,7 @@ define_config! {
11061108
jemalloc: Option<bool> = "jemalloc",
11071109
test_compare_mode: Option<bool> = "test-compare-mode",
11081110
llvm_libunwind: Option<String> = "llvm-libunwind",
1111+
llvm_libzstd: Option<bool> = "llvm-libzstd",
11091112
control_flow_guard: Option<bool> = "control-flow-guard",
11101113
ehcont_guard: Option<bool> = "ehcont-guard",
11111114
new_symbol_mangling: Option<bool> = "new-symbol-mangling",
@@ -1132,6 +1135,7 @@ define_config! {
11321135
llvm_has_rust_patches: Option<bool> = "llvm-has-rust-patches",
11331136
llvm_filecheck: Option<String> = "llvm-filecheck",
11341137
llvm_libunwind: Option<String> = "llvm-libunwind",
1138+
llvm_libzstd: Option<bool> = "llvm-libzstd",
11351139
sanitizers: Option<bool> = "sanitizers",
11361140
profiler: Option<StringOrBool> = "profiler",
11371141
rpath: Option<bool> = "rpath",
@@ -1633,6 +1637,7 @@ impl Config {
16331637
jemalloc,
16341638
test_compare_mode,
16351639
llvm_libunwind,
1640+
llvm_libzstd,
16361641
control_flow_guard,
16371642
ehcont_guard,
16381643
new_symbol_mangling,
@@ -1719,6 +1724,7 @@ impl Config {
17191724
set(&mut config.ehcont_guard, ehcont_guard);
17201725
config.llvm_libunwind_default =
17211726
llvm_libunwind.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
1727+
config.llvm_libzstd_default = llvm_libzstd;
17221728

17231729
if let Some(ref backends) = codegen_backends {
17241730
let available_backends = ["llvm", "cranelift", "gcc"];
@@ -1925,6 +1931,7 @@ impl Config {
19251931
panic!("failed to parse target.{triple}.llvm-libunwind")
19261932
})
19271933
});
1934+
target.llvm_libzstd = cfg.llvm_libzstd;
19281935
if let Some(s) = cfg.no_std {
19291936
target.no_std = s;
19301937
}
@@ -2411,6 +2418,14 @@ impl Config {
24112418
})
24122419
}
24132420

2421+
pub fn llvm_libzstd(&self, target: TargetSelection) -> bool {
2422+
self.target_config
2423+
.get(&target)
2424+
.and_then(|t| t.llvm_libzstd)
2425+
.or(self.llvm_libzstd_default)
2426+
.unwrap_or(target.contains("linux"))
2427+
}
2428+
24142429
pub fn split_debuginfo(&self, target: TargetSelection) -> SplitDebuginfo {
24152430
self.target_config
24162431
.get(&target)
@@ -2715,6 +2730,7 @@ fn check_incompatible_options_for_ci_rustc(rust: &Rust) -> Result<(), String> {
27152730
remap_debuginfo: _,
27162731
test_compare_mode: _,
27172732
llvm_libunwind: _,
2733+
llvm_libzstd: _,
27182734
control_flow_guard: _,
27192735
ehcont_guard: _,
27202736
new_symbol_mangling: _,

0 commit comments

Comments
 (0)