|
| 1 | +# Dockerfile for cross-compiling bisonw-desktop.exe for Windows from Linux. |
| 2 | +# |
| 3 | +# Prerequisites: |
| 4 | +# The site bundle must be built before running the docker build: |
| 5 | +# cd client/webserver/site && npm clean-install && npm run build |
| 6 | +# |
| 7 | +# Build (from the repo root): |
| 8 | +# docker build -t bisonw-desktop-windows -f client/cmd/bisonw-desktop/windows/Dockerfile . |
| 9 | +# |
| 10 | +# Build with XMR support: |
| 11 | +# docker build -t bisonw-desktop-windows --build-arg XMR=1 -f client/cmd/bisonw-desktop/windows/Dockerfile . |
| 12 | +# |
| 13 | +# Extract the exe and DLLs: |
| 14 | +# mkdir -p build && docker run --rm bisonw-desktop-windows tar -cf - -C /out . | tar -xf - -C ./build |
| 15 | + |
| 16 | +FROM golang:1.24-bookworm |
| 17 | + |
| 18 | +ENV DEBIAN_FRONTEND=noninteractive |
| 19 | + |
| 20 | +RUN apt-get update && apt-get install -y \ |
| 21 | + gcc-mingw-w64-x86-64 \ |
| 22 | + g++-mingw-w64-x86-64 \ |
| 23 | + mingw-w64-tools \ |
| 24 | + unzip \ |
| 25 | + && rm -rf /var/lib/apt/lists/* |
| 26 | + |
| 27 | +ARG XMR=0 |
| 28 | +ARG WEBVIEW2_VERSION=1.0.3856.49 |
| 29 | + |
| 30 | +COPY . /src |
| 31 | +WORKDIR /src/client/cmd/bisonw-desktop |
| 32 | + |
| 33 | +# Fetch the WebView2 NuGet package for the runtime DLL (WebView2Loader.dll). |
| 34 | +RUN mkdir -p /tmp/webview2 && \ |
| 35 | + curl -sSL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/${WEBVIEW2_VERSION}" -o /tmp/webview2.zip && \ |
| 36 | + unzip -q /tmp/webview2.zip -d /tmp/webview2 && \ |
| 37 | + rm /tmp/webview2.zip |
| 38 | + |
| 39 | +# Create a stub EventToken.h. The webview_go module's bundled WebView2.h |
| 40 | +# includes this Windows SDK header, which MinGW does not provide. |
| 41 | +RUN mkdir -p /tmp/winsdk && \ |
| 42 | + printf '#pragma once\ntypedef struct EventRegistrationToken { __int64 value; } EventRegistrationToken;\n' \ |
| 43 | + > /tmp/winsdk/EventToken.h |
| 44 | + |
| 45 | +# Generate a MinGW import library for the XMR DLL. The MinGW linker cannot |
| 46 | +# link directly against a .dll. Named .a (not .dll.a) because webview_go's |
| 47 | +# CGO LDFLAGS include -static, which makes the linker skip .dll.a files. |
| 48 | +RUN if [ "$XMR" = "1" ]; then \ |
| 49 | + cd /src/client/asset/xmr/lib/windows-amd64 && \ |
| 50 | + gendef libwallet2_api_c.dll && \ |
| 51 | + x86_64-w64-mingw32-dlltool -d libwallet2_api_c.def \ |
| 52 | + -l libwallet2_api_c.a -D libwallet2_api_c.dll; \ |
| 53 | + fi |
| 54 | + |
| 55 | +RUN mkdir -p /out |
| 56 | + |
| 57 | +ENV GOOS=windows |
| 58 | +ENV GOARCH=amd64 |
| 59 | +ENV CGO_ENABLED=1 |
| 60 | +ENV CC=x86_64-w64-mingw32-gcc |
| 61 | +ENV CXX=x86_64-w64-mingw32-g++ |
| 62 | +ENV CGO_CXXFLAGS="-I/tmp/winsdk" |
| 63 | + |
| 64 | +RUN if [ "$XMR" = "1" ]; then \ |
| 65 | + go build -v -tags xmr -ldflags="-H windowsgui" -o /out/bisonw-desktop.exe; \ |
| 66 | + else \ |
| 67 | + go build -v -ldflags="-H windowsgui" -o /out/bisonw-desktop.exe; \ |
| 68 | + fi |
| 69 | + |
| 70 | +# Bundle runtime DLLs that are not present on a stock Windows install. |
| 71 | +RUN cp /tmp/webview2/runtimes/win-x64/native/WebView2Loader.dll /out/ && \ |
| 72 | + cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll /out/ |
| 73 | + |
| 74 | +RUN if [ "$XMR" = "1" ]; then \ |
| 75 | + cp /src/client/asset/xmr/lib/windows-amd64/libwallet2_api_c.dll /out/; \ |
| 76 | + fi |
0 commit comments