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.
This commit is contained in:
parent
97e72524a3
commit
6e9afb8dde
7 changed files with 51 additions and 7 deletions
|
@ -259,6 +259,7 @@ fn main() {
|
||||||
cmd.args(&components);
|
cmd.args(&components);
|
||||||
|
|
||||||
for lib in output(&mut cmd).split_whitespace() {
|
for lib in output(&mut cmd).split_whitespace() {
|
||||||
|
let mut is_static = false;
|
||||||
let name = if let Some(stripped) = lib.strip_prefix("-l") {
|
let name = if let Some(stripped) = lib.strip_prefix("-l") {
|
||||||
stripped
|
stripped
|
||||||
} else if let Some(stripped) = lib.strip_prefix('-') {
|
} else if let Some(stripped) = lib.strip_prefix('-') {
|
||||||
|
@ -266,8 +267,24 @@ fn main() {
|
||||||
} else if Path::new(lib).exists() {
|
} else if Path::new(lib).exists() {
|
||||||
// On MSVC llvm-config will print the full name to libraries, but
|
// On MSVC llvm-config will print the full name to libraries, but
|
||||||
// we're only interested in the name part
|
// we're only interested in the name part
|
||||||
let name = Path::new(lib).file_name().unwrap().to_str().unwrap();
|
// On Unix when we get a static library llvm-config will print the
|
||||||
|
// full name and we *are* interested in the path, but we need to
|
||||||
|
// handle it separately. For example, when statically linking to
|
||||||
|
// libzstd llvm-config will output something like
|
||||||
|
// -lrt -ldl -lm -lz /usr/local/lib/libzstd.a -lxml2
|
||||||
|
// and we transform the zstd part into
|
||||||
|
// cargo:rustc-link-search-native=/usr/local/lib
|
||||||
|
// cargo:rustc-link-lib=static=zstd
|
||||||
|
let path = Path::new(lib);
|
||||||
|
if lib.ends_with(".a") {
|
||||||
|
is_static = true;
|
||||||
|
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
|
||||||
|
let name = path.file_stem().unwrap().to_str().unwrap();
|
||||||
|
name.trim_start_matches("lib")
|
||||||
|
} else {
|
||||||
|
let name = path.file_name().unwrap().to_str().unwrap();
|
||||||
name.trim_end_matches(".lib")
|
name.trim_end_matches(".lib")
|
||||||
|
}
|
||||||
} else if lib.ends_with(".lib") {
|
} else if lib.ends_with(".lib") {
|
||||||
// Some MSVC libraries just come up with `.lib` tacked on, so chop
|
// Some MSVC libraries just come up with `.lib` tacked on, so chop
|
||||||
// that off
|
// that off
|
||||||
|
@ -285,7 +302,13 @@ fn main() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let kind = if name.starts_with("LLVM") { llvm_kind } else { "dylib" };
|
let kind = if name.starts_with("LLVM") {
|
||||||
|
llvm_kind
|
||||||
|
} else if is_static {
|
||||||
|
"static"
|
||||||
|
} else {
|
||||||
|
"dylib"
|
||||||
|
};
|
||||||
println!("cargo:rustc-link-lib={kind}={name}");
|
println!("cargo:rustc-link-lib={kind}={name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,9 @@
|
||||||
# library provided by LLVM.
|
# library provided by LLVM.
|
||||||
#static-libstdcpp = false
|
#static-libstdcpp = false
|
||||||
|
|
||||||
|
# Enable LLVM to use zstd for compression.
|
||||||
|
#libzstd = false
|
||||||
|
|
||||||
# Whether to use Ninja to build LLVM. This runs much faster than make.
|
# Whether to use Ninja to build LLVM. This runs much faster than make.
|
||||||
#ninja = true
|
#ninja = true
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Change this file to make users of the `download-ci-llvm` configuration download
|
Change this file to make users of the `download-ci-llvm` configuration download
|
||||||
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
|
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
|
||||||
|
|
||||||
Last change is for: https://github.com/rust-lang/rust/pull/126298
|
Last change is for: https://github.com/rust-lang/rust/pull/125642
|
||||||
|
|
|
@ -368,9 +368,7 @@ impl Step for Llvm {
|
||||||
cfg.define("LLVM_PROFDATA_FILE", path);
|
cfg.define("LLVM_PROFDATA_FILE", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable zstd to avoid a dependency on libzstd.so.
|
// Libraries for ELF section compression.
|
||||||
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
|
|
||||||
|
|
||||||
if !target.is_windows() {
|
if !target.is_windows() {
|
||||||
cfg.define("LLVM_ENABLE_ZLIB", "ON");
|
cfg.define("LLVM_ENABLE_ZLIB", "ON");
|
||||||
} else {
|
} else {
|
||||||
|
@ -824,6 +822,14 @@ fn configure_llvm(builder: &Builder<'_>, target: TargetSelection, cfg: &mut cmak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Libraries for ELF section compression.
|
||||||
|
if builder.config.llvm_libzstd {
|
||||||
|
cfg.define("LLVM_ENABLE_ZSTD", "FORCE_ON");
|
||||||
|
cfg.define("LLVM_USE_STATIC_ZSTD", "TRUE");
|
||||||
|
} else {
|
||||||
|
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref linker) = builder.config.llvm_use_linker {
|
if let Some(ref linker) = builder.config.llvm_use_linker {
|
||||||
cfg.define("LLVM_USE_LINKER", linker);
|
cfg.define("LLVM_USE_LINKER", linker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,7 @@ pub struct Config {
|
||||||
pub llvm_thin_lto: bool,
|
pub llvm_thin_lto: bool,
|
||||||
pub llvm_release_debuginfo: bool,
|
pub llvm_release_debuginfo: bool,
|
||||||
pub llvm_static_stdcpp: bool,
|
pub llvm_static_stdcpp: bool,
|
||||||
|
pub llvm_libzstd: bool,
|
||||||
/// `None` if `llvm_from_ci` is true and we haven't yet downloaded llvm.
|
/// `None` if `llvm_from_ci` is true and we haven't yet downloaded llvm.
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
llvm_link_shared: Cell<Option<bool>>,
|
llvm_link_shared: Cell<Option<bool>>,
|
||||||
|
@ -878,6 +879,7 @@ define_config! {
|
||||||
plugins: Option<bool> = "plugins",
|
plugins: Option<bool> = "plugins",
|
||||||
ccache: Option<StringOrBool> = "ccache",
|
ccache: Option<StringOrBool> = "ccache",
|
||||||
static_libstdcpp: Option<bool> = "static-libstdcpp",
|
static_libstdcpp: Option<bool> = "static-libstdcpp",
|
||||||
|
libzstd: Option<bool> = "libzstd",
|
||||||
ninja: Option<bool> = "ninja",
|
ninja: Option<bool> = "ninja",
|
||||||
targets: Option<String> = "targets",
|
targets: Option<String> = "targets",
|
||||||
experimental_targets: Option<String> = "experimental-targets",
|
experimental_targets: Option<String> = "experimental-targets",
|
||||||
|
@ -1153,6 +1155,7 @@ impl Config {
|
||||||
llvm_optimize: true,
|
llvm_optimize: true,
|
||||||
ninja_in_file: true,
|
ninja_in_file: true,
|
||||||
llvm_static_stdcpp: false,
|
llvm_static_stdcpp: false,
|
||||||
|
llvm_libzstd: false,
|
||||||
backtrace: true,
|
backtrace: true,
|
||||||
rust_optimize: RustOptimize::Bool(true),
|
rust_optimize: RustOptimize::Bool(true),
|
||||||
rust_optimize_tests: true,
|
rust_optimize_tests: true,
|
||||||
|
@ -1787,6 +1790,7 @@ impl Config {
|
||||||
plugins,
|
plugins,
|
||||||
ccache,
|
ccache,
|
||||||
static_libstdcpp,
|
static_libstdcpp,
|
||||||
|
libzstd,
|
||||||
ninja,
|
ninja,
|
||||||
targets,
|
targets,
|
||||||
experimental_targets,
|
experimental_targets,
|
||||||
|
@ -1821,6 +1825,7 @@ impl Config {
|
||||||
set(&mut config.llvm_thin_lto, thin_lto);
|
set(&mut config.llvm_thin_lto, thin_lto);
|
||||||
set(&mut config.llvm_release_debuginfo, release_debuginfo);
|
set(&mut config.llvm_release_debuginfo, release_debuginfo);
|
||||||
set(&mut config.llvm_static_stdcpp, static_libstdcpp);
|
set(&mut config.llvm_static_stdcpp, static_libstdcpp);
|
||||||
|
set(&mut config.llvm_libzstd, libzstd);
|
||||||
if let Some(v) = link_shared {
|
if let Some(v) = link_shared {
|
||||||
config.llvm_link_shared.set(Some(v));
|
config.llvm_link_shared.set(Some(v));
|
||||||
}
|
}
|
||||||
|
@ -1871,6 +1876,7 @@ impl Config {
|
||||||
check_ci_llvm!(optimize_toml);
|
check_ci_llvm!(optimize_toml);
|
||||||
check_ci_llvm!(thin_lto);
|
check_ci_llvm!(thin_lto);
|
||||||
check_ci_llvm!(release_debuginfo);
|
check_ci_llvm!(release_debuginfo);
|
||||||
|
check_ci_llvm!(libzstd);
|
||||||
check_ci_llvm!(targets);
|
check_ci_llvm!(targets);
|
||||||
check_ci_llvm!(experimental_targets);
|
check_ci_llvm!(experimental_targets);
|
||||||
check_ci_llvm!(clang_cl);
|
check_ci_llvm!(clang_cl);
|
||||||
|
|
|
@ -220,4 +220,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
|
||||||
severity: ChangeSeverity::Warning,
|
severity: ChangeSeverity::Warning,
|
||||||
summary: "For tarball sources, default value for `rust.channel` will be taken from `src/ci/channel` file.",
|
summary: "For tarball sources, default value for `rust.channel` will be taken from `src/ci/channel` file.",
|
||||||
},
|
},
|
||||||
|
ChangeInfo {
|
||||||
|
change_id: 125642,
|
||||||
|
severity: ChangeSeverity::Info,
|
||||||
|
summary: "New option `llvm.libzstd` to control whether llvm is built with zstd support.",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -79,6 +79,7 @@ ENV RUST_CONFIGURE_ARGS \
|
||||||
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
|
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
|
||||||
--set llvm.thin-lto=true \
|
--set llvm.thin-lto=true \
|
||||||
--set llvm.ninja=false \
|
--set llvm.ninja=false \
|
||||||
|
--set llvm.libzstd=true \
|
||||||
--set rust.jemalloc \
|
--set rust.jemalloc \
|
||||||
--set rust.use-lld=true \
|
--set rust.use-lld=true \
|
||||||
--set rust.lto=thin \
|
--set rust.lto=thin \
|
||||||
|
|
Loading…
Add table
Reference in a new issue