| 1 |
# x86_64 base |
| 2 |
FROM quay.io/pypa/manylinux2014_x86_64 AS base-amd64 |
| 3 |
# x86_64 builder |
| 4 |
FROM --platform=$BUILDPLATFORM ghcr.io/rust-cross/rust-musl-cross:x86_64-musl AS builder-amd64 |
| 5 |
|
| 6 |
# aarch64 base |
| 7 |
FROM quay.io/pypa/manylinux2014_aarch64 AS base-arm64 |
| 8 |
# aarch64 cross compile builder |
| 9 |
FROM --platform=$BUILDPLATFORM ghcr.io/rust-cross/rust-musl-cross:aarch64-musl AS builder-arm64 |
| 10 |
|
| 11 |
ARG TARGETARCH |
| 12 |
FROM builder-$TARGETARCH AS builder |
| 13 |
|
| 14 |
ENV PATH=/root/.cargo/bin:$PATH |
| 15 |
|
| 16 |
# Compile dependencies only for build caching |
| 17 |
ADD Cargo.toml /maturin/Cargo.toml |
| 18 |
ADD Cargo.lock /maturin/Cargo.lock |
| 19 |
RUN --mount=type=cache,target=/root/.cargo/git \ |
| 20 |
--mount=type=cache,target=/root/.cargo/registry \ |
| 21 |
--mount=type=cache,target=/maturin/target,sharing=locked \ |
| 22 |
mkdir /maturin/src && \ |
| 23 |
touch /maturin/src/lib.rs && \ |
| 24 |
echo 'fn main() { println!("Dummy") }' > /maturin/src/main.rs && \ |
| 25 |
cargo rustc --target $CARGO_BUILD_TARGET --bin maturin --manifest-path /maturin/Cargo.toml --release --features password-storage -- -C link-arg=-s |
| 26 |
|
| 27 |
ADD . /maturin/ |
| 28 |
|
| 29 |
# Manually update the timestamps as ADD keeps the local timestamps and cargo would then believe the cache is fresh |
| 30 |
RUN touch /maturin/src/lib.rs /maturin/src/main.rs |
| 31 |
|
| 32 |
RUN --mount=type=cache,target=/root/.cargo/git \ |
| 33 |
--mount=type=cache,target=/root/.cargo/registry \ |
| 34 |
--mount=type=cache,target=/maturin/target,sharing=locked \ |
| 35 |
cargo rustc --target $CARGO_BUILD_TARGET --bin maturin --manifest-path /maturin/Cargo.toml --release --features password-storage -- -C link-arg=-s \ |
| 36 |
&& mv /maturin/target/$CARGO_BUILD_TARGET/release/maturin /usr/bin/maturin |
| 37 |
|
| 38 |
FROM base-$TARGETARCH |
| 39 |
|
| 40 |
ENV PATH=/root/.cargo/bin:$PATH |
| 41 |
# Add all supported python versions |
| 42 |
ENV PATH=/opt/python/cp39-cp39/bin:/opt/python/cp310-cp310/bin:/opt/python/cp311-cp311/bin:/opt/python/cp312-cp312/bin:/opt/python/cp313-cp313/bin/:/opt/python/cp313-cp313t/bin/:$PATH |
| 43 |
# Otherwise `cargo new` errors |
| 44 |
ENV USER=root |
| 45 |
|
| 46 |
RUN curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ |
| 47 |
&& yum install -y libffi-devel openssh-clients \ |
| 48 |
&& python3.8 -m pip install --no-cache-dir cffi \ |
| 49 |
&& python3.9 -m pip install --no-cache-dir cffi \ |
| 50 |
&& python3.10 -m pip install --no-cache-dir cffi \ |
| 51 |
&& python3.11 -m pip install --no-cache-dir cffi \ |
| 52 |
&& python3.12 -m pip install --no-cache-dir cffi \ |
| 53 |
&& mkdir /io |
| 54 |
|
| 55 |
COPY --from=builder /usr/bin/maturin /usr/bin/maturin |
| 56 |
|
| 57 |
WORKDIR /io |
| 58 |
|
| 59 |
ENTRYPOINT ["/usr/bin/maturin"] |