Skip to content

Commit

Permalink
Enable cross-lang-fat-lto on Linux (#817)
Browse files Browse the repository at this point in the history
Fixed #806

 - Add new feature flag `cross-lang-fat-lto` and enable it on release for linux
 - Enable `-C linker-plugin-lto` for linux
 - Only use `-Z gcc-ld=lld` on non-windows targets when `cargo-zigbuild` is not enabled

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu authored Feb 19, 2023
1 parent e76a4df commit 3f01076
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ native-tls = ["binstalk/native-tls"]
trust-dns = ["binstalk/trust-dns"]

zstd-thin = ["binstalk/zstd-thin"]
cross-lang-fat-lto = ["binstalk/cross-lang-fat-lto"]

fancy-no-backtrace = ["miette/fancy-no-backtrace"]
fancy-with-backtrace = ["fancy-no-backtrace", "miette/fancy"]
Expand Down
2 changes: 2 additions & 0 deletions crates/binstalk-downloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ native-tls = ["reqwest/native-tls", "trust-dns-resolver?/dns-over-native-tls"]
trust-dns = ["trust-dns-resolver", "reqwest/trust-dns"]

zstd-thin = ["zstd/thin"]

cross-lang-fat-lto = ["zstd/fat-lto"]
1 change: 1 addition & 0 deletions crates/binstalk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ native-tls = ["binstalk-downloader/native-tls"]
trust-dns = ["binstalk-downloader/trust-dns"]

zstd-thin = ["binstalk-downloader/zstd-thin"]
cross-lang-fat-lto = ["binstalk-downloader/cross-lang-fat-lto"]
25 changes: 22 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ support-pkg-config := if target == target-host {

cargo-features := trim_end_match(if override-features != "" { override-features
} else if (cargo-profile / ci-or-no) == "dev/ci" { "rustls,fancy-with-backtrace,zstd-thin,log_release_max_level_debug" + (if support-pkg-config != "" { ",pkg-config" } else { "" }) + extra-features
} else if (cargo-profile / ci-or-no) == "release/ci" { "static,rustls,trust-dns,fancy-no-backtrace,zstd-thin,log_release_max_level_debug" + extra-features
} else if (cargo-profile / ci-or-no) == "release/ci" { "static,rustls,trust-dns,fancy-no-backtrace,zstd-thin,log_release_max_level_debug" + (if target-os != "macos" { ",cross-lang-fat-lto" } else { "" }) + extra-features
} else { extra-features
}, ",")

Expand All @@ -92,14 +92,33 @@ rustc-miropt := if for-release != "" { " -Z mir-opt-level=4" } else { "" }
# TODO: There is ongoing effort to stabilise this and we will need to update
# this once it is merged.
# https://github.com/rust-lang/compiler-team/issues/510
rust-lld := if target-os != "windows" { " -Z gcc-ld=lld" } else { "" }
#
# If cargo-zigbuild is used, then it will provide the lld linker.
# This option is disabled on windows since it not supported.
rust-lld := if use-cargo-zigbuild != "" {
""
} else if target-os != "windows" {
" -Z gcc-ld=lld"
} else {
""
}

# ICF: link-time identical code folding
#
# On windows it works out of the box and on other targets it uses
# rust-lld.
rustc-icf := if for-release != "" { " -C link-arg=-Wl,--icf=safe" } else { "" }

# Only enable linker-plugin-lto for release
# Also disable this on windows since it uses msvc.
linker-plugin-lto := if for-release == "" {
""
} else if target-os == "linux" {
"-C linker-plugin-lto "
} else {
""
}

target-glibc-ver-postfix := if glibc-version != "" {
if use-cargo-zigbuild != "" {
"." + glibc-version
Expand All @@ -111,7 +130,7 @@ target-glibc-ver-postfix := if glibc-version != "" {
}

cargo-build-args := (if for-release != "" { " --release" } else { "" }) + (" --target ") + (target) + (target-glibc-ver-postfix) + (cargo-buildstd) + (if extra-build-args != "" { " " + extra-build-args } else { "" }) + (cargo-no-default-features) + (cargo-split-debuginfo) + (if cargo-features != "" { " --features " + cargo-features } else { "" }) + (win-arm64-ring16)
export RUSTFLAGS := "-Z share-generics " + (rustc-gcclibs) + (rustc-miropt) + (rust-lld) + (rustc-icf)
export RUSTFLAGS := "-Z share-generics " + (linker-plugin-lto) + (rustc-gcclibs) + (rustc-miropt) + (rust-lld) + (rustc-icf)


# libblocksruntime-dev provides compiler-rt
Expand Down

0 comments on commit 3f01076

Please sign in to comment.