Skip to content

Static binary #1

Open
Open
@probonopd

Description

@probonopd

Hello @ryanabx. Very interesting project! In fact, I have wondered for a long time whether writing an AppImage runtime in Rust would be a) feasible and b) beneficial. Unfortunately, I have never done anything with Rust so far.

Could you please add some instructions how to create a static binary for the runtime? It should not depend on glibc (or another C library) being present on the target system. For https://github.com/AppImage/type2-runtime, we are statically linking musl libc.

This is what I figured out so far:

  • Rust already links most libraries (but not the C standard library) statically
  • It may be possible to link musl libc statically, creating a fully static binary, by using something along these lines:
# Install Rust if not already installed (as a user, not as root)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. ~/.cargo/env

sudo apt-get -y install libfuse3 

cargo build --release

# This works, but dynamically links glibc
# Hence we try:

mkdir -p .cargo
cat > .cargo/config.toml <<\EOF
[build]
target = "x86_64-unknown-linux-musl"

[target.'cfg(target_os = "linux")']
rustflags = ["-C", "linker=ld.lld", "-C", "relocation-model=static", "-C", "strip=symbols"]
EOF

rustup target add x86_64-unknown-linux-musl

cargo build --release

This gives

--- stderr
  pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.
  pkg-config has not been configured to support cross-compilation.

How to proceed?

For https://github.com/AppImage/type2-runtime, we are building the whole thing in an Alpine Linux chroot. Do we need something similar here?

(At this point I am mainly interested in finding out how large an entirely static AppImage runtime written in Rust might be.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions