# Dockerfile for building synor-crypto-wasm WASM module
# This builds the post-quantum cryptography WASM module for the web wallet

FROM rust:latest AS builder

# Install required tools
RUN apt-get update && apt-get install -y \
    curl \
    pkg-config \
    libssl-dev \
    && rm -rf /var/lib/apt/lists/*

# Install wasm-pack
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Install wasm32 target
RUN rustup target add wasm32-unknown-unknown

# Create workspace
WORKDIR /build

# Copy Cargo files first for dependency caching
COPY Cargo.toml Cargo.lock* ./
COPY .cargo .cargo

# Copy source code
COPY src ./src

# Build for bundler target (for Vite)
RUN wasm-pack build \
    --target bundler \
    --out-dir /output/pkg \
    --out-name synor_crypto \
    --release

# Build for web target (direct browser)
RUN wasm-pack build \
    --target web \
    --out-dir /output/pkg-web \
    --out-name synor_crypto \
    --release

# Final stage - just copy the built files
FROM scratch AS output

COPY --from=builder /output /output
