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

Release static binaries #177

Open
SkyperTHC opened this issue Apr 19, 2024 · 2 comments
Open

Release static binaries #177

SkyperTHC opened this issue Apr 19, 2024 · 2 comments
Labels
enhancement New feature or request packaging Related to packaging and distribution

Comments

@SkyperTHC
Copy link

The x86_64 release binary rarely works on Linux because of libc mismatches. It would be desirable to have a statically compiled binary as well.

I'm currently using these steps to compile a static binary using your Dockerfile.alpine:

# Inside Dockerfile.alpine:
cd /src
RUSTFLAGS='-C target-feature=+crt-static' cargo build --locked --profile release --target x86_64-unknown-linux-musl --features release
strip target/x86_64-unknown-linux-musl/release/noseyparker-cli

The statically compiled binary is then created in target/x86_64-unknown-linux-musl/release/noseyparker-cli

Happy to fiddle it into hour GitHub CI/CD but feels like it would be easier for you - gimme a shout.

@SkyperTHC SkyperTHC added the enhancement New feature or request label Apr 19, 2024
@bradlarsen bradlarsen added the packaging Related to packaging and distribution label Apr 19, 2024
@bradlarsen
Copy link
Collaborator

@SkyperTHC thank you for opening this. Yes, I'd like to solve this here, as the glibc mismatch has continued to be a pain point from time to time (e.g., #103), making it difficult to run on older Linux systems.

I'll take a look at this.

@bradlarsen
Copy link
Collaborator

The desired end state: Nosey Parker releases will include an additional prebuilt releases for *-unknown-linux-musl that is statically linked.

The v0.17.0 release has the following prebuilt artifacts:

  • noseyparker-v0.17.0-x86_64-apple-darwin.tar.gz
  • noseyparker-v0.17.0-aarch64-apple-darwin.tar.gz
  • noseyparker-v0.17.0-x86_64-unknown-linux-gnu.tar.gz

We want to include an additional file like noseyparker-v0.17.0-x86_64-unknown-linux-musl.tar.gz in future releases, which is fully statically linked.

Notes

Okay, so I tried a few things. Simply enabling the crt-static target feature for the x86_64-unknown-linux-gnu target fails early on:

error: cannot produce proc-macro for `clap_derive v4.5.4` as the target `x86_64-unknown-linux-gnu` does not support these crate types

A few minutes of research indicates that this may be a limitation of the *-linux-gnu targets...

Instead, using the x86_64-unknown-linux-musl target seems like it works, but setting up an Ubuntu-based build environment with all the necessary tools appears to be more complicated than simply doing an apt install of a few packages. (I get errors about musl-g++ missing...)

@SkyperTHC does this match your experience, or am I missing something about building statically-linked Rust programs on Linux?

Fully static x86_64 Linux binaries do get built within the Alpine-based Docker image. One option for building the *unknown-linux-musl release would be to use the Dockerfile.alpine build and simply copy the release out of there. Another option might be using cross.

Azathothas added a commit to Azathothas/Toolpacks that referenced this issue Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request packaging Related to packaging and distribution
Projects
None yet
Development

No branches or pull requests

2 participants