|
| 1 | +# escape=` |
| 2 | +# |
| 3 | +# Builds Opus on Windows as a SHARED library (opus.dll + opus.lib import library) |
| 4 | +# with CMake + the Visual C++ toolchain, and packages the public headers + |
| 5 | +# binaries into zip files that the FreeSWITCH mod_opus / mod_opusfile modules can |
| 6 | +# consume in place of building Opus from source in-tree. |
| 7 | +# |
| 8 | +# This image only contains the TOOLCHAIN. The actual Opus version is cloned at |
| 9 | +# `docker run` time from an env var, so you can produce a new release without |
| 10 | +# rebuilding the (slow, multi-GB) Visual Studio layer. |
| 11 | +# |
| 12 | +# Build the toolchain image once: |
| 13 | +# docker build -t opus-packaging . |
| 14 | +# |
| 15 | +# Produce zips for an Opus tag (writes to .\artifacts on the host): |
| 16 | +# docker run --rm --cpus 8 --memory 8g ` |
| 17 | +# -e OPUS_VERSION=v1.5.2 ` |
| 18 | +# -v ${PWD}\artifacts:C:\artifacts ` |
| 19 | +# opus-packaging |
| 20 | +# |
| 21 | +# Requires Windows containers. The host must be able to run a Windows base image |
| 22 | +# of an equal-or-older build than the host (process isolation), otherwise run |
| 23 | +# with `--isolation=hyperv`. |
| 24 | + |
| 25 | +ARG WINDOWS_BASE=mcr.microsoft.com/windows/servercore:ltsc2025 |
| 26 | +FROM ${WINDOWS_BASE} |
| 27 | + |
| 28 | +# The Visual Studio bootstrapper. aka.ms/vs/17/release installs the latest VS 2022 |
| 29 | +# Build Tools. |
| 30 | +ARG VS_BOOTSTRAPPER_URL=https://aka.ms/vs/17/release/vs_buildtools.exe |
| 31 | + |
| 32 | +SHELL ["powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue';"] |
| 33 | + |
| 34 | +# --------------------------------------------------------------------------- |
| 35 | +# 1. Visual Studio 2022 Build Tools: the C++ workload (MSVC v143 + Windows SDK). |
| 36 | +# build-opus.ps1 locates the install via vswhere (dropped by the bootstrapper) |
| 37 | +# and drives it through CMake's Visual Studio generator. |
| 38 | +# Exit code 3010 == success-but-reboot-required, which is fine in an image. |
| 39 | +# --------------------------------------------------------------------------- |
| 40 | +RUN Invoke-WebRequest -Uri $env:VS_BOOTSTRAPPER_URL -OutFile C:\vs_buildtools.exe; ` |
| 41 | + Write-Host 'Installing Visual Studio Build Tools (this takes a while)...'; ` |
| 42 | + $p = Start-Process -FilePath C:\vs_buildtools.exe -Wait -PassThru -ArgumentList ` |
| 43 | + '--quiet','--wait','--norestart','--nocache', ` |
| 44 | + '--installPath','C:\BuildTools', ` |
| 45 | + '--add','Microsoft.VisualStudio.Workload.VCTools', ` |
| 46 | + '--includeRecommended'; ` |
| 47 | + if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) { throw "VS Build Tools install failed ($($p.ExitCode))" }; ` |
| 48 | + Remove-Item C:\vs_buildtools.exe -Force |
| 49 | + |
| 50 | +# --------------------------------------------------------------------------- |
| 51 | +# 2. Chocolatey, then Opus's two remaining prerequisites. Installed AFTER Visual |
| 52 | +# Studio so these small layers can be rebuilt without invalidating the cached |
| 53 | +# (slow) VS layer above. |
| 54 | +# - git : to clone the Opus source at the requested tag |
| 55 | +# - cmake : Opus's build system (>= 3.16) |
| 56 | +# --------------------------------------------------------------------------- |
| 57 | +RUN [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; ` |
| 58 | + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) |
| 59 | + |
| 60 | +RUN choco install -y --no-progress git; ` |
| 61 | + if ($LASTEXITCODE -ne 0) { throw "git install failed ($LASTEXITCODE)" } |
| 62 | + |
| 63 | +RUN choco install -y --no-progress cmake --installargs 'ADD_CMAKE_TO_PATH=System'; ` |
| 64 | + if ($LASTEXITCODE -ne 0) { throw "cmake install failed ($LASTEXITCODE)" } |
| 65 | + |
| 66 | +# NOTE: do NOT set `ENV PATH` here. The Windows base image exports the variable as |
| 67 | +# `Path` (mixed case), but Docker's ${...} substitution is case-sensitive, so |
| 68 | +# `${PATH}` expands to empty and wipes C:\Windows\System32 from the path. The |
| 69 | +# choco/VS installers already register their dirs in the machine PATH (which |
| 70 | +# container processes inherit), and build-opus.ps1 prepends the tool dirs |
| 71 | +# defensively at runtime. |
| 72 | + |
| 73 | +# --------------------------------------------------------------------------- |
| 74 | +# 3. Build driver. |
| 75 | +# --------------------------------------------------------------------------- |
| 76 | +COPY build-opus.ps1 C:\build-opus.ps1 |
| 77 | + |
| 78 | +# Defaults; override any of these with `docker run -e ...`. |
| 79 | +ENV OPUS_VERSION=v1.5.2 ` |
| 80 | + CONFIGS="Release Debug" ` |
| 81 | + PLATFORMS="x64 Win32" ` |
| 82 | + PKG_PREFIX=opus ` |
| 83 | + OUT_DIR=C:\artifacts ` |
| 84 | + OPUS_REPO=https://gitlab.xiph.org/xiph/opus.git ` |
| 85 | + OPUS_BUILD_ROOT=C:\ob ` |
| 86 | + OPUS_CUSTOM_MODES=OFF |
| 87 | + |
| 88 | +ENTRYPOINT ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\build-opus.ps1"] |
0 commit comments