Skip to content

Commit 6e9afb8

Browse files
committed
Enable zstd for debug compression.
Set LLVM_ENABLE_ZSTD alongside LLVM_ENABLE_ZLIB so that --compress-debug-sections=zstd is an option. Use static linking to avoid a new runtime dependency. Add an llvm.libzstd bootstrap option for LLVM with zstd. Set it off by default except for the dist builder. Handle llvm-config --system-libs output that contains static libraries.
1 parent 97e7252 commit 6e9afb8

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

Diff for: compiler/rustc_llvm/build.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,32 @@ fn main() {
259259
cmd.args(&components);
260260

261261
for lib in output(&mut cmd).split_whitespace() {
262+
let mut is_static = false;
262263
let name = if let Some(stripped) = lib.strip_prefix("-l") {
263264
stripped
264265
} else if let Some(stripped) = lib.strip_prefix('-') {
265266
stripped
266267
} else if Path::new(lib).exists() {
267268
// On MSVC llvm-config will print the full name to libraries, but
268269
// we're only interested in the name part
269-
let name = Path::new(lib).file_name().unwrap().to_str().unwrap();
270-
name.trim_end_matches(".lib")
270+
// On Unix when we get a static library llvm-config will print the
271+
// full name and we *are* interested in the path, but we need to
272+
// handle it separately. For example, when statically linking to
273+
// libzstd llvm-config will output something like
274+
// -lrt -ldl -lm -lz /usr/local/lib/libzstd.a -lxml2
275+
// and we transform the zstd part into
276+
// cargo:rustc-link-search-native=/usr/local/lib
277+
// cargo:rustc-link-lib=static=zstd
278+
let path = Path::new(lib);
279+
if lib.ends_with(".a") {
280+
is_static = true;
281+
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
282+
let name = path.file_stem().unwrap().to_str().unwrap();
283+
name.trim_start_matches("lib")
284+
} else {
285+
let name = path.file_name().unwrap().to_str().unwrap();
286+
name.trim_end_matches(".lib")
287+
}
271288
} else if lib.ends_with(".lib") {
272289
// Some MSVC libraries just come up with `.lib` tacked on, so chop
273290
// that off
@@ -285,7 +302,13 @@ fn main() {
285302
continue;
286303
}
287304

288-
let kind = if name.starts_with("LLVM") { llvm_kind } else { "dylib" };
305+
let kind = if name.starts_with("LLVM") {
306+
llvm_kind
307+
} else if is_static {
308+
"static"
309+
} else {
310+
"dylib"
311+
};
289312
println!("cargo:rustc-link-lib={kind}={name}");
290313
}
291314

Diff for: config.example.toml

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
# library provided by LLVM.
8888
#static-libstdcpp = false
8989

90+
# Enable LLVM to use zstd for compression.
91+
#libzstd = false
92+
9093
# Whether to use Ninja to build LLVM. This runs much faster than make.
9194
#ninja = true
9295

Diff for: src/bootstrap/download-ci-llvm-stamp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Change this file to make users of the `download-ci-llvm` configuration download
22
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
33

4-
Last change is for: https://github.com/rust-lang/rust/pull/126298
4+
Last change is for: https://github.com/rust-lang/rust/pull/125642

Diff for: src/bootstrap/src/core/build_steps/llvm.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ impl Step for Llvm {
368368
cfg.define("LLVM_PROFDATA_FILE", path);
369369
}
370370

371-
// Disable zstd to avoid a dependency on libzstd.so.
372-
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
373-
371+
// Libraries for ELF section compression.
374372
if !target.is_windows() {
375373
cfg.define("LLVM_ENABLE_ZLIB", "ON");
376374
} else {
@@ -824,6 +822,14 @@ fn configure_llvm(builder: &Builder<'_>, target: TargetSelection, cfg: &mut cmak
824822
}
825823
}
826824

825+
// Libraries for ELF section compression.
826+
if builder.config.llvm_libzstd {
827+
cfg.define("LLVM_ENABLE_ZSTD", "FORCE_ON");
828+
cfg.define("LLVM_USE_STATIC_ZSTD", "TRUE");
829+
} else {
830+
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
831+
}
832+
827833
if let Some(ref linker) = builder.config.llvm_use_linker {
828834
cfg.define("LLVM_USE_LINKER", linker);
829835
}

Diff for: src/bootstrap/src/core/config/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub struct Config {
218218
pub llvm_thin_lto: bool,
219219
pub llvm_release_debuginfo: bool,
220220
pub llvm_static_stdcpp: bool,
221+
pub llvm_libzstd: bool,
221222
/// `None` if `llvm_from_ci` is true and we haven't yet downloaded llvm.
222223
#[cfg(not(test))]
223224
llvm_link_shared: Cell<Option<bool>>,
@@ -878,6 +879,7 @@ define_config! {
878879
plugins: Option<bool> = "plugins",
879880
ccache: Option<StringOrBool> = "ccache",
880881
static_libstdcpp: Option<bool> = "static-libstdcpp",
882+
libzstd: Option<bool> = "libzstd",
881883
ninja: Option<bool> = "ninja",
882884
targets: Option<String> = "targets",
883885
experimental_targets: Option<String> = "experimental-targets",
@@ -1153,6 +1155,7 @@ impl Config {
11531155
llvm_optimize: true,
11541156
ninja_in_file: true,
11551157
llvm_static_stdcpp: false,
1158+
llvm_libzstd: false,
11561159
backtrace: true,
11571160
rust_optimize: RustOptimize::Bool(true),
11581161
rust_optimize_tests: true,
@@ -1787,6 +1790,7 @@ impl Config {
17871790
plugins,
17881791
ccache,
17891792
static_libstdcpp,
1793+
libzstd,
17901794
ninja,
17911795
targets,
17921796
experimental_targets,
@@ -1821,6 +1825,7 @@ impl Config {
18211825
set(&mut config.llvm_thin_lto, thin_lto);
18221826
set(&mut config.llvm_release_debuginfo, release_debuginfo);
18231827
set(&mut config.llvm_static_stdcpp, static_libstdcpp);
1828+
set(&mut config.llvm_libzstd, libzstd);
18241829
if let Some(v) = link_shared {
18251830
config.llvm_link_shared.set(Some(v));
18261831
}
@@ -1871,6 +1876,7 @@ impl Config {
18711876
check_ci_llvm!(optimize_toml);
18721877
check_ci_llvm!(thin_lto);
18731878
check_ci_llvm!(release_debuginfo);
1879+
check_ci_llvm!(libzstd);
18741880
check_ci_llvm!(targets);
18751881
check_ci_llvm!(experimental_targets);
18761882
check_ci_llvm!(clang_cl);

Diff for: src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
220220
severity: ChangeSeverity::Warning,
221221
summary: "For tarball sources, default value for `rust.channel` will be taken from `src/ci/channel` file.",
222222
},
223+
ChangeInfo {
224+
change_id: 125642,
225+
severity: ChangeSeverity::Info,
226+
summary: "New option `llvm.libzstd` to control whether llvm is built with zstd support.",
227+
},
223228
];

Diff for: src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ ENV RUST_CONFIGURE_ARGS \
7979
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
8080
--set llvm.thin-lto=true \
8181
--set llvm.ninja=false \
82+
--set llvm.libzstd=true \
8283
--set rust.jemalloc \
8384
--set rust.use-lld=true \
8485
--set rust.lto=thin \

0 commit comments

Comments
 (0)