Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Cannot compile with musl as target #30

Closed
Keats opened this issue Jul 17, 2018 · 10 comments
Closed

Cannot compile with musl as target #30

Keats opened this issue Jul 17, 2018 · 10 comments

Comments

@Keats
Copy link
Collaborator

Keats commented Jul 17, 2018

See getzola/zola#316

In short:

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

@naturallymitchell
Copy link

Linked root issue and merged issue are closed. Is this done?

@Keats
Copy link
Collaborator Author

Keats commented Nov 21, 2018

It didn't work before even with the issue merged, haven't tried recently.
Someone could try to run the dockerfile from getzola/zola#316 with the latest Rust to see if it works

@greizgh
Copy link
Contributor

greizgh commented Jan 19, 2019

This issue seems to be reproduced when trying to build the example with musl:

alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:x86_64-musl'
rust-musl-builder cargo run --example compile_sass

@izelnakri
Copy link

How can we make this work with Docker/musl? Is there any example Dockerfile's?

@Keats
Copy link
Collaborator Author

Keats commented Nov 16, 2019

I have no idea, I'd be happy if someone figures it out.

@izelnakri
Copy link

izelnakri commented Nov 17, 2019

I found the solution, my container(s) were missing make and perhaps other system dependencies however the error was "saying file is not found" instead. Even an archlinux setup with libsass package can give the same error when make package is not installed. Can we make build.rs give better error messages?

@DusterTheFirst
Copy link
Contributor

@Keats Does your system have git installed? By adding RUST_BACKTRACE to my build, I found line 56 (https://github.com/compass-rs/sass-rs/blob/master/sass-sys/build.rs#L56) as the culprit, and installing git fixed the problem for me

@shalzz
Copy link

shalzz commented Apr 5, 2020

@DusterTheFirst The issue is the libsass_sys still relies on glibc when build on a musl target.
You can test this when building on a musl distro like alpine or clux/muslrust

Here is the latest error I got when build libsass (as a dependency of zola)

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-nostdlib" "/root/.rustup/toolchains/stable-2020-03-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crt1.o" "/root/.rustup/toolchains/stable-2020-03-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crti.o" "-L" "/root/.rustup/toolchains/stable-2020-03-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "/volume/zola/target/x86_64-unknown-linux-musl/release/deps/zola-968e9cfc378e8f2f.zola.alpi785d-cgu.0.rcgu.o" "-o" "/volume/zola/target/x86_64-unknown-linux-musl/release/deps/zola-968e9cfc378e8f2f" "-Wl,--gc-sections" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/volume/zola/target/x86_64-unknown-linux-musl/release/deps" "-L" "/volume/zola/target/release/deps" "-L" "/volume/zola/target/x86_64-unknown-linux-musl/release/build/onig_sys-0e0b3f18c88aaec8/out" "-L" "/volume/zola/target/x86_64-unknown-linux-musl/release/build/ring-e6b213b30851ee3d/out" "-L" "/musl/lib" "-L" "/volume/zola/target/x86_64-unknown-linux-musl/release/build/sass-sys-46c51feb898fb45f/out/build/lib" "-L" "/root/.rustup/toolchains/stable-2020-03-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/tmp/rustcRfKRWT/libring-618a352d682617ed.rlib" "/tmp/rustcRfKRWT/libopenssl_sys-226e7cfe5dfe39f7.rlib" "/tmp/rustcRfKRWT/libsass_sys-db0c88bd4bf3fed9.rlib" "/tmp/rustcRfKRWT/libonig_sys-bc9463563034fbd4.rlib" "-Wl,--start-group" "/tmp/rustcRfKRWT/libbacktrace_sys-9a97763b2b5e5e63.rlib" "/tmp/rustcRfKRWT/libunwind-984beb1d09763686.rlib" "/tmp/rustcRfKRWT/liblibc-6c4492b949101b15.rlib" "-Wl,--end-group" "/root/.rustup/toolchains/stable-2020-03-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-c9fca8d265033410.rlib" "-Wl,-Bdynamic" "-lstdc++" "-static" "/root/.rustup/toolchains/stable-2020-03-12-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crtn.o"
  = note: /usr/bin/ld: /tmp/rustcRfKRWT/libsass_sys-db0c88bd4bf3fed9.rlib(json.o): undefined reference to symbol '__fprintf_chk@@GLIBC_2.3.4'
          //lib/x86_64-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

For reference here is the Dockerfile I'm using

ARG RUSTC_VERSION=1.42.0

FROM clux/muslrust:${RUSTC_VERSION}-stable as builder
#FROM rust:${RUSTC_VERSION}-slim-stretch as builder

ENV ZOLA_VERSION 0.10.1

RUN apt-get update -y && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y -q \
    wget

RUN wget https://github.com/getzola/zola/archive/v${ZOLA_VERSION}.tar.gz && \
    mkdir zola && \
    tar -zxvf v${ZOLA_VERSION}.tar.gz -C zola && \
    mv zola/zola-${ZOLA_VERSION}/* zola/ && \
    rm -f v${ZOLA_VERSION}.tar.gz

WORKDIR zola

ENV RUST_BACKTRACE=1

RUN cargo build --release

FROM alpine

COPY --from=builder /zola/target/release/zola /usr/local/bin/

CMD ["zola"]

@DusterTheFirst
Copy link
Contributor

@shalzz I was able to build and run sass-sys on alpine.

Here’s the docker file I used.

https://github.com/DusterTheFirst/sxfs/blob/master/Dockerfile

@Elinvynia
Copy link

Is there any way to compile this fully statically to be used in a scratch container?

@Keats Keats closed this as completed Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants