# Shared build image for fasten-core native libraries.
#
# Produces two artifacts from a single glibc (Debian) build:
#   /fasten/libfasten_core.so  — dynamic, for Python services (Debian/glibc runtime)
#   /fasten/libfasten_core.a   — static archive, for Go services (static-linked Alpine binary)
#
# Build:
#   docker build -t edgebits/fasten-core:latest -f Dockerfile.fasten-core .
#
# Multi-arch (CI):
#   docker buildx build --platform linux/amd64,linux/arm64 \
#     -t edgebits/fasten-core:latest -f Dockerfile.fasten-core . --push
#
# Usage in Python service Dockerfiles:
#   ARG FASTEN_CORE_IMAGE=edgebits/fasten-core:latest
#   FROM ${FASTEN_CORE_IMAGE} AS fasten-core
#   COPY --from=fasten-core /fasten/libfasten_core.so /fasten/
#   ENV FASTEN_CORE_LIB=/fasten/libfasten_core.so
#
# Usage in Go service Dockerfiles (Alpine/musl final image):
#   COPY --from=fasten-core /fasten/libfasten_core.a <release-dir>/
#   Build with: -ldflags="-extldflags '-static'"
#   (static binary has no runtime .so dependency — runs on Alpine)

FROM rust:1.85-slim AS builder
WORKDIR /fasten-core
COPY fasten/fasten-core/ .
# cargo builds both cdylib (.so) and staticlib (.a) per Cargo.toml crate-type
RUN cargo build --release --features all

FROM debian:bookworm-slim
COPY --from=builder /fasten-core/target/release/libfasten_core.so /fasten/libfasten_core.so
COPY --from=builder /fasten-core/target/release/libfasten_core.a   /fasten/libfasten_core.a
