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

Optimize liblzma.a build #107

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ tokio-core = "0.1.17"
tokio = ["tokio-io", "futures"]
static = ["lzma-sys/static"]

fat-lto = ["lzma-sys/fat-lto"]
thin-lto = ["lzma-sys/thin-lto"]

thin = ["lzma-sys/thin"]

[package.metadata.docs.rs]
features = ["tokio-io", "futures"]
5 changes: 5 additions & 0 deletions lzma-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ pkg-config = "0.3.14"

[features]
static = []

fat-lto = [] # Enable fat-lto, will override thin-lto if specified
thin-lto = [] # Enable thin-lto, will fallback to fat-lto if not supported

thin = [] # Enable HAVE_SMALL to optimize for size
21 changes: 21 additions & 0 deletions lzma-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ fn main() {
}
}

build

Choose a reason for hiding this comment

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

This should be gates behind OPT_LEVEL. Only after OPT_LEVEL = Some("3")?

Choose a reason for hiding this comment

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

Related to this MR by name.... xz2 should also define NDEBUG when OPT_LEVEL is 3

https://github.com/xz-mirror/xz/blob/b69da6d4bb6bb11fc0cf066920791990d2b22a06/dos/config.h#L136

Copy link
Author

Choose a reason for hiding this comment

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

Related to this MR by name.... xz2 should also define NDEBUG when OPT_LEVEL is 3

I've added #define NDEBUG 1 to config.h.

Copy link
Author

Choose a reason for hiding this comment

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

This should be gates behind OPT_LEVEL. Only after OPT_LEVEL = Some("3")?

I'm not sure which line are you referring to.
The line you referenced does not contain anything related to opt-level or optimization flags.

.flag_if_supported("-ffunction-sections")
.flag_if_supported("-fdata-sections")
.flag_if_supported("-fmerge-all-constants");

if cfg!(feature = "fat-lto") {
build.flag_if_supported("-flto");
} else if cfg!(feature = "thin-lto") {
if build.is_flag_supported("-flto=thin").unwrap_or(false) {
build.flag("-flto=thin");
} else {
build.flag_if_supported("-flto");
}
}

if cfg!(feature = "thin") {
build.define("HAVE_SMALL", Some("1"));

build.opt_level_str("z");
}

build.compile("liblzma.a");
}

Expand Down
2 changes: 2 additions & 0 deletions lzma-sys/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#define MYTHREAD_POSIX 1
#endif

#define NDEBUG 1

#if defined(__sun)
#define HAVE_CLOCK_GETTIME 1
#define HAVE_DECL_CLOCK_MONOTONIC 1
Expand Down