From 6e29c7cd9d2a2b6629839606e2cf6d570e714530 Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Wed, 29 Oct 2025 14:56:13 +0100 Subject: [PATCH] feat(docker): add Windows cross-compilation support via Docker Add Dockerfile.windows and build-windows.sh for cross-compiling Windows executables in a containerized environment. Includes documentation updates in README.md with build instructions and troubleshooting tips for Windows builds. --- docker-build/Dockerfile.windows | 18 +++++++++ docker-build/README.md | 65 ++++++++++++++++++++++++++++++++- docker-build/build-windows.sh | 63 ++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 docker-build/Dockerfile.windows create mode 100644 docker-build/build-windows.sh diff --git a/docker-build/Dockerfile.windows b/docker-build/Dockerfile.windows new file mode 100644 index 0000000..1df9a76 --- /dev/null +++ b/docker-build/Dockerfile.windows @@ -0,0 +1,18 @@ +FROM ubuntu:20.04 + +ENV DEBIAN_FRONTEND=noninteractive TZ=UTC + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential libtool autotools-dev automake autoconf pkg-config \ + bsdmainutils python3 curl ca-certificates git unzip zip file rsync \ + g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 nsis \ + && rm -rf /var/lib/apt/lists/* + +RUN update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix || true && \ + update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix || true + +WORKDIR /src + +COPY . /src + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/docker-build/README.md b/docker-build/README.md index 96835c2..479dc0a 100644 --- a/docker-build/README.md +++ b/docker-build/README.md @@ -62,4 +62,67 @@ docker run --rm -it -v "$(pwd)/../build/linux-x86_64":/out palladium-builder:lin **Docker build issues:** Ensure Docker has sufficient resources and the daemon is running -**Missing dependencies:** The Dockerfile installs all required build dependencies automatically \ No newline at end of file +**Missing dependencies:** The Dockerfile installs all required build dependencies automatically + +## Windows x86_64 Build + +### Overview + +This build creates Windows x86_64 executables using cross-compilation in a Docker container based on Ubuntu 20.04. The build process: + +1. **Builds a Docker image** (`palladium-builder:windows-ubuntu20.04`) containing MinGW-w64 cross-compilation toolchain +2. **Copies the entire repository** into the container during image build +3. **Cross-compiles for Windows** using the `depends` system with `x86_64-w64-mingw32` target +4. **Outputs .exe files** to a mounted volume for host access + +### Quick Start + +```bash +cd docker-build +chmod +x build-windows.sh +./build-windows.sh +``` + +Windows executables will be available in `../build/windows/` directory. + +### Prerequisites + +- Docker installed and running ([installation guide](https://docs.docker.com/get-docker/)) +- Sufficient disk space for the build process (at least 12 GB free) +- Internet connection for downloading dependencies and MinGW-w64 toolchain + +### Produced Executables + +The following Windows executables are built and copied to the output directory: + +- `palladiumd.exe`: Main daemon +- `palladium-cli.exe`: Command-line client +- `palladium-tx.exe`: Transaction utility +- `palladium-wallet.exe`: Wallet utility +- `palladium-qt.exe`: GUI application (if Qt dependencies are available) + +### Output Directory + +Executables are placed in: `../build/windows/` (relative to the docker-build directory) + +### Cross-Compilation Details + +- **Target Triple**: `x86_64-w64-mingw32` +- **Toolchain**: MinGW-w64 cross-compiler +- **Dependencies**: Built using the `depends` system for Windows target +- **Configuration**: Uses `CONFIG_SITE` for proper cross-compilation setup + +### Troubleshooting + +**Permission errors:** The build script automatically handles file permissions using host UID/GID + +**Build failed:** Run interactive container for debugging: +```bash +docker run --rm -it -v "$(pwd)/../build/windows":/out palladium-builder:windows-ubuntu20.04 bash +``` + +**Cross-compilation issues:** Ensure the MinGW-w64 toolchain is properly installed in the container + +**Missing .exe files:** Check that the configure script detected the Windows target correctly + +**Docker build issues:** Ensure Docker has sufficient resources and the daemon is running \ No newline at end of file diff --git a/docker-build/build-windows.sh b/docker-build/build-windows.sh new file mode 100644 index 0000000..638ba92 --- /dev/null +++ b/docker-build/build-windows.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +set -euo pipefail + +IMAGE_NAME="palladium-builder:windows-ubuntu20.04" +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" +OUT_DIR="${REPO_DIR}/build/windows" +HOST_TRIPLE="x86_64-w64-mingw32" + +HOST_UID="$(id -u)" +HOST_GID="$(id -g)" + +echo "[*] Building Docker image including the ENTIRE repository (COPY . /src)..." + +docker build --platform=linux/amd64 \ + -t "$IMAGE_NAME" \ + -f "${SCRIPT_DIR}/Dockerfile.windows" \ + "${REPO_DIR}" + +mkdir -p "${OUT_DIR}" + +echo "[*] Starting container: build COMPLETELY in container; mount ONLY the output..." +docker run --rm --platform=linux/amd64 \ + -e HOST_UID="${HOST_UID}" -e HOST_GID="${HOST_GID}" \ + -v "${OUT_DIR}":/out \ + "$IMAGE_NAME" \ + bash -c " + set -euo pipefail + cd /src + + echo '[*] depends (Windows cross, HOST=${HOST_TRIPLE})...' + cd depends && make HOST=${HOST_TRIPLE} -j\$(nproc) && cd .. + + echo '[*] autogen/configure...' + [[ -x ./autogen.sh ]] && ./autogen.sh + [[ -f ./configure ]] || { echo 'configure not found: autogen failed'; exit 1; } + + # For Windows with depends: use CONFIG_SITE and prefix=/ + CONFIG_SITE=\$PWD/depends/${HOST_TRIPLE}/share/config.site \ + ./configure --prefix=/ + + echo '[*] make...' + make -j\$(nproc) + + echo '[*] copying .exe files to /out...' + mkdir -p /out + # Typical executables (update the names if your project produces different ones) + for b in \ + src/palladiumd.exe \ + src/palladium-cli.exe \ + src/palladium-tx.exe \ + src/palladium-wallet.exe \ + src/qt/palladium-qt.exe; do + [[ -f \"\$b\" ]] && install -m 0755 \"\$b\" /out/ + done + + # Align permissions to host user + chown -R \${HOST_UID:-0}:\${HOST_GID:-0} /out + + echo '[*] build COMPLETED (everything in container) → /out' + " + +echo "[*] Windows executables available in: ${OUT_DIR}" \ No newline at end of file