Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
uses: docker/build-push-action@v7
with:
context: .
build-args: VARIANT=x64
tags: w64devkit:${{ env.ARCH }}
load: true
cache-from: type=gha,scope=w64devkit-${{ env.ARCH }}
Expand Down Expand Up @@ -97,9 +98,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Apply x86 patch
run: patch -p1 -i src/variant-x86.patch

- name: Generate archive name and version string
id: filename
run: |
Expand All @@ -112,6 +110,7 @@ jobs:
uses: docker/build-push-action@v7
with:
context: .
build-args: VARIANT=x86
tags: w64devkit:${{ env.ARCH }}
load: true
cache-from: type=gha,scope=w64devkit-${{ env.ARCH }}
Expand Down Expand Up @@ -159,6 +158,7 @@ jobs:
uses: docker/build-push-action@v7
with:
context: .
build-args: VARIANT=x64
target: signed
tags: w64devkit:x64-signed
load: true
Expand All @@ -175,13 +175,11 @@ jobs:
> w64devkit-x64-${{ steps.filename.outputs.version }}.7z.exe
ls -lh w64devkit-x64-${{ steps.filename.outputs.version }}.7z.exe

- name: Apply x86 patch
run: patch -p1 -i src/variant-x86.patch

- name: Build signed image (x86)
uses: docker/build-push-action@v7
with:
context: .
build-args: VARIANT=x86
target: signed
tags: w64devkit:x86-signed
load: true
Expand Down
202 changes: 185 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG VERSION=2.9.1 \
PREFIX=/w64devkit
ARG VARIANT=x64

FROM debian:trixie-slim AS base
ARG PREFIX
Expand Down Expand Up @@ -207,9 +208,33 @@ RUN mkdir nsis \

# Build cross-compiler

FROM dl-cross AS cross
ARG ARCH=x86_64-w64-mingw32
ENV ARCH=$ARCH
FROM dl-cross AS variant-x64
ENV ARCH=x86_64-w64-mingw32 \
GCC_ARCH_FLAG=--with-arch-32=pentium4 \
GCC_MULTILIB=enable \
CRT_LIB32=enable \
CRT_LIB64=enable \
GCC_MANIFEST_FLAG="" \
BUSYBOX_CONFIG=mingw64u_defconfig \
ZSTD_THREAD_FLAG="" \
CMAKE_WINNT_C_FLAGS="" \
CMAKE_WINNT_CXX_FLAGS="" \
NSIS_ARCH=amd64

FROM dl-cross AS variant-x86
ENV ARCH=i686-w64-mingw32 \
GCC_ARCH_FLAG=--with-arch=pentium4 \
GCC_MULTILIB=disable \
CRT_LIB32=enable \
CRT_LIB64=disable \
GCC_MANIFEST_FLAG=--disable-win32-utf8-manifest \
BUSYBOX_CONFIG=mingw32w_defconfig \
ZSTD_THREAD_FLAG=HAVE_THREAD=0 \
CMAKE_WINNT_C_FLAGS="-O2 -D_WIN32_WINNT=0x0601" \
CMAKE_WINNT_CXX_FLAGS="-O2 -D_WIN32_WINNT=0x0601" \
NSIS_ARCH=x86

FROM variant-${VARIANT} AS cross

WORKDIR /dl/binutils
COPY src/binutils-*.patch $PREFIX/src/
Expand Down Expand Up @@ -253,6 +278,8 @@ RUN cat $PREFIX/src/gcc-*.patch | patch -d/dl/gcc -p1 \
&& /dl/gcc/configure \
--prefix=/bootstrap \
--with-sysroot=/bootstrap \
$GCC_ARCH_FLAG \
--${GCC_MULTILIB}-multilib \
--target=$ARCH \
--enable-static \
--disable-shared \
Expand All @@ -266,7 +293,6 @@ RUN cat $PREFIX/src/gcc-*.patch | patch -d/dl/gcc -p1 \
--disable-dependency-tracking \
--disable-nls \
--disable-lto \
--disable-multilib \
CFLAGS_FOR_TARGET="-O2" \
CXXFLAGS_FOR_TARGET="-O2" \
LDFLAGS_FOR_TARGET="-s" \
Expand All @@ -285,7 +311,16 @@ RUN mkdir -p $PREFIX/lib \
&& ln $PREFIX/lib/libmemory.a /bootstrap/lib/ \
&& CC=$ARCH-gcc AR=$ARCH-ar DESTDIR=$PREFIX/lib/ \
sh $PREFIX/src/libchkstk.S \
&& ln $PREFIX/lib/libchkstk.a /bootstrap/lib/
&& ln $PREFIX/lib/libchkstk.a /bootstrap/lib/ \
&& if [ "$GCC_MULTILIB" = enable ]; then \
mkdir -p $PREFIX/lib32 /bootstrap/lib32 \
&& CC="$ARCH-gcc -m32" AR=$ARCH-ar DESTDIR=$PREFIX/lib32/ \
sh $PREFIX/src/libmemory.c \
&& ln $PREFIX/lib32/libmemory.a /bootstrap/lib32/ \
&& CC="$ARCH-gcc -m32" AR=$ARCH-ar DESTDIR=$PREFIX/lib32/ \
sh $PREFIX/src/libchkstk.S \
&& ln $PREFIX/lib32/libchkstk.a /bootstrap/lib32/ ; \
fi

WORKDIR /x-mingw-crt
RUN /dl/mingw/mingw-w64-crt/configure \
Expand All @@ -294,8 +329,8 @@ RUN /dl/mingw/mingw-w64-crt/configure \
--host=$ARCH \
--with-default-msvcrt=msvcrt-os \
--disable-dependency-tracking \
--disable-lib32 \
--enable-lib64 \
--${CRT_LIB32}-lib32 \
--${CRT_LIB64}-lib64 \
CFLAGS="-O2" \
LDFLAGS="-s" \
&& make -j$(nproc) \
Expand All @@ -313,6 +348,22 @@ RUN /dl/mingw/mingw-w64-libraries/winpthreads/configure \
&& make -j$(nproc) \
&& make install

WORKDIR /x-winpthreads32
RUN if [ "$GCC_MULTILIB" = enable ]; then \
/dl/mingw/mingw-w64-libraries/winpthreads/configure \
--prefix=/bootstrap \
--libdir=/bootstrap/lib32 \
--with-sysroot=/bootstrap \
--host=$ARCH \
--enable-static \
--disable-shared \
CC="$ARCH-gcc -m32" \
CFLAGS="-O2" \
LDFLAGS="-s" \
&& make -j$(nproc) \
&& make install ; \
fi

WORKDIR /x-gcc
RUN make -j$(nproc) \
&& make install
Expand All @@ -331,7 +382,7 @@ RUN /dl/binutils/configure \
LDFLAGS="-s" \
&& make MAKEINFO=true tooldir=$PREFIX -j$(nproc) \
&& make MAKEINFO=true tooldir=$PREFIX install \
&& rm $PREFIX/bin/elfedit.exe $PREFIX/bin/readelf.exe
&& rm $PREFIX/bin/dllwrap.exe $PREFIX/bin/elfedit.exe $PREFIX/bin/readelf.exe
Comment thread
Peter0x44 marked this conversation as resolved.

WORKDIR /gmp
RUN /dl/gmp/configure \
Expand Down Expand Up @@ -398,8 +449,8 @@ RUN /dl/mingw/mingw-w64-crt/configure \
--host=$ARCH \
--with-default-msvcrt=msvcrt-os \
--disable-dependency-tracking \
--disable-lib32 \
--enable-lib64 \
--${CRT_LIB32}-lib32 \
--${CRT_LIB64}-lib64 \
CFLAGS="-O2" \
LDFLAGS="-s" \
&& make -j$(nproc) \
Expand All @@ -409,7 +460,13 @@ COPY src/threads.c $PREFIX/src/
COPY src/threads.h $PREFIX/include/
RUN $ARCH-gcc -c -Oz -I$PREFIX/include/ \
-ffunction-sections -Wa,--no-pad-sections $PREFIX/src/threads.c \
&& $ARCH-ar r $PREFIX/lib/libmingwex.a threads.o
&& $ARCH-ar r $PREFIX/lib/libmingwex.a threads.o \
&& if [ "$GCC_MULTILIB" = enable ]; then \
$ARCH-gcc -m32 -c -Oz -I$PREFIX/include/ \
-ffunction-sections -Wa,--no-pad-sections \
-o threads32.o $PREFIX/src/threads.c \
&& $ARCH-ar r $PREFIX/lib32/libmingwex.a threads32.o ; \
fi

WORKDIR /winpthreads
RUN /dl/mingw/mingw-w64-libraries/winpthreads/configure \
Expand All @@ -423,13 +480,31 @@ RUN /dl/mingw/mingw-w64-libraries/winpthreads/configure \
&& make -j$(nproc) \
&& make install

WORKDIR /winpthreads32
RUN if [ "$GCC_MULTILIB" = enable ]; then \
/dl/mingw/mingw-w64-libraries/winpthreads/configure \
--prefix=$PREFIX \
--libdir=$PREFIX/lib32 \
--with-sysroot=$PREFIX \
--host=$ARCH \
--enable-static \
--disable-shared \
CC="$ARCH-gcc -m32" \
CFLAGS="-O2" \
LDFLAGS="-s" \
&& make -j$(nproc) \
&& make install ; \
fi

WORKDIR /gcc
COPY src/crossgcc-*.patch $PREFIX/src/
RUN cat $PREFIX/src/crossgcc-*.patch | patch -d/dl/gcc -p1 \
&& /dl/gcc/configure \
--prefix=$PREFIX \
--with-sysroot=$PREFIX \
--with-native-system-header-dir=/include \
$GCC_ARCH_FLAG \
--${GCC_MULTILIB}-multilib \
--target=$ARCH \
--host=$ARCH \
--enable-static \
Expand All @@ -446,9 +521,9 @@ RUN cat $PREFIX/src/crossgcc-*.patch | patch -d/dl/gcc -p1 \
--disable-libstdcxx-verbose \
--disable-dependency-tracking \
--disable-lto \
--disable-multilib \
--disable-nls \
--disable-win32-registry \
$GCC_MANIFEST_FLAG \
--enable-mingw-wildcard \
CFLAGS_FOR_TARGET="-O2" \
CXXFLAGS_FOR_TARGET="-O2" \
Expand All @@ -475,7 +550,7 @@ RUN $ARCH-gcc -DEXE=gcc.exe -DCMD=cc \
&& $ARCH-gcc -DEXE=gcc.exe -DCMD="cc -ansi" \
-Oz -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/c89.exe $PREFIX/src/alias.c -lkernel32 \
&& printf '%s\n' addr2line ar as c++filt cpp dlltool dllwrap g++ \
&& printf '%s\n' addr2line ar as c++filt cpp dlltool g++ \
gcc gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool gendef gfortran \
ld nm objcopy objdump ranlib size strings strip uuidgen widl \
windmc windres \
Expand All @@ -485,6 +560,49 @@ RUN $ARCH-gcc -DEXE=gcc.exe -DCMD=cc \
-Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/$ARCH-{}.exe $PREFIX/src/alias.c -lkernel32

# Create i686 tool aliases
RUN if [ "$GCC_MULTILIB" = enable ]; then \
printf '%s\n' addr2line ar c++filt gcc-ar gcc-nm gcc-ranlib gcov \
gcov-dump gcov-tool gendef nm objcopy objdump ranlib size strings \
strip uuidgen windmc \
| xargs -I{} -P$(nproc) \
$ARCH-gcc -DEXE={}.exe -DCMD=i686-w64-mingw32-{} \
-Oz -fno-asynchronous-unwind-tables \
-Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-{}.exe \
$PREFIX/src/alias.c -lkernel32 \
&& printf '%s\n' cpp gcc g++ gfortran \
| xargs -I{} -P$(nproc) \
$ARCH-gcc -DEXE={}.exe -DCMD="i686-w64-mingw32-{} -m32" \
-Oz -fno-asynchronous-unwind-tables \
-Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-{}.exe \
$PREFIX/src/alias.c -lkernel32 \
&& $ARCH-gcc -DEXE=as.exe -DCMD="i686-w64-mingw32-as --32" \
-Oz -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-as.exe \
$PREFIX/src/alias.c -lkernel32 \
&& $ARCH-gcc -DEXE=ld.exe -DCMD="i686-w64-mingw32-ld -m i386pe" \
-Oz -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-ld.exe \
$PREFIX/src/alias.c -lkernel32 \
&& $ARCH-gcc -DEXE=dlltool.exe \
-DCMD="i686-w64-mingw32-dlltool -m i386 --as-flags=--32" \
-Oz -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-dlltool.exe \
$PREFIX/src/alias.c -lkernel32 \
&& $ARCH-gcc -DEXE=widl.exe \
-DCMD="i686-w64-mingw32-widl --win32" \
-Oz -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-widl.exe \
$PREFIX/src/alias.c -lkernel32 \
&& $ARCH-gcc -DEXE=windres.exe \
-DCMD="i686-w64-mingw32-windres --target=pe-i386" \
-Oz -fno-asynchronous-unwind-tables -Wl,--gc-sections -s -nostdlib \
-o $PREFIX/bin/i686-w64-mingw32-windres.exe \
$PREFIX/src/alias.c -lkernel32 ; \
fi

# Build some extra development tools

FROM cross AS build-gendef
Expand Down Expand Up @@ -598,7 +716,7 @@ COPY --from=dl-busybox /dl/ /dl/
WORKDIR /dl/busybox
COPY src/busybox-* $PREFIX/src/
RUN cat $PREFIX/src/busybox-*.patch | patch -p1 \
&& make mingw64u_defconfig \
&& make $BUSYBOX_CONFIG \
&& sed -ri 's/^(CONFIG_AR)=y/\1=n/' .config \
&& sed -ri 's/^(CONFIG_ASCII)=y/\1=n/' .config \
&& sed -ri -e 's/^(CONFIG_BASH_IS_ASH)=y/\1=n/' \
Expand Down Expand Up @@ -693,7 +811,7 @@ RUN make -j$(nproc) CC=$ARCH-gcc AR=$ARCH-ar CFLAGS="-O2" libzstd.a \

WORKDIR /dl/zstd
RUN make -j$(nproc) -C programs zstd \
CC=$ARCH-gcc CFLAGS="-O2" LDFLAGS="-s" EXT=.exe \
CC=$ARCH-gcc CFLAGS="-O2" LDFLAGS="-s" EXT=.exe $ZSTD_THREAD_FLAG \
&& mkdir -p /out/bin \
&& cp programs/zstd.exe /out/bin/ \
&& $ARCH-gcc -DEXE=zstd.exe -DCMD=unzstd \
Expand Down Expand Up @@ -788,7 +906,9 @@ COPY --from=build-pdcurses /deps/include/curses.h /deps/include/
WORKDIR /cmake
COPY src/cmake-*.patch $PREFIX/src/
RUN cat $PREFIX/src/cmake-*.patch | patch -d/dl/cmake -p1 \
&& cmake -DCMAKE_BUILD_TYPE=Release \
&& cmake -DCMAKE_C_FLAGS="$CMAKE_WINNT_C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CMAKE_WINNT_CXX_FLAGS" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=$ARCH-gcc \
-DCMAKE_CXX_COMPILER=$ARCH-g++ \
Expand Down Expand Up @@ -853,7 +973,7 @@ RUN sed -i 's/\r$//' Source/build.cpp \
&& cat $PREFIX/src/nsis-*.patch | patch -p1 \
&& scons -j$(nproc) \
XGCC_W32_PREFIX=$ARCH- \
TARGET_ARCH=amd64 \
TARGET_ARCH=$NSIS_ARCH \

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, does nsis need to be able to make "multilib" 32-or-64 bit installers?
I'm not going to use it, just curious. I've actually made windows installers myself at my job it's a surprisingly tricky problem.

PREFIX=$PREFIX \
PREFIX_BIN=$PREFIX/share/nsis/bin \
PREFIX_DATA=$PREFIX/share/nsis \
Expand All @@ -865,6 +985,54 @@ RUN sed -i 's/\r$//' Source/build.cpp \
install-compiler install-stubs install-includes install-plugins \
install-contrib install-utils

# Also provide x86 stubs and plugins in the multilib kit so makensis
# can produce 32-bit installers ("Target x86-unicode"). NSIS never
# passes -m32 itself and derives every tool name from XGCC_W32_PREFIX,
# so present the multilib compiler through an i686 interface, wrapper
# scripts mirroring the kit's own i686 aliases. The wrappers embed
# absolute tool paths because scons scrubs the PATH of its
# subprocesses down to the directory holding the prefixed tools, so
# they cannot find /bootstrap/bin themselves. NSIS's zlib configure
# probe runs even for stub-only targets and link-tests with -m32, so
# it needs a 32-bit libz.a, built from Binutils' bundled zlib exactly
# like the 64-bit copy in /deps.
RUN if [ "$GCC_MULTILIB" = enable ]; then \
printf '#!/bin/sh\nexec %s -m32 "$@"\n' "$(command -v $ARCH-gcc)" \
>/usr/local/bin/i686-w64-mingw32-gcc \
&& printf '#!/bin/sh\nexec %s -m32 "$@"\n' "$(command -v $ARCH-g++)" \
>/usr/local/bin/i686-w64-mingw32-g++ \
&& printf '#!/bin/sh\nexec %s --32 "$@"\n' "$(command -v $ARCH-as)" \
>/usr/local/bin/i686-w64-mingw32-as \
&& printf '#!/bin/sh\nexec %s --target=pe-i386 "$@"\n' \
"$(command -v $ARCH-windres)" \
>/usr/local/bin/i686-w64-mingw32-windres \
&& printf '#!/bin/sh\nexec %s "$@"\n' "$(command -v $ARCH-ar)" \
>/usr/local/bin/i686-w64-mingw32-ar \
&& printf '#!/bin/sh\nexec %s "$@"\n' "$(command -v $ARCH-ranlib)" \
>/usr/local/bin/i686-w64-mingw32-ranlib \
&& chmod +x /usr/local/bin/i686-w64-mingw32-* \
&& mkdir -p /zlib32 /deps32/lib /deps32/include \
&& (cd /zlib32 \
&& /dl/binutils/zlib/configure --host=i686-w64-mingw32 \
CFLAGS="-O2" \
&& make -j$(nproc) libz.a \
&& cp libz.a /deps32/lib/ \
&& cp /dl/binutils/zlib/zlib.h /dl/binutils/zlib/zconf.h \
/deps32/include/) \
&& scons -j$(nproc) \
XGCC_W32_PREFIX=i686-w64-mingw32- \
TARGET_ARCH=x86 \
PREFIX=$PREFIX \
PREFIX_BIN=$PREFIX/share/nsis/bin \
PREFIX_DATA=$PREFIX/share/nsis \
NSIS_CONFIG_CONST_DATA_PATH=no \
PREFIX_DEST=/out \
SKIPDOC=all \
SKIPUTILS="NSIS Menu,Makensisw,VPatch/Source/GenPat,MakeLangId,zip2exe" \
ZLIB_W32=/deps32 \
install-stubs install-plugins ; \
fi

# Collect source tarballs
FROM base AS source
COPY --from=dl-cross /dl/*.* /source/
Expand Down
Loading
Loading