# Multi-platform Rust cross-compilation image
FROM rust:1.94-bookworm

# Install cross-compilation toolchains
RUN apt-get update && apt-get install -y \
    gcc-aarch64-linux-gnu \
    gcc-x86-64-linux-gnu \
    libc6-dev-arm64-cross \
    libc6-dev-amd64-cross \
    mingw-w64 \
    && rm -rf /var/lib/apt/lists/*

# Add Rust targets for all platforms
RUN rustup target add \
    x86_64-unknown-linux-gnu \
    aarch64-unknown-linux-gnu \
    x86_64-apple-darwin \
    aarch64-apple-darwin \
    x86_64-pc-windows-gnu

# Install cargo-zigbuild for easier cross-compilation (especially macOS)
RUN curl -sSL https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz | tar -xJ -C /opt \
    && ln -s /opt/zig-linux-x86_64-0.13.0/zig /usr/local/bin/zig
RUN cargo install cargo-zigbuild

# Configure linkers for cross-compilation
RUN mkdir -p /.cargo
RUN echo '[target.aarch64-unknown-linux-gnu]\nlinker = "aarch64-linux-gnu-gcc"\n\n[target.x86_64-pc-windows-gnu]\nlinker = "x86_64-w64-mingw32-gcc"\n' > /.cargo/config.toml

WORKDIR /build

ENTRYPOINT ["/bin/bash"]
