Enable cross-lang-fat-lto on Linux (#817)

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 <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-02-19 15:19:35 +11:00 committed by GitHub
parent e76a4dff62
commit 3f0107696b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View file

@ -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"]

View file

@ -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"]

View file

@ -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"]

View file

@ -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
}, ",")
@ -92,7 +92,16 @@ 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
#
@ -100,6 +109,16 @@ rust-lld := if target-os != "windows" { " -Z gcc-ld=lld" } else { "" }
# 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
@ -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