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 Static Binaries for Releases #401

Open
greshake opened this issue Jul 14, 2019 · 5 comments
Open

Produce Static Binaries for Releases #401

greshake opened this issue Jul 14, 2019 · 5 comments
Labels
enhancement help wanted packaging Issues related to distro packaging.

Comments

@greshake
Copy link
Owner

I tried setting up static builds using Docker containers based on either Alpine and Ubuntu with musl versions of Rust. Unfortunately the builds fail because proc_macro used by serde_derive can't be used in static builds. I'm not quite sure if there will be a workaround for this.

You can try this yourself with this Dockerfile (build with docker build -t i3status-rust .):

FROM alpine:3.10

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories

RUN apk update && \
    apk add dbus-dev pulseaudio rustup

RUN /usr/bin/rustup-init -y \
    --default-host x86_64-unknown-linux-musl \
    --default-toolchain stable

Execute this from the main repo folder to get a build:

docker run --rm -it -v "$(pwd)":/src i3status-rust sh -c 'cd src && cargo build --release'
@atheriel atheriel added the packaging Issues related to distro packaging. label Nov 6, 2019
@ammgws
Copy link
Collaborator

ammgws commented May 2, 2020

@atheriel I saw this comment today and gave it a go - it built successfully.

Dockerfile:

FROM alpine:3.11

RUN apk update && \
    apk add dbus-dev pulseaudio build-base

RUN apk add --update-cache \
--repository https://alpine.global.ssl.fastly.net/alpine/edge/community \
rustup

RUN /usr/bin/rustup-init -y \
    --default-host x86_64-unknown-linux-musl \
    --default-toolchain stable

ENV PATH /root/.cargo/bin:$PATH

docker run --rm -it -v "$(pwd)":/src i3status-rust sh -c 'cd src && RUSTFLAGS="-C target-feature=-crt-static" cargo build --release'

@ammgws
Copy link
Collaborator

ammgws commented Apr 2, 2021

Last time I gave it a go, I was able to compile, but the resulting binary wasn't executable. Maybe someone else can try?

@GladOSkar
Copy link
Contributor

I actually get this compile error:

error: failed to run custom build command for `openssl-sys v0.9.60`

Caused by:
  process didn't exit successfully: `/src/target/release/build/openssl-sys-1f4459c902b3ad26/build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR
  X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR
  X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit code: 1\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc\'\nto the PKG_CONFIG_PATH environment variable\nPackage \'openssl\', required by \'virtual:world\', not found\n"

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-musl
  $TARGET = x86_64-unknown-linux-musl
  openssl-sys = 0.9.60

  ', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.60/build/find_normal.rs:173:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

@MaxVerevkin
Copy link
Collaborator

Info

  • Void Linux - musl libc
  • rustc - 1.50.0/1.51.0
  • stable-x86_64-unknown-linux-musl
  • Default compiler options

Compilation

Successful

Execution

Segfaults immediately. Some time ago I did some debugging and the segfault is caused by dbus, pulseaudio and openssl. If I remove all the blocks that require them from my config, it works.


Setting cargo config to

❯ cat .cargo/config.toml                              
[build]
rustflags = ["-C", "target-feature=-crt-static"]

makes it possible to use i3status-rust, but the binary is no longer static.

@ammgws
Copy link
Collaborator

ammgws commented Sep 7, 2021

Yeah I couldn't get past that either. Wonder if it's just not possible to do this with our codebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted packaging Issues related to distro packaging.
Projects
None yet
Development

No branches or pull requests

5 participants