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);
|
||||
|
||||
for lib in output(&mut cmd).split_whitespace() {
|
||||
let mut is_static = false;
|
||||
let name = if let Some(stripped) = lib.strip_prefix("-l") {
|
||||
stripped
|
||||
} else if let Some(stripped) = lib.strip_prefix('-') {
|
||||
|
@ -266,8 +267,24 @@ fn main() {
|
|||
} else if Path::new(lib).exists() {
|
||||
// On MSVC llvm-config will print the full name to libraries, but
|
||||
// we're only interested in the name part
|
||||
let name = Path::new(lib).file_name().unwrap().to_str().unwrap();
|
||||
name.trim_end_matches(".lib")
|
||||
// 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")
|
||||
}
|
||||
} else if lib.ends_with(".lib") {
|
||||
// Some MSVC libraries just come up with `.lib` tacked on, so chop
|
||||
// that off
|
||||
|
@ -285,7 +302,13 @@ fn main() {
|
|||
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}");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue