Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile: Add MinGW-w64 toolchain #26

Merged
merged 1 commit into from
Oct 23, 2024
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
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ RUN pip3 install awscli
# Install meson to allow building picolibc
RUN pip3 install meson

# Install MinGW-w64 toolchain
COPY mingw-build.sh /mingw-build.sh
RUN /mingw-build.sh && rm -f /mingw-build.sh

# Install QEMU
RUN wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz && \
tar Jxf qemu-${QEMU_VERSION}.tar.xz && \
Expand Down
107 changes: 107 additions & 0 deletions mingw-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash

BINUTILS_VERSION=2.42
GCC_VERSION=13.2.0
MINGW_VERSION=12.0.0

mkdir mingw
pushd mingw

# Download source code
echo "@@@ Downloading source code"
mkdir src
pushd src
## Binutils
wget https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz
tar Jxf binutils-${BINUTILS_VERSION}.tar.xz
## GCC
wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz
tar Jxf gcc-${GCC_VERSION}.tar.xz
pushd gcc-${GCC_VERSION}
contrib/download_prerequisites
popd
## MinGW-w64
wget https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v${MINGW_VERSION}.tar.bz2
tar jxf mingw-w64-v${MINGW_VERSION}.tar.bz2
popd

build_mingw_toolchain() {
local old_path=$PATH
local thread_model=$1
local prefix=/opt/mingw-w64-${thread_model}

echo "@@@ Building MinGW-w64 toolchain with '${thread_model}' thread model"

# Add prefix bin directory to PATH to aid toolchain discovery
export PATH="${prefix}/bin:${PATH}"

# Create build directory
mkdir build-${thread_model}
pushd build-${thread_model}

# Build Binutils
mkdir binutils
pushd binutils
../../src/binutils-${BINUTILS_VERSION}/configure \
--prefix=${prefix} \
--target=x86_64-w64-mingw32 \
--disable-multilib
make -j$(nproc)
make install
popd

# Install MinGW headers
mkdir mingw-headers
pushd mingw-headers
../../src/mingw-w64-v${MINGW_VERSION}/mingw-w64-headers/configure \
--prefix=${prefix}/x86_64-w64-mingw32 \
--host=x86_64-w64-mingw32 \
--with-default-msvcrt=ucrt
make install
popd

# Build core GCC
mkdir gcc
pushd gcc
../../src/gcc-${GCC_VERSION}/configure \
--prefix=${prefix} \
--target=x86_64-w64-mingw32 \
--disable-multilib \
--enable-languages=c,c++ \
--enable-threads=win32 \
--with-headers
make -j$(nproc) all-gcc
make install-gcc
popd

# Build MinGW
mkdir mingw
pushd mingw
../../src/mingw-w64-v${MINGW_VERSION}/configure \
--prefix=${prefix}/x86_64-w64-mingw32 \
--host=x86_64-w64-mingw32 \
--with-default-msvcrt=ucrt
make -j$(nproc)
make install -j$(nproc)
popd

# Build final GCC
pushd gcc
make -j$(nproc)
make install
popd

# Restore environment
popd
export PATH=${old_path}
}

# Build MinGW toolchain with 'win32' thread model
build_mingw_toolchain win32

# Build MinGW toolchain with 'posix' thread model
build_mingw_toolchain posix

# Clean up build directories
popd
rm -rf mingw