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

Produce statically-linked release binaries #103

Open
bradlarsen opened this issue Dec 14, 2023 · 3 comments
Open

Produce statically-linked release binaries #103

bradlarsen opened this issue Dec 14, 2023 · 3 comments
Labels
help wanted Extra attention is needed packaging Related to packaging and distribution

Comments

@bradlarsen
Copy link
Collaborator

bradlarsen commented Dec 14, 2023

In a comment by @Azathothas, a couple incantations were shared that seem to generate statically-linked noseyparker binaries:

!# cross
  git clone --filter "blob:none" "https://github.com/praetorian-inc/noseyparker" && cd "./noseyparker"
  cargo install -f cross
  export TARGET="x86_64-unknown-linux-musl" ; rustup target add "$TARGET" ; export RUSTFLAGS="-C target-feature=+crt-static"
  sed '/^\[profile\.release\]/,/^$/d' -i "./Cargo.toml" ; echo -e '\n[profile.release]\nstrip = true\nopt-level = "z"\nlto = true' >> "./Cargo.toml"
  cross build --target "$TARGET" --release

!# cargo
  git clone --filter "blob:none" "https://github.com/praetorian-inc/noseyparker" && cd "./noseyparker"
  export TARGET="x86_64-unknown-linux-gnu" ; rustup target add "$TARGET" ; export RUSTFLAGS="-C target-feature=+crt-static"
  sed '/^\[profile\.release\]/,/^$/d' -i "./Cargo.toml" ; echo -e '\n[profile.release]\nstrip = true\nopt-level = "z"\nlto = true' >> "./Cargo.toml"
  cargo build --target "$TARGET" --release 

---
  file "./target/$TARGET/release/noseyparker-cli"
  ./target/x86_64-unknown-linux-musl/release/noseyparker-cli: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, stripped

This needs some more investigation. If it (a) works for the platforms we care about (x86_64 and ARM64 macOS and Linux), and (b) does not introduce performance or functionality regressions, we should switch the Nosey Parker releases to statically link instead.

@bradlarsen
Copy link
Collaborator Author

Using statically linked binaries would probably resolve #58.

@bradlarsen
Copy link
Collaborator Author

@Azathothas in the snippets you shared, I see that you are switching the release profile to use different LTO and optimization options (lto=true and opt-level="z"). Nosey Parker currently builds with lto="thin" and opt-level=3.

Have you experimented with those different settings, or are lto=true and opt-level="z" just what you use by default with Rust projects?

@bradlarsen bradlarsen added the packaging Related to packaging and distribution label Dec 14, 2023
@Azathothas
Copy link

@bradlarsen

I have indeed experimented with building rust binaries, in my testing, I have found those settings that I forcefully apply, result in smaller binaries.

You can find hundreds of other binaries being built with the same settings/config at:
https://github.com/Azathothas/Toolpacks/blob/main/.github/scripts/eget_build_binaries_amd_x86_64.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed packaging Related to packaging and distribution
Projects
None yet
Development

No branches or pull requests

2 participants