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

Cannot compile with musl as target #316

Closed
nbigaouette opened this issue Jun 9, 2018 · 9 comments
Closed

Cannot compile with musl as target #316

nbigaouette opened this issue Jun 9, 2018 · 9 comments

Comments

@nbigaouette
Copy link

I'm trying to build a docker image providing a statically linked musl binary of gutenberg (v0.3.3). This way the final docker image could contain only the static binary by using FROM scratch.

Here's the dockerfile:

ARG RUSTC_VERSION=1.26.2

FROM rust:${RUSTC_VERSION}-slim-stretch as builder

ENV GUTENBERG_VERSION 0.3.3

RUN apt-get update -y && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y -q \
    wget \
    tar \
    cmake \
    build-essential \
    musl-dev \
    musl-tools \
    libpq-dev \
    libsqlite-dev \
    libssl-dev \
    pkgconf \
    xutils-dev \
    && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN wget https://github.com/Keats/gutenberg/archive/v${GUTENBERG_VERSION}.tar.gz && \
    tar -zxvf v${GUTENBERG_VERSION}.tar.gz && \
    rm -f v${GUTENBERG_VERSION}.tar.gz

RUN rustup target add x86_64-unknown-linux-musl

WORKDIR gutenberg-${GUTENBERG_VERSION}

ENV RUST_BACKTRACE=1

RUN cargo build --release

FROM rust:${RUSTC_VERSION}-slim-stretch as runner
COPY --from=builder /gutenberg-${GUTENBERG_VERSION}/target/release/gutenberg .
CMD ["./gutenberg", "serve"]

Built and ran like this: docker build . -t gutenberg:v0.3.3 && docker run -it --rm gutenberg:v0.3.3

Right now it does not work. I've facing some issues.

First issue is the following:

error[E0518]: attribute should be applied to function
  --> /usr/local/cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/tera-0.11.6/src/parser/mod.rs:13:10
   |
13 | #[derive(Parser)]
   |          ^^^^^^ not a function

I'm not sure to understand this error. I was able to bypass it by running cargo update. Here's the resulting lock file: Cargo.lock.txt
Could a release be done with updated dependencies? I guess that should fix this problem.

Secondly, I get a linking error if I try to link to musl (cargo build --release --target=x86_64-unknown-linux-musl):

  = note: /gutenberg-0.3.3/target/x86_64-unknown-linux-musl/release/deps/libsass_sys-e5c815c30709cae7.rlib(sass_context.o): In fun
ction `_GLOBAL__sub_I_sass_context.cpp':
          sass_context.cpp:(.text.startup+0x1c): undefined reference to `__dso_handle'
          sass_context.cpp:(.text.startup+0x4e): undefined reference to `__dso_handle'
          sass_context.cpp:(.text.startup+0xc9): undefined reference to `__dso_handle'
          sass_context.cpp:(.text.startup+0xef): undefined reference to `__dso_handle'
          sass_context.cpp:(.text.startup+0x118): undefined reference to `__dso_handle'
          /gutenberg-0.3.3/target/x86_64-unknown-linux-musl/release/deps/libsass_sys-e5c815c30709cae7.rlib(sass_context.o):sass_co
ntext.cpp:(.text.startup+0x141): more undefined references to `__dso_handle' follow
          /usr/bin/ld: /gutenberg-0.3.3/target/x86_64-unknown-linux-musl/release/deps/gutenberg-55708b3e089522b3: hidden symbol `_
_dso_handle' isn't defined
          /usr/bin/ld: final link failed: Bad value
          collect2: error: ld returned 1 exit status

Could rust-lang/rust#50105 be related?

Thanks!

@onelson
Copy link
Contributor

onelson commented Jun 10, 2018

I ran into this same error for a project I have which depends on tera. I think the specific crate that needed updating was pest_derive and maybe one other I can't remember.

@ilovezfs
Copy link

@Keats yes we're now seeing this failure on Homebrew's CI as well.

@Keats
Copy link
Collaborator

Keats commented Jun 11, 2018

Doing a 0.3.4 release after cargo update is not an issue but we should ensure sass-rs works with musl first, would it be possible to make a PR to https://github.com/compass-rs/sass-rs to add the musl target in travis?

@Keats
Copy link
Collaborator

Keats commented Jun 20, 2018

@nbigaouette can you try to run the Dockerfile on nightly? If it compiles fine than we can leave it as is and I'll just release a 0.3.4 version

@Keats
Copy link
Collaborator

Keats commented Jun 22, 2018

I tried with the Dockerfile using nightly rust but the issue is still there.

Root issue: rust-lang/rust#36710
Related (?) RFC: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
Current merged solution: rust-lang/rust#51063

@Keats
Copy link
Collaborator

Keats commented Jun 22, 2018

In the meantime I published 0.3.4 which is a cargo updated version only

@Keats Keats changed the title Issue compiling in Docker Cannot compile with musl as target Jun 22, 2018
@ilovezfs
Copy link

Awesome! Thank you @Keats. 0.3.4 shipped in Homebrew Homebrew/homebrew-core#29331

@Keats
Copy link
Collaborator

Keats commented Jul 5, 2018

So I believe the issue is only with https://github.com/compass-rs/sass-rs as libsass uses global, which Rust seems to have issues with. Should we move this issue there?

@Keats
Copy link
Collaborator

Keats commented Jul 17, 2018

Closing in favour of the issue in sass-rs linked above

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

4 participants