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

Distribute a static build #185

Closed
malbarbo opened this issue Jun 29, 2018 · 7 comments
Closed

Distribute a static build #185

malbarbo opened this issue Jun 29, 2018 · 7 comments
Assignees

Comments

@malbarbo
Copy link
Contributor

I know what you're thinking: it's easier said than done!

But I did it! I built a static version of tectonic! It toke a lot of time, but the final patches are really small.

I used the following docker alpine container to do the build:

FROM alpine:edge

RUN apk update && \
    apk upgrade && \
    apk add \
        g++ \
        git \
        rust \
        cargo \
        fontconfig-dev \
        freetype-static \
        glib-static \
        graphite2-dev \
        graphite2-static \
        harfbuzz-dev \
        harfbuzz-static \
        icu-dev \
        icu-static \
        openssl-dev \
        zlib-dev

ENV TECTONIC_STATIC=1
ENV PKG_CONFIG_ALL_STATIC=1
ENV OPENSSL_STATIC=1
ENV OPENSSL_DIR=/usr
ENV RUSTFLAGS="-C target-feature=+crt-static"

RUN mkdir /out/

CMD git clone https://github.com/malbarbo/tectonic --branch static && \
    cd tectonic && \
    sed -i -e 's/AES_cbc_encrypt/AES_cbc_encrypt2/g' \
              ./tectonic/dpx-dpxcrypt.h \
              ./tectonic/dpx-pdfencrypt.c \
              ./tectonic/dpx-dpxcrypt.c && \
    cargo build --release && \
    cp target/release/tectonic /out/
docker build . -t tectonic
docker run -v $(pwd):/out tectonic

The image install the requirements including static version of the libs.

The env vars indicates to tectonic, pkg-config and openssl packages and rustc to do a static build.

The rename of AES_cbc_encrypt to AES_cbc_encrypt2 is to avoid duplicate symbol between tectonic and openssl.

The following changes to tectonic are needed:

  • disable serde_derive (it does not work with static musl build). The changes disable loading config, so the final patch needs another approach, maybe implementing Deserialize
  • add TECTONIC_STATIC as an option to build.rs to static link stdc++
  • use a pkg-config-rs crate that allows static linking system libraries

I can no longer work on it, but I would be glad if anyone could move on from here and add a static builder to travis.

@malbarbo
Copy link
Contributor Author

For the curious, the static build have 50MB and 35MB stripped.

@pkgw
Copy link
Collaborator

pkgw commented Jun 29, 2018

Cool, and thanks for sharing! I will think about how to make this available. I am more than happy to accept PRs to integrate some of the changes needed here, but if you can't spend any more time on this, I understand.

@pkgw
Copy link
Collaborator

pkgw commented Jan 15, 2019

An update: I've upgraded the Travis infrastructure so that it is a bit more thinkable to generate static binaries on CI and upload them to GitHub releases — see the new driver script for some context.

@ghost
Copy link

ghost commented Aug 5, 2019

This looks great!
@malbarbo have you been able to work on this with the new driver script @pkgw mentioned? If not I can help complete this task.

@malbarbo
Copy link
Contributor Author

malbarbo commented Aug 5, 2019

@efx it would be great if you could complete the task!

@ghost
Copy link

ghost commented Aug 5, 2019

I also noticed the work in #420 which could be applicable as well; as I get some "free time" I'll investigate that work compared with the above approach.

@malbarbo
Copy link
Contributor Author

malbarbo commented Oct 7, 2020

Now we have a static build! Thanks @pkgw.

@malbarbo malbarbo closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants