Rocket: Building Rocket for Alpine Targets Fails

Created on 6 Jul 2019  路  3Comments  路  Source: SergioBenitez/Rocket

I'm trying to build an app using Rocket to run on an Alpine image, but I get a build error because of linked dependencies.

Details of Cargo.yml/Cargo.lock.

https://gist.github.com/marceloboeira/478e02894f817afb093b073a2e7466c6

CARGO_CFG_TARGET_FEATURE = Some("crt-static,fxsr,mmx,sse,sse2")
running "musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-static" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wenum
-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-declarations" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wundef" "-W
uninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-Wno-cast-align" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-D_XOPEN_SOURCE=700" "-c" "-o/target/x86_64-unknown-linux-musl/release/build/ring-039e047ee579cc4d/out/aes-x86_64-elf.o" "/Users/marcelo_boeira/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.13.5/pr
egenerated/aes-x86_64-elf.S"

--- stderr
thread 'main' panicked at 'failed to execute ["musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-static" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra
" "-Wcast-align" "-Wcast-qual" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-declarations" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-W
shadow" "-Wsign-compare" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-Wno-cast-align" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-D_XOPEN_SOURCE=
700" "-c" "-o/Users/marcelo_boeira/Development/marceloboeira/kurz/api/target/x86_64-unknown-linux-musl/release/build/ring-039e047ee579cc4d/out/aes-x86_64-elf.o" "/Users/marcelo_boeira/.cargo/registry/src/gith
ub.com-1ecc6299db9ec823/ring-0.13.5/pregenerated/aes-x86_64-elf.S"]: No such file or directory (os error 2)', /.../.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.13.5/build.rs:642:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
upstream

Most helpful comment

thanks @SergioBenitez, I've opened an issue there.

thanks @jebrosen, I've managed to compile now and run the alpine target.

For future reference, I'm compiling using: https://github.com/emk/rust-musl-builder

In very simple terms:

FROM ekidd/rust-musl-builder:nightly-2019-06-08 AS rust-build

# Add alpine target
RUN rustup target add x86_64-unknown-linux-musl

# Re-own home
# https://github.com/emk/rust-musl-builder#making-static-releases-with-travis-ci-and-github
RUN sudo chown -R rust:rust /home

# Install and cache dependencies layers
# Rather than copying everything every time, re-use cached dependency layers
# to install/build deps only when Cargo.* files change.
RUN USER=root cargo new /home/my-app --bin

WORKDIR /home/my-app
COPY api/Cargo.lock ./Cargo.lock
COPY api/Cargo.toml ./Cargo.toml
RUN cargo build --bins --release --target x86_64-unknown-linux-musl

# Load real sources
RUN rm src/*.rs
COPY api/src ./src

# Rebuild with real sources
RUN rm ./target/x86_64-unknown-linux-musl/release/deps/my-app*
RUN cargo build --bins --release --target x86_64-unknown-linux-musl


FROM alpine:3.9.4

WORKDIR /home

# Copy Rust artifacts
COPY --from=rust-build /home/my-app/target/x86_64-unknown-linux-musl/release/my-app .

EXPOSE 8000
CMD ["./my-app"]

All 3 comments

This an issue with ring. I would suggest asking on their issue tracker.

If you haven't installed it already, musl-gcc itself is provided by musl or musl-tools depending on your operating system and is required to compile and link least C and assembly (such as in ring) for the musl target.

thanks @SergioBenitez, I've opened an issue there.

thanks @jebrosen, I've managed to compile now and run the alpine target.

For future reference, I'm compiling using: https://github.com/emk/rust-musl-builder

In very simple terms:

FROM ekidd/rust-musl-builder:nightly-2019-06-08 AS rust-build

# Add alpine target
RUN rustup target add x86_64-unknown-linux-musl

# Re-own home
# https://github.com/emk/rust-musl-builder#making-static-releases-with-travis-ci-and-github
RUN sudo chown -R rust:rust /home

# Install and cache dependencies layers
# Rather than copying everything every time, re-use cached dependency layers
# to install/build deps only when Cargo.* files change.
RUN USER=root cargo new /home/my-app --bin

WORKDIR /home/my-app
COPY api/Cargo.lock ./Cargo.lock
COPY api/Cargo.toml ./Cargo.toml
RUN cargo build --bins --release --target x86_64-unknown-linux-musl

# Load real sources
RUN rm src/*.rs
COPY api/src ./src

# Rebuild with real sources
RUN rm ./target/x86_64-unknown-linux-musl/release/deps/my-app*
RUN cargo build --bins --release --target x86_64-unknown-linux-musl


FROM alpine:3.9.4

WORKDIR /home

# Copy Rust artifacts
COPY --from=rust-build /home/my-app/target/x86_64-unknown-linux-musl/release/my-app .

EXPOSE 8000
CMD ["./my-app"]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

loothood picture loothood  路  4Comments

Turakar picture Turakar  路  4Comments

sphinxc0re picture sphinxc0re  路  3Comments

denysvitali picture denysvitali  路  3Comments

lucklove picture lucklove  路  4Comments