Skip to content

Commit a54c136

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

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

config.example.toml

+8
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

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

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

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

+16
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ pub struct Config {
282282
pub llvm_profile_use: Option<String>,
283283
pub llvm_profile_generate: bool,
284284
pub llvm_libunwind_default: Option<LlvmLibunwind>,
285+
pub llvm_libzstd_default: Option<bool>,
285286
pub enable_bolt_settings: bool,
286287

287288
pub reproducible_artifacts: Vec<String>,
@@ -547,6 +548,7 @@ pub struct Target {
547548
/// Some(path to FileCheck) if one was specified.
548549
pub llvm_filecheck: Option<PathBuf>,
549550
pub llvm_libunwind: Option<LlvmLibunwind>,
551+
pub llvm_libzstd: Option<bool>,
550552
pub cc: Option<PathBuf>,
551553
pub cxx: Option<PathBuf>,
552554
pub ar: Option<PathBuf>,
@@ -1103,6 +1105,7 @@ define_config! {
11031105
jemalloc: Option<bool> = "jemalloc",
11041106
test_compare_mode: Option<bool> = "test-compare-mode",
11051107
llvm_libunwind: Option<String> = "llvm-libunwind",
1108+
llvm_libzstd: Option<bool> = "llvm-libzstd",
11061109
control_flow_guard: Option<bool> = "control-flow-guard",
11071110
ehcont_guard: Option<bool> = "ehcont-guard",
11081111
new_symbol_mangling: Option<bool> = "new-symbol-mangling",
@@ -1129,6 +1132,7 @@ define_config! {
11291132
llvm_has_rust_patches: Option<bool> = "llvm-has-rust-patches",
11301133
llvm_filecheck: Option<String> = "llvm-filecheck",
11311134
llvm_libunwind: Option<String> = "llvm-libunwind",
1135+
llvm_libzstd: Option<bool> = "llvm-libzstd",
11321136
sanitizers: Option<bool> = "sanitizers",
11331137
profiler: Option<StringOrBool> = "profiler",
11341138
rpath: Option<bool> = "rpath",
@@ -1630,6 +1634,7 @@ impl Config {
16301634
jemalloc,
16311635
test_compare_mode,
16321636
llvm_libunwind,
1637+
llvm_libzstd,
16331638
control_flow_guard,
16341639
ehcont_guard,
16351640
new_symbol_mangling,
@@ -1716,6 +1721,7 @@ impl Config {
17161721
set(&mut config.ehcont_guard, ehcont_guard);
17171722
config.llvm_libunwind_default =
17181723
llvm_libunwind.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
1724+
config.llvm_libzstd_default = llvm_libzstd;
17191725

17201726
if let Some(ref backends) = codegen_backends {
17211727
let available_backends = ["llvm", "cranelift", "gcc"];
@@ -1908,6 +1914,7 @@ impl Config {
19081914
panic!("failed to parse target.{triple}.llvm-libunwind")
19091915
})
19101916
});
1917+
target.llvm_libzstd = cfg.llvm_libzstd;
19111918
if let Some(s) = cfg.no_std {
19121919
target.no_std = s;
19131920
}
@@ -2394,6 +2401,14 @@ impl Config {
23942401
})
23952402
}
23962403

2404+
pub fn llvm_libzstd(&self, target: TargetSelection) -> bool {
2405+
self.target_config
2406+
.get(&target)
2407+
.and_then(|t| t.llvm_libzstd)
2408+
.or(self.llvm_libzstd_default)
2409+
.unwrap_or(target.contains("linux"))
2410+
}
2411+
23972412
pub fn split_debuginfo(&self, target: TargetSelection) -> SplitDebuginfo {
23982413
self.target_config
23992414
.get(&target)
@@ -2698,6 +2713,7 @@ fn check_incompatible_options_for_ci_rustc(rust: &Rust) -> Result<(), String> {
26982713
remap_debuginfo: _,
26992714
test_compare_mode: _,
27002715
llvm_libunwind: _,
2716+
llvm_libzstd: _,
27012717
control_flow_guard: _,
27022718
ehcont_guard: _,
27032719
new_symbol_mangling: _,

0 commit comments

Comments
 (0)