Skip to content

Commit

Permalink
Add mold linker support
Browse files Browse the repository at this point in the history
  • Loading branch information
ffuugoo committed Apr 12, 2023
1 parent 2e41cbd commit 559bed6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -22,17 +22,40 @@ ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}

RUN xx-apt-get install -y gcc g++ libc6-dev

ARG BUILDPLATFORM
ENV BUILDPLATFORM=${BUILDPLATFORM:-linux/amd64}

ARG PROFILE=release
ARG FEATURES
ARG RUSTFLAGS

ARG LINKER=lld
ARG MOLD_VERSION=1.11.0

RUN if [ "$LINKER" = mold ]; then \
case "$BUILDPLATFORM" in \
*/amd64 ) PLATFORM=x86_64 ;; \
*/arm64 | */arm64/* ) PLATFORM=aarch64 ;; \
* ) echo "Unexpected BUILDPLATFORM '$BUILDPLATFORM'" >&2; exit 1 ;; \
esac; \
\
mkdir -p /opt/mold; \
cd /opt/mold; \
\
TARBALL="mold-$MOLD_VERSION-$PLATFORM-linux.tar.gz"; \
curl -sSLO "https://github.com/rui314/mold/releases/download/v$MOLD_VERSION/$TARBALL"; \
tar -xf "$TARBALL" --strip-components 1; \
rm "$TARBALL"; \
fi

COPY --from=planner /qdrant/recipe.json recipe.json
RUN RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \
RUN PATH="$PATH:/opt/mold/bin" \
RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \
xx-cargo chef cook --profile $PROFILE ${FEATURES:+--features} $FEATURES --recipe-path recipe.json

COPY . .
RUN RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \
RUN PATH="$PATH:/opt/mold/bin" \
RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \
xx-cargo build --profile $PROFILE ${FEATURES:+--features} $FEATURES --bin qdrant \
&& PROFILE_DIR=$(if [ "$PROFILE" = dev ]; then echo debug; else echo $PROFILE; fi) \
&& mv target/$(xx-cargo --print-target-triple)/$PROFILE_DIR/qdrant /qdrant/qdrant

0 comments on commit 559bed6

Please sign in to comment.