Skip to content

Commit

Permalink
Merge pull request #211 from Mossaka/release-dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
cpuguy83 authored Jul 31, 2023
2 parents fd8fa40 + 440916b commit d02c2c0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
# Make sure to keep in sync with the version in rust-toolchain.toml
ARG RUST_VERSION=1.71

ARG XX_VERSION=1.1.0
ARG XX_VERSION=1.2.1

FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx

FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION} AS base
COPY --from=xx / /
RUN apt-get update -y && apt-get install --no-install-recommends -y clang jq wget
RUN apt-get update -y && apt-get install --no-install-recommends -y clang pkg-config dpkg-dev jq

# See https://github.com/tonistiigi/xx/issues/108
RUN sed -i -E 's/xx-clang --setup-target-triple/XX_VENDOR=\$vendor xx-clang --setup-target-triple/' $(which xx-cargo) && \
sed -i -E 's/\$\(xx-info\)-/\$\(XX_VENDOR=\$vendor xx-info\)-/g' $(which xx-cargo)

FROM base AS build
SHELL ["/bin/bash", "-c"]
ARG BUILD_TAGS TARGETPLATFORM
RUN xx-apt-get install -y gcc g++ libc++6-dev zlib1g
RUN xx-apt-get install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
RUN rustup target add $(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)
RUN xx-apt-get install -y libsystemd-dev libdbus-1-dev libseccomp-dev

WORKDIR /build/src
COPY --link crates ./crates
Expand All @@ -25,18 +28,17 @@ COPY --link Cargo.toml ./
COPY --link Cargo.lock ./
ARG CRATE=""
ARG TARGETOS TARGETARCH TARGETVARIANT

RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry/cache \
--mount=type=cache,target=/usr/local/cargo/registry/index \
--mount=type=cache,target=/build/src/target,id=runwasi-cargo-build-cache-${TARGETOS}-${TARGETARCH}${TARGETVARIANT} <<EOT
set -e
export "CARGO_NET_GIT_FETCH_WITH_CLI=true"
export "CARGO_TARGET_$(xx-info march | tr '[:lower:]' '[:upper:]' | tr - _)_UNKNOWN_$(xx-info os | tr '[:lower:]' '[:upper:]' | tr - _)_$(xx-info libc | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER=$(xx-info)-gcc"
export "CC_$(xx-info march | tr '[:lower:]' '[:upper:]' | tr - _)_UNKNOWN_$(xx-info os | tr '[:lower:]' '[:upper:]' | tr - _)_$(xx-info libc | tr '[:lower:]' '[:upper:]' | tr - _)=$(xx-info)-gcc"
if [ -n "${CRATE}" ]; then
package="--package=${CRATE}"
fi
cargo build --release --target=$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc) ${package}
xx-cargo build --release ${package}
EOT
COPY scripts ./scripts
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
Expand All @@ -48,7 +50,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/git/db \
bins="$(scripts/bins.sh ${CRATE} | jq -r 'join(" ")')"
echo "Copying binaries: ${bins}"
for bin in ${bins}; do
cp target/$(xx-info march)-unknown-$(xx-info os)-$(xx-info libc)/release/${bin} /build/bin/${bin}
cp target/$(xx-cargo --print-target-triple)/release/${bin} /build/bin/${bin}
done
EOT

Expand Down

0 comments on commit d02c2c0

Please sign in to comment.