Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable lto support guarded behind feature flags #198

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 3 additions & 0 deletions zstd-safe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 3 additions & 0 deletions zstd-safe/zstd-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 7 additions & 9 deletions zstd-safe/zstd-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
);
Comment on lines +154 to +160
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous bug with lto should be fixed by rust-lang/cc-rs#757

@gyscos I recommend to upgrade to new cc once it lands.

But still, I want to be safe here by putting them behind feature flags so that users can decide whether to enable fat-lto or thin-lto.

}
*/

#[cfg(feature = "thin")]
{
Expand Down