# syntax=docker/dockerfile:1
ARG ALPINE_VERSION="3.20"

FROM rustlang/rust:nightly-alpine$ALPINE_VERSION AS builder
# https://github.com/rust-lang/rustup/issues/1239
RUN rustup toolchain uninstall nightly-x86_64-unknown-linux-musl

RUN apk add --no-cache musl-dev

RUN mkdir /root/natter
WORKDIR /root/natter
COPY --link . .
# TODO: Add static build, which currently errors due to proc_macro. RUSTFLAGS="-C target-feature=+crt-static"
RUN --mount=type=tmpfs,target=/tmp --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked CARGO_TARGET_DIR=/target cargo build --profile lto

FROM alpine:$ALPINE_VERSION AS runner

COPY --link --from=builder /target/lto/natter /usr/bin/
