# ModelRouter GUI Windows builder
# Self-sufficient cross-compilation environment for the embedded llmsproxy core.
# Produces llmsproxy.exe (Go, windows/amd64, luajit tag) + lua51.dll (LuaJIT mingw build)
# inside a mounted workspace: cmd/gui/bin/{llmsproxy.exe,lua51.dll}
#
# Build:   docker build -t modelrouter/win-builder cmd/gui/docker/win-builder
# Usage:   make gui-win-docker   (or cmd/gui/scripts/dist-win-docker.sh)
#
# LuaJIT source is fetched from gitcode.com (CN-reachable mirror) with github
# fallback; pass --build-arg LUAJIT_REPO to override.

FROM golang:1.25

ARG LUAJIT_REPO=https://gitcode.com/openresty/luajit2.git

RUN apt-get update -qq \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
      gcc-mingw-w64-x86-64 make ca-certificates git \
 && rm -rf /var/lib/apt/lists/*

# LuaJIT cross-compiled for Windows; keeps lua51.dll and the cgo import lib
# (libluajit-5.1.dll.a -> libluajit-5.1.a in the mingw lib dir).
# NOTE: $LUAJIT_REPO deliberately unquoted in "sh -c" — quoting the ARG would
#       embed literal quotes into the URL.
RUN git clone --depth 1 $LUAJIT_REPO /opt/luajit2 \
 || git clone --depth 1 https://github.com/openresty/luajit2 /opt/luajit2 \
 && cd /opt/luajit2 \
 && make HOST_CC=gcc CROSS=x86_64-w64-mingw32- TARGET_SYS=Windows TARGET_XCFLAGS=-DLUAJIT_ENABLE_LUA52COMPAT \
 && cp src/libluajit-5.1.dll.a /usr/x86_64-w64-mingw32/lib/libluajit-5.1.a

# Go proxy mirror for builds behind GFW-ish networks; overridable at runtime.
ENV GOPROXY=https://goproxy.cn,direct

WORKDIR /workspace
CMD ["/bin/bash"]
