-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
You can build httpget with nightly for some improvements in size reduction: neonmoe/minreq#111
Reproduction
I've adapted the referenced example to httpget build. I've omitted some extra optimizations from the linked issue which would be approx 20KB smaller (or 50%+ with UPX for further reduction via compression).
# Reproduction environment via Docker:
docker run --rm -it --workdir /build fedora:41
# - `lld` is optional, it's used with `-C link-arg=-fuse-ld=lld`,
# slight improvement over the internal LLD linker the rust toolchain bundles
# - `musl-gcc` is required for `--features tls` since we're building from a glibc host:
dnf install -y lld git gcc musl-gcc rustup-init
# Nightly rust with the musl target (for static build) and `rust-src` (for `-Z build-std`)
# rustc 1.84.0-nightly (e7c0d2750 2024-10-15)
rustup-init -y \
--profile minimal \
--component rust-src \
--target x86_64-unknown-linux-musl \
--default-toolchain nightly
. "$HOME/.cargo/env"
git clone --depth 1 https://github.com/cryptaliagy/httpget .HTTP only (127.5KB)
$ cargo +nightly build --release --target x86_64-unknown-linux-musl
$ du --bytes target/x86_64-unknown-linux-musl/release/httpget
534760 target/x86_64-unknown-linux-musl/release/httpget
$ RUSTFLAGS='-C link-arg=-fuse-ld=lld -C relocation-model=static' \
cargo +nightly build --release \
--target x86_64-unknown-linux-musl \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort
du --bytes target/x86_64-unknown-linux-musl/release/httpget
127488 target/x86_64-unknown-linux-musl/release/httpgetHTTPS (766KB)
$ cargo +nightly build --release --target x86_64-unknown-linux-musl --features tls
$ du --bytes target/x86_64-unknown-linux-musl/release/httpget
1509720 target/x86_64-unknown-linux-musl/release/httpget
$ RUSTFLAGS='-C link-arg=-fuse-ld=lld -C relocation-model=static' \
cargo +nightly build --release \
--target x86_64-unknown-linux-musl \
--features tls \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort
du --bytes target/x86_64-unknown-linux-musl/release/httpget
995024 target/x86_64-unknown-linux-musl/release/httpgetSize improvement cargo update + UPX
For the --features tls results, if you update Cargo.lock with cargo update the sizes are 1,268,056 vs 766,320, which is a nice improvement in savings.
- No improvement observed in size for an HTTP only build.
- Your README states 1.2MB for
rustls, that was true with theCargo.lockbefore update dependencies #15
Use UPX to bring the HTTPS build down to just 432KB 😎 (for an HTTP-only build, this reduces down to about 70KB)
$ dnf install -y upx
$ upx --lzma target/x86_64-unknown-linux-musl/release/httpget
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2024
UPX 4.2.4 Markus Oberhumer, Laszlo Molnar & John Reiser May 9th 2024
File size Ratio Format Name
-------------------- ------ ----------- -----------
763216 -> 432356 56.65% linux/amd64 httpgetMetadata
Metadata
Assignees
Labels
No labels