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

Unable to build ring for aarch64-unknown-linux-musl #2127

Open
Timtam opened this issue Jul 12, 2024 · 2 comments
Open

Unable to build ring for aarch64-unknown-linux-musl #2127

Timtam opened this issue Jul 12, 2024 · 2 comments

Comments

@Timtam
Copy link

Timtam commented Jul 12, 2024

Hello,

first of all, sorry if I'll be missing important info here, i'm really unexperienced with linkers, compilers and stuff like that.

I am developing a Rust app that seems to be using ring as one of its sub-dependencies. Until now I built using the official rust docker image and deployed it into a debian-slim-bookworm container, which works just fine for amd_64 and arm64 containers. I however wanted to try to reduce the final image size and thus tried to switch to a musl-based clux/muslrust build image and a final alpine:3.20 deployment container. Everything works just fine with amd_64, but ring seems to fail the build process when building for arm64 (aarch64). Here's the dockerfile:

FROM node:20 AS client_build_image

WORKDIR /app

COPY ./client /app
COPY ./server/Cargo.toml /app/Cargo.toml

RUN npm install && npm run build

FROM clux/muslrust:1.79.0-stable AS server_build_image

# create a new empty shell project
RUN USER=root cargo new --bin /hitster

WORKDIR /hitster

# copy over your manifests
COPY ./server/Cargo.toml ./Cargo.toml

# this build step will cache your dependencies
RUN cargo build --release && \
    rm ./src/*.rs

# copy your source tree
COPY ./server/migrations ./migrations
COPY ./server/src ./src
COPY ./server/build.rs ./build.rs
COPY ./server/etc ./etc

# build for release
RUN rm ./target/x86_64-unknown-linux-musl/release/deps/hitster* && \
    cargo build --release

FROM alpine:3.20

# yt-dlp version
ARG YT_DLP_BUILD_VERSION=2024.07.09

WORKDIR /hitster

ENV CLIENT_DIRECTORY=/hitster/client
ENV PATH="$PATH:/opt/ffmpeg/bin/"
ENV USE_YT_DLP=true
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

# prepare the OS

RUN set -x && \
    apk update && \
    apk upgrade -a && \
    apk add --no-cache ca-certificates ffmpeg python3 py3-mutagen && \
    mkdir /.cache && \
    chmod 777 /.cache

# copy the build artifact from the build stage
COPY --from=server_build_image /hitster/target/x86_64-unknown-linux-musl/release/hitster-server /hitster/server/hitster
COPY --from=client_build_image /app/dist /hitster/client

# yt-dlp

ADD --chmod=777 https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_BUILD_VERSION}/yt-dlp /usr/local/bin/yt-dlp

# set the startup command to run your binary
CMD ["/hitster/server/hitster"]

The project repository with all the necessary files can be found here: https://github.com/Timtam/hitster

I know I do have a different problem within my final stage with being unable to copy the build from the correct path when building for arm64, but the build process already fails before reaching that point with an error like this:

496.2 error: failed to run custom build command for `ring v0.17.8`                                                      
496.2                                                                                                                   
496.2 Caused by:                                                                                                        
496.2   process didn't exit successfully: `/hitster/target/release/build/ring-e57f28357ba90b86/build-script-build` (exit status: 1)                                                                                                             
496.2   --- stdout                                                                                                      
496.2   cargo:rerun-if-env-changed=RING_PREGENERATE_ASM                                                                 
496.2   cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_8_                                                              
496.2   OPT_LEVEL = Some(z)                                                                                             
496.2   TARGET = Some(aarch64-unknown-linux-musl)                                                                       
496.2   OUT_DIR = Some(/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out)              
496.2   HOST = Some(aarch64-unknown-linux-gnu)                                                                          
496.2   cargo:rerun-if-env-changed=CC_aarch64-unknown-linux-musl                                                        
496.2   CC_aarch64-unknown-linux-musl = None                                                                            
496.2   cargo:rerun-if-env-changed=CC_aarch64_unknown_linux_musl                                                        
496.2   CC_aarch64_unknown_linux_musl = None                                                                            
496.2   cargo:rerun-if-env-changed=TARGET_CC                                                                            
496.2   TARGET_CC = None                                                                                                
496.2   cargo:rerun-if-env-changed=CC                                                                                   
496.2   CC = Some(musl-gcc)                                                                                             
496.2   RUSTC_WRAPPER = None                                                                                            
496.2   cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT                                                               
496.2   cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS                                                                 
496.2   CRATE_CC_NO_DEFAULTS = None                                                                                     
496.2   DEBUG = Some(false)                                                                                             
496.2   CARGO_CFG_TARGET_FEATURE = Some(crt-static,neon)                                                                
496.2   cargo:rerun-if-env-changed=CFLAGS_aarch64-unknown-linux-musl                                                    
496.2   CFLAGS_aarch64-unknown-linux-musl = None                                                                        
496.2   cargo:rerun-if-env-changed=CFLAGS_aarch64_unknown_linux_musl                                                    
496.2   CFLAGS_aarch64_unknown_linux_musl = None                                                                        
496.2   cargo:rerun-if-env-changed=TARGET_CFLAGS                                                                        
496.2   TARGET_CFLAGS = None                                                                                            
496.2   cargo:rerun-if-env-changed=CFLAGS                                                                               
496.2   CFLAGS = None                                                                                                   
496.2                                                                                                                   
496.2   --- stderr                                                                                                      
496.2                                                                                                                   
496.2                                                                                                                   
496.2   error occurred: Command ZERO_AR_DATE="1" "aarch64-linux-musl-ar" "cq" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/libring_core_0_17_8_.a" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/fad98b632b8ce3cc-curve25519.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca4b6ef5433f5aeb-aes_nohw.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca8bd8684bb569fa-montgomery.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca8bd8684bb569fa-montgomery_inv.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/a9af75d892b04b75-ecp_nistz.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/a9af75d892b04b75-gfp_p256.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/a9af75d892b04b75-gfp_p384.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/a9af75d892b04b75-p256.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/a1949f2101df4b9c-limbs.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/7effb53edfc7fa2d-mem.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/bec76f70393ddef1-poly1305.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/7effb53edfc7fa2d-crypto.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/a9af75d892b04b75-p256-nistz.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-aesv8-armx-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-ghashv8-armx-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-chacha-armv8-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-chacha20_poly1305_armv8-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-vpaes-armv8-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-armv8-mont-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-p256-armv8-asm-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-ghash-neon-armv8-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-aesv8-gcm-armv8-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-sha512-armv8-linux64.o" "/hitster/target/aarch64-unknown-linux-musl/release/build/ring-70892c10ae014e24/out/ca5a6bd8bd60c5f6-sha256-armv8-linux64.o" with args aarch64-linux-musl-ar did not execute successfully (status code exit status: 127).                                                                                                        
496.2                                                                                                                   
496.2                                                                                                                   
496.2 warning: build failed, waiting for other jobs to finish...                                                        

I'm trying to build with good old docker build -t hitster --platform linux/arm64 .
I don't know if i'm doing anything wrong or if ring is the issue, but maybe someone is able to help me? Thank you. Please let me know if I can give you any more useful information.

@gcavelier
Copy link

Same isse here, using rust:1.79.0-slim-bookworm as my builder image

@mpaperno
Copy link

Apparently the linker and compiler need to be specified... so says the Internet (and some other issues on this repo, like #1414, #2131).

export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc &&
export CC=aarch64-linux-gnu-gcc &&

I had the exact same error, and this was the final magic to getting ring built as a dependency of another project (or sub[, sub ...]dep... I'm not even sure to what, exactly).

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

3 participants