From bd75cb48ea390ffa4925d1dc1d8c430ca775d0a3 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 27 Jan 2023 13:22:26 +1100 Subject: [PATCH] Re-enable lto support guarded behind feature flags (#198) - fat-lto for fat lto, will override thin-lto if specified - thin-lto for thin lto, will fallback to fat-lto is not supported Signed-off-by: Jiahao XU Signed-off-by: Jiahao XU --- Cargo.toml | 3 +++ zstd-safe/Cargo.toml | 3 +++ zstd-safe/zstd-sys/Cargo.toml | 3 +++ zstd-safe/zstd-sys/build.rs | 16 +++++++--------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 371df7a5..a334afdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,9 @@ no_asm = ["zstd-safe/no_asm"] doc-cfg = [] zdict_builder = ["zstd-safe/zdict_builder"] +fat-lto = ["zstd-safe/fat-lto"] +thin-lto = ["zstd-safe/thin-lto"] + [[example]] name = "train" required-features = ["zdict_builder"] diff --git a/zstd-safe/Cargo.toml b/zstd-safe/Cargo.toml index 3fcaed67..09d585cd 100644 --- a/zstd-safe/Cargo.toml +++ b/zstd-safe/Cargo.toml @@ -34,3 +34,6 @@ arrays = [] no_asm = ["zstd-sys/no_asm"] doc-cfg = [] zdict_builder = ["zstd-sys/zdict_builder"] + +fat-lto = ["zstd-sys/fat-lto"] +thin-lto = ["zstd-sys/thin-lto"] diff --git a/zstd-safe/zstd-sys/Cargo.toml b/zstd-safe/zstd-sys/Cargo.toml index 089ac61b..8f959d1f 100644 --- a/zstd-safe/zstd-sys/Cargo.toml +++ b/zstd-safe/zstd-sys/Cargo.toml @@ -76,3 +76,6 @@ zstdmt = [] # Enable multi-thread support (with pthread) thin = [] # Optimize binary by size no_asm = [] # Disable ASM files (only on amd64 for decompression) zdict_builder = [] + +fat-lto = [] # Enable fat-lto, will override thin-lto if specified +thin-lto = [] # Enable thin-lto, will fallback to fat-lto if not supported diff --git a/zstd-safe/zstd-sys/build.rs b/zstd-safe/zstd-sys/build.rs index 848f795c..3f36aa3b 100644 --- a/zstd-safe/zstd-sys/build.rs +++ b/zstd-safe/zstd-sys/build.rs @@ -151,16 +151,14 @@ fn compile_zstd() { .flag_if_supported("-Wl,--gc-sections") .flag_if_supported("-Wl,--icf=safe"); - // TODO: re-enable thin lto when a more robust solution is found. - /* - if config.get_compiler().is_like_gnu() { - config.flag_if_supported("-fwhopr"); - } else { - // gcc has a -flto but not -flto=thin - // Apparently this is causing crashes on windows-gnu? - config.flag_if_supported("-flto=thin"); + if cfg!(feature = "fat-lto") { + config.flag_if_supported("-flto"); + } else if cfg!(feature = "thin-lto") { + flag_if_supported_with_fallbacks( + &mut config, + &["-flto=thin", "-flto"], + ); } - */ #[cfg(feature = "thin")] {