eyra
eyra copied to clipboard
docs: `hello-world-small` example size update
Summary
- Rust nightly (1.83) now builds these targets (from a glibc host) at 13-20KB smaller.
- An actual improvement from approx 13KB difference to near 16KB difference.
Reproduction
# Docker with Fedora 41 for the base reproduction environment:
$ docker run --rm -it --workdir /example fedora:41
# Prep environment:
$ dnf install -y gcc rustup nano
$ rustup-init -y --profile minimal --default-toolchain nightly --target x86_64-unknown-linux-gnu x86_64-unknown-linux-musl --component rust-src
$ . "$HOME/.cargo/env"
# Create basic hello world example:
$ cargo init
# Add the release profile:
# https://github.com/sunfishcode/eyra/blob/v0.17.0/example-crates/hello-world-small/Cargo.toml#L10-L16
$ nano Cargo.toml
musl
# musl build (30KB):
$ RUSTFLAGS="-Z location-detail=none -C relocation-model=static -C target-feature=+crt-static" cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-musl --release
$ du --bytes target/x86_64-unknown-linux-musl/release/example
30288 target/x86_64-unknown-linux-musl/release/example
musl + zig
# musl build via zig (26KB):
dnf install -y zig
cargo install cargo-zigbuild
# Only differs by replacing the `build` sub-command with `zigbuild`:
$ RUSTFLAGS="-Z location-detail=none -C relocation-model=static -C target-feature=+crt-static" cargo +nightly zigbuild -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-musl --release
$ du --bytes target/x86_64-unknown-linux-musl/release/example
26424 target/x86_64-unknown-linux-musl/release/example
# NOTE: Zig does not presently support static glibc builds,
# nor is it compatible with Eyra due to duplicate `_start` from Zig
glibc
# glibc build (83KB):
# glibc static libs are needed for gnu target to link statically:
$ dnf -y install glibc-static
# Same command as before, only adjusted `--target`
$ RUSTFLAGS="-Z location-detail=none -C relocation-model=static -C target-feature=+crt-static" cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release
$ du --bytes target/x86_64-unknown-linux-gnu/release/example
834224 target/x86_64-unknown-linux-gnu/release/example
eyra
# eyra build (24KB):
$ cargo add eyra --no-default-features
# `moreutils` provides the `sponge` command (or you could just edit via nano):
$ dnf -y install moreutils
# Add this line to the top of `src/main.rs`
$ echo 'extern crate eyra;' | cat - src/main.rs | sponge src/main.rs
# NOTE: Only differs by prepending `-C link-arg=nostartfiles`
$ RUSTFLAGS="-C link-arg=-nostartfiles -Z location-detail=none -C relocation-model=static -C target-feature=+crt-static" cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release
$ du --bytes target/x86_64-unknown-linux-gnu/release/example
24616 target/x86_64-unknown-linux-gnu/release/example