|
| 1 | +# escape=` |
| 2 | +# |
| 3 | +# Builds zlib on Windows (zlib.dll + import lib, and the static zlibstatic.lib) |
| 4 | +# and packages the headers + binaries into zip files that FreeSWITCH's Windows |
| 5 | +# build consumes -- the same zips the GitHub Actions workflow produces. |
| 6 | +# |
| 7 | +# This image only contains the TOOLCHAIN. The actual zlib version is built at |
| 8 | +# `docker run` time from an env var, so you can produce a new release without |
| 9 | +# rebuilding the (slow, multi-GB) toolchain layer. |
| 10 | +# |
| 11 | +# Build the toolchain image once: |
| 12 | +# docker build -t zlib-packaging . |
| 13 | +# |
| 14 | +# Produce zips for a zlib release (writes to .\artifacts on the host): |
| 15 | +# docker run --rm --cpus 4 --memory 4g ` |
| 16 | +# -e ZLIB_VERSION=1.3.2 ` |
| 17 | +# -v ${PWD}\artifacts:C:\artifacts ` |
| 18 | +# zlib-packaging |
| 19 | +# |
| 20 | +# Requires Windows containers. The host must be able to run a Windows base image |
| 21 | +# of an equal-or-older build than the host (process isolation), otherwise run |
| 22 | +# with `--isolation=hyperv`. |
| 23 | + |
| 24 | +ARG WINDOWS_BASE=mcr.microsoft.com/windows/servercore:ltsc2025 |
| 25 | +FROM ${WINDOWS_BASE} |
| 26 | + |
| 27 | +# The Visual Studio bootstrapper. aka.ms/vs/17/release installs the latest VS 2022 |
| 28 | +# Build Tools. |
| 29 | +ARG VS_BOOTSTRAPPER_URL=https://aka.ms/vs/17/release/vs_buildtools.exe |
| 30 | + |
| 31 | +SHELL ["powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue';"] |
| 32 | + |
| 33 | +# --------------------------------------------------------------------------- |
| 34 | +# 1. Chocolatey + CMake (zlib's build system; build-zlib.ps1 drives it with the |
| 35 | +# "NMake Makefiles" generator from inside the VC environment). |
| 36 | +# tar.exe (for unpacking the source tarball) ships with the base image. |
| 37 | +# --------------------------------------------------------------------------- |
| 38 | +RUN [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; ` |
| 39 | + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) |
| 40 | + |
| 41 | +RUN choco install -y --no-progress cmake --installargs 'ADD_CMAKE_TO_SYSTEM_PATH=System'; ` |
| 42 | + if ($LASTEXITCODE -ne 0) { throw "choco install failed ($LASTEXITCODE)" }; ` |
| 43 | + if (-not (Test-Path 'C:\Program Files\CMake\bin\cmake.exe')) { throw 'cmake.exe not found after install' }; ` |
| 44 | + & 'C:\Program Files\CMake\bin\cmake.exe' --version |
| 45 | + |
| 46 | +# --------------------------------------------------------------------------- |
| 47 | +# 2. Visual Studio 2022 Build Tools: the C++ workload (MSVC v143 + Windows SDK + |
| 48 | +# nmake + rc). build-zlib.ps1 enters this environment via vcvarsall.bat. |
| 49 | +# Exit code 3010 == success-but-reboot-required, which is fine in an image. |
| 50 | +# --------------------------------------------------------------------------- |
| 51 | +RUN Invoke-WebRequest -Uri $env:VS_BOOTSTRAPPER_URL -OutFile C:\vs_buildtools.exe; ` |
| 52 | + Write-Host 'Installing Visual Studio Build Tools (this takes a while)...'; ` |
| 53 | + $p = Start-Process -FilePath C:\vs_buildtools.exe -Wait -PassThru -ArgumentList ` |
| 54 | + '--quiet','--wait','--norestart','--nocache', ` |
| 55 | + '--installPath','C:\BuildTools', ` |
| 56 | + '--add','Microsoft.VisualStudio.Workload.VCTools', ` |
| 57 | + '--includeRecommended'; ` |
| 58 | + if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) { throw "VS Build Tools install failed ($($p.ExitCode))" }; ` |
| 59 | + Remove-Item C:\vs_buildtools.exe -Force |
| 60 | + |
| 61 | +# --------------------------------------------------------------------------- |
| 62 | +# 3. Build driver. |
| 63 | +# --------------------------------------------------------------------------- |
| 64 | +COPY build-zlib.ps1 C:\build-zlib.ps1 |
| 65 | + |
| 66 | +# Defaults; override any of these with `docker run -e ...`. |
| 67 | +ENV ZLIB_VERSION=1.3.2 ` |
| 68 | + CONFIGS="Release Debug" ` |
| 69 | + PLATFORMS="x64" ` |
| 70 | + PKG_PREFIX=zlib ` |
| 71 | + OUT_DIR=C:\artifacts ` |
| 72 | + ZLIB_BUILD_ROOT=C:\zb |
| 73 | + |
| 74 | +# NOTE: do NOT set `ENV PATH` here -- the Windows base image exports the variable |
| 75 | +# as `Path` (mixed case) and Docker's ${...} substitution is case-sensitive, so |
| 76 | +# `${PATH}` would expand to empty and wipe System32 from the path. The installers |
| 77 | +# register their dirs in the machine PATH (which container processes inherit), and |
| 78 | +# build-zlib.ps1 prepends the CMake dir defensively at runtime. |
| 79 | + |
| 80 | +ENTRYPOINT ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\build-zlib.ps1"] |
0 commit comments