Skip to content

Commit 2f1a132

Browse files
committed
Initial commit for zlib v1.3.2
0 parents  commit 2f1a132

9 files changed

Lines changed: 827 additions & 0 deletions

File tree

‎.dockerignore‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Keep the Docker build context small: only the Dockerfile and build-zlib.ps1
2+
# are needed inside the image.
3+
.git
4+
.github
5+
examples
6+
artifacts
7+
*.zip
8+
SHA256SUMS.txt
9+
build-*.log
10+
README.md
11+
.gitignore

‎.gitattributes‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This repository targets Windows. Keep CRLF line endings on checkout.
2+
* text=auto eol=crlf
3+
4+
# The build script is invoked as a file by CI/Docker; CRLF is fine for pwsh.
5+
*.ps1 text eol=crlf
6+
7+
# Anything binary that might land here stays untouched.
8+
*.zip binary
9+
*.lib binary
10+
*.dll binary
11+
*.pdb binary
12+
*.exe binary

‎.github/workflows/build-zlib.yml‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Build zlib (Windows)
2+
3+
# Builds zlib (zlib.dll + import lib, static zlibstatic.lib) on a Windows runner
4+
# and uploads the headers + binaries as zip artifacts -- the same zips the Docker
5+
# image produces and the same layout FreeSWITCH's w32\zlib.props consumes.
6+
#
7+
# Trigger manually (Actions tab -> "Build zlib (Windows)" -> Run workflow)
8+
# choosing the zlib version, or push a tag like `zlib-v1.3.2` to build it and
9+
# attach the zips to a GitHub Release. The Release assets are what FreeSWITCH
10+
# downloads (see examples/freeswitch/w32/zlib.props).
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
zlib_version:
16+
description: 'zlib release to build (e.g. 1.3.2)'
17+
required: true
18+
default: '1.3.2'
19+
configs:
20+
description: 'Configurations to build (space-separated)'
21+
required: true
22+
default: 'Release Debug'
23+
platforms:
24+
description: 'Platforms to build (space-separated; x64-only by default, Win32 also supported)'
25+
required: true
26+
default: 'x64'
27+
push:
28+
tags:
29+
- 'zlib-v*' # e.g. push tag `zlib-v1.3.2`
30+
31+
jobs:
32+
build:
33+
runs-on: windows-2022
34+
timeout-minutes: 30
35+
permissions:
36+
contents: write # needed to attach zips to a Release on tag push
37+
steps:
38+
- name: Checkout builder
39+
uses: actions/checkout@v4
40+
41+
- name: Resolve build parameters
42+
id: p
43+
shell: pwsh
44+
run: |
45+
if ($env:GITHUB_EVENT_NAME -eq 'push') {
46+
# tag form: zlib-v1.3.2 -> version 1.3.2
47+
$ver = "$env:GITHUB_REF_NAME" -replace '^zlib-v', ''
48+
$cfg = 'Release Debug'
49+
$plat = 'x64'
50+
} else {
51+
$ver = '${{ inputs.zlib_version }}'
52+
$cfg = '${{ inputs.configs }}'
53+
$plat = '${{ inputs.platforms }}'
54+
}
55+
"zlib_version=$ver" >> $env:GITHUB_OUTPUT
56+
"configs=$cfg" >> $env:GITHUB_OUTPUT
57+
"platforms=$plat" >> $env:GITHUB_OUTPUT
58+
Write-Host "Building zlib $ver [$cfg] for [$plat]"
59+
60+
# The runner image already has Visual Studio 2022 and CMake; build-zlib.ps1
61+
# enters the VC environment via vcvarsall and drives cmake from there.
62+
- name: Verify toolchain
63+
shell: pwsh
64+
run: |
65+
Write-Host "cmake: $((Get-Command cmake -ErrorAction SilentlyContinue)?.Source)"
66+
cmake --version
67+
Write-Host "tar : $((Get-Command tar -ErrorAction SilentlyContinue)?.Source)"
68+
69+
- name: Build zlib + package zips
70+
shell: pwsh
71+
env:
72+
ZLIB_VERSION: ${{ steps.p.outputs.zlib_version }}
73+
CONFIGS: ${{ steps.p.outputs.configs }}
74+
PLATFORMS: ${{ steps.p.outputs.platforms }}
75+
OUT_DIR: ${{ github.workspace }}\artifacts
76+
ZLIB_BUILD_ROOT: C:\zb
77+
run: .\build-zlib.ps1
78+
79+
- name: List artifacts
80+
shell: pwsh
81+
run: Get-ChildItem '${{ github.workspace }}\artifacts' | Format-Table Name, Length
82+
83+
- name: Upload zips
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: zlib-${{ steps.p.outputs.zlib_version }}
87+
path: |
88+
artifacts/*.zip
89+
artifacts/SHA256SUMS.txt
90+
artifacts/*.log
91+
if-no-files-found: error
92+
retention-days: 30
93+
94+
# On a tag push, attach the zips to a GitHub Release: that is where FreeSWITCH
95+
# downloads them from.
96+
- name: Publish to Release
97+
if: github.event_name == 'push'
98+
uses: softprops/action-gh-release@v2
99+
with:
100+
files: |
101+
artifacts/*.zip
102+
artifacts/SHA256SUMS.txt

‎.gitignore‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Build outputs
2+
/artifacts/
3+
*.zip
4+
SHA256SUMS.txt
5+
build-*.log
6+
7+
# zlib source / build trees (when building natively in-tree)
8+
/zb/
9+
zlib-*.tar.gz
10+
build-*/
11+
12+
# OS / editor cruft
13+
Thumbs.db
14+
.DS_Store

‎Dockerfile‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)