Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.user
*.ncb
/build*
!/build.sh

Choose a reason for hiding this comment

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

This change to .gitignore is no longer required.

Copy link
Author

Choose a reason for hiding this comment

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

I think the docker files should not be too far from the build script but I will split it

But moving it like this causes a problem with the working dir

I can either :

  1. implement it to be run from root ie:
    scripts/dockerbuild.sh
  2. or from inside the script folder

having both will need some folder search magic
This will end up to be confusing

having it at least the build script in root makes easier to implement more usable and consistent -> there are 5 build related files and folders in the root (build,cmake....)

Choose a reason for hiding this comment

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

The script shouldn't care what path its run from, it should detect its path and work out where other stuff is relative to itself. Relying on the current working dir is normally a bad idea and will just generate support requests when people run it wrong.

You already make use of basename to get the script name, using dirname will get you the containing folder (lets say scripts) and running direname on that folder would get you the top level project folder. You can then use that to construct the other paths you need.

nbproject/
project/
doxygen/
Expand Down
73 changes: 73 additions & 0 deletions dockerbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

#!/usr/bin/env bash
set -euo pipefail

usage() {
cat <<EOF
Usage:
$(basename "$0") [OPTIONS] [TARGET]

TARGET is passed to ninja.exe

Options:
-h, --help Show this help and exit
--cmake Force run cmake.
--bash Run the container interactively with bash entrypoint.

Examples:
$(basename "$0")
$(basename "$0") my_target
$(basename "$0") --cmake
$(basename "$0") --cmake my_target
$(basename "$0") --bash
EOF
}


FORCE_CMAKE="false"
MAKE_TARGET=""
INTERACTIVE="false"
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--cmake)
FORCE_CMAKE="true"
shift
;;
--bash)
INTERACTIVE="true"
shift
;;
--) # end of options
shift
break
;;
-*)
echo "Unknown option: $1" >&2
usage
exit 1
;;
*)
# Positional TARGET (accept only one)
MAKE_TARGET="$MAKE_TARGET $1"
shift
;;
esac
done

docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) dockerbuild -t zerohour-build
if [[ "$INTERACTIVE" == "true" ]]; then
FLAGS=" -it --entrypoint bash"
else
FLAGS=""
fi
docker run -u $(id -u):$(id -g) -e MAKE_TARGET="$MAKE_TARGET" -e FORCE_CMAKE=$FORCE_CMAKE -v "`pwd`":/build/cnc --rm $FLAGS zerohour-build





93 changes: 93 additions & 0 deletions dockerbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
FROM debian:12.10-slim

# Build arguments
ARG CMAKE_VERSION="3.31.6"
ARG GIT_VERSION="2.49.0"
ARG UID
ARG GID

# Install utils
RUN apt update \
&& apt install wget gpg unzip git -y \
&& dpkg --add-architecture i386 \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

# Install wine
RUN mkdir -pm755 /etc/apt/keyrings \
&& (wget -O - https://dl.winehq.org/wine-builds/winehq.key | gpg --dearmor -o /etc/apt/keyrings/winehq-archive.key -) \
&& wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/debian/dists/bookworm/winehq-bookworm.sources \
&& apt update \
&& apt install --no-install-recommends winehq-stable -y \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*
# Setup build folder
RUN mkdir /build
RUN chown ${UID}:${GID} /build

USER ${UID}:${GID}
WORKDIR /build/tools

# Install cmake windows
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-windows-x86_64.zip \
&& unzip cmake-${CMAKE_VERSION}-windows-x86_64.zip -d /build/tools/ \
&& mv /build/tools/cmake-${CMAKE_VERSION}-windows-x86_64 /build/tools/cmake \
&& find /build/tools/ -name "*.zip" -exec rm -f {} +

# Install git windows
RUN wget https://github.com/git-for-windows/git/releases/download/v${GIT_VERSION}.windows.1/MinGit-${GIT_VERSION}-64-bit.zip \
&& unzip MinGit-${GIT_VERSION}-64-bit.zip -d /build/tools/ \
&& mv /build/tools/cmd /build/tools/git \
&& find /build/tools/ -name "*.zip" -exec rm -f {} +

# Install Visual Studio 6 Portable
RUN wget https://github.com/itsmattkc/MSVC600/archive/refs/heads/master.zip \
&& unzip master.zip -d /build/tools \
&& mv /build/tools/MSVC600-master/ /build/tools/vs6 \
&& find /build/tools/ -name "*.zip" -exec rm -f {} +


#Install ninja
RUN wget https://github.com/ninja-build/ninja/releases/download/v1.13.1/ninja-win.zip \
&& unzip ninja-win.zip -d /build/tools/ \
&& find /build/tools/ -name "*.zip" -exec rm -f {} +

# Setup wine prefix
ENV WINEDEBUG=-all
ENV WINEARCH=win64
ENV WINEPREFIX=/build/prefix64

# Create empty TEMP folder for linking
RUN mkdir /build/tmp
ENV TMP="Z:\\build\\tmp"
ENV TEMP="Z:\\build\\tmp"
ENV TEMPDIR="Z:\\build\\tmp"

# Setup Visual Studio 6 Environment variables
ENV VS="Z:\\build\\tools\\vs6"
ENV MSVCDir="$VS\\vc98"
ENV WINEPATH="C:\\windows\\system32;\
$VS\\vc98\\bin;\
$VS\\vc98\\lib;\
$VS\\vc98\\include;\
$VS\\common\\Tools;\
$VS\\common\\MSDev98\\bin"
ENV LIB="$VS\\vc98\\Lib;$VS\\vc98\\MFC\\Lib;Z:\\build\\cnc\\build\\vc6"
ENV INCLUDE="$VS\\vc98\\ATL\\INCLUDE;\
$VS\\vc98\\INCLUDE;\
$VS\\vc98\\MFC\\INCLUDE;\
$VS\\vc98\\Include"
ENV CC="$VS\\vc98\\bin\\CL.exe"
ENV CXX="$VS\\vc98\\bin\\CL.exe"
ENV PRESET=vc6

#prevent cache warning
ENV HOME=/build/tmp/home
RUN mkdir /build/tmp/home

WORKDIR /build/cnc

USER root
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD /entrypoint.sh
28 changes: 28 additions & 0 deletions dockerbuild/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail
cd /build/cnc
wineboot
if [ "${FORCE_CMAKE:-}" = "true" ] || [ ! -f build/docker/build.ninja ]; then
wine /build/tools/cmake/bin/cmake.exe \
--preset ${PRESET} \
-DCMAKE_SYSTEM="Windows" \
-DCMAKE_SYSTEM_NAME="Windows" \
-DCMAKE_SIZEOF_VOID_P=4 \
-DCMAKE_MAKE_PROGRAM="Z:/build/tools/ninja.exe" \
-DCMAKE_C_COMPILER="Z:/build/tools/vs6/vc98/bin/cl.exe" \
-DCMAKE_CXX_COMPILER="Z:/build/tools/vs6/vc98/bin/cl.exe" \
-DGIT_EXECUTABLE="Z:/build/tools/git/git.exe" \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=1 \
-DCMAKE_C_COMPILER_WORKS=1 \
-DCMAKE_CXX_COMPILER_WORKS=1 \
-B /build/cnc/build/docker
fi

cd /build/cnc/build/docker
wine cmd /c "set TMP=Z:\build\tmp& set TEMP=Z:\build\tmp& Z:\build\tools\ninja.exe $MAKE_TARGET"


Loading