|
| 1 | +# escape=` |
| 2 | +# |
| 3 | +# Builds Node.js on Windows as a SHARED library (libnode.dll) and packages |
| 4 | +# the V8 headers + libnode import library/DLL into zip files that the FreeSWITCH |
| 5 | +# mod_v8 JavaScript module can consume in place of the old standalone libv8 zips. |
| 6 | +# |
| 7 | +# This image only contains the TOOLCHAIN. The actual Node 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 libnode-packaging . |
| 13 | +# |
| 14 | +# Produce zips for a Node tag (writes to .\artifacts on the host): |
| 15 | +# docker run --rm --cpus 8 --memory 16g ` |
| 16 | +# -e NODE_VERSION=v20.19.2 ` |
| 17 | +# -v ${PWD}\artifacts:C:\artifacts ` |
| 18 | +# libnode-packaging |
| 19 | +# |
| 20 | +# Requires Windows containers. The host must be able to run a Windows base |
| 21 | +# image of an equal-or-older build than the host (process isolation), otherwise |
| 22 | +# run 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 Build Tools, |
| 28 | +# new enough for the ClangCL components that Node >= 24 requires. |
| 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 + Node's non-VS prerequisites: |
| 35 | +# - python3 : a Python 3.x on PATH for Node's configure (PEP 514). The build |
| 36 | +# actually uses the 3.13 installed in step 2c (Node 20.x rejects 3.14). |
| 37 | +# - nasm : OpenSSL assembler modules on x64 (find_nasm.cmd looks in %ProgramFiles%\NASM) |
| 38 | +# - git : to clone the Node source at the requested tag |
| 39 | +# --------------------------------------------------------------------------- |
| 40 | +RUN [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; ` |
| 41 | + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) |
| 42 | + |
| 43 | +RUN choco install -y --no-progress python3 nasm git; ` |
| 44 | + if ($LASTEXITCODE -ne 0) { throw "choco install failed ($LASTEXITCODE)" } |
| 45 | + |
| 46 | +# --------------------------------------------------------------------------- |
| 47 | +# 2. Visual Studio 2022 Build Tools: C++ workload + ClangCL. |
| 48 | +# Node.js >= 24 forces ClangCL (vcbuild sets clang_cl=1), so the two LLVM |
| 49 | +# components below are mandatory. --includeRecommended pulls in MSVC v143 |
| 50 | +# and the Windows SDK. |
| 51 | +# Exit code 3010 == success-but-reboot-required, which is fine in an image. |
| 52 | +# --------------------------------------------------------------------------- |
| 53 | +RUN Invoke-WebRequest -Uri $env:VS_BOOTSTRAPPER_URL -OutFile C:\vs_buildtools.exe; ` |
| 54 | + Write-Host 'Installing Visual Studio Build Tools (this takes a while)...'; ` |
| 55 | + $p = Start-Process -FilePath C:\vs_buildtools.exe -Wait -PassThru -ArgumentList ` |
| 56 | + '--quiet','--wait','--norestart','--nocache', ` |
| 57 | + '--installPath','C:\BuildTools', ` |
| 58 | + '--add','Microsoft.VisualStudio.Workload.VCTools', ` |
| 59 | + '--add','Microsoft.VisualStudio.Component.VC.Llvm.Clang', ` |
| 60 | + '--add','Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset', ` |
| 61 | + '--includeRecommended'; ` |
| 62 | + if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) { throw "VS Build Tools install failed ($($p.ExitCode))" }; ` |
| 63 | + Remove-Item C:\vs_buildtools.exe -Force |
| 64 | + |
| 65 | +# --------------------------------------------------------------------------- |
| 66 | +# 2b. Rust toolchain (MSVC ABI). Installed AFTER VS so this small layer can be |
| 67 | +# added without invalidating the cached (slow) VS Build Tools layer above. |
| 68 | +# Node >= 26 builds the deps/crates Rust crates because Temporal support is |
| 69 | +# ON by default; cargo/rustc (>= 1.82) are required unless the build is |
| 70 | +# configured with --v8-disable-temporal-support. |
| 71 | +# --------------------------------------------------------------------------- |
| 72 | +RUN choco install -y --no-progress rust-ms; ` |
| 73 | + if ($LASTEXITCODE -ne 0) { throw "rust install failed ($LASTEXITCODE)" } |
| 74 | + |
| 75 | +# --------------------------------------------------------------------------- |
| 76 | +# 2c. Python 3.13. Node 20.x's configure rejects Python 3.14 ("Please use |
| 77 | +# python3.13 or ..."), while newer Node (>= 24) accepts 3.13 too. Installing |
| 78 | +# 3.13 alongside the default python3 covers every Node line we build; |
| 79 | +# build-libnode.ps1 puts C:\Python313 first on PATH so find_python picks it. |
| 80 | +# Installed after VS so this small layer doesn't invalidate the VS cache. |
| 81 | +# --------------------------------------------------------------------------- |
| 82 | +RUN choco install -y --no-progress python313; ` |
| 83 | + if ($LASTEXITCODE -ne 0) { throw "python313 install failed ($LASTEXITCODE)" } |
| 84 | + |
| 85 | +# NOTE: do NOT set `ENV PATH` here. The Windows base image exports the variable |
| 86 | +# as `Path` (mixed case), but Docker's ${...} substitution is case-sensitive, so |
| 87 | +# `${PATH}` expands to empty and wipes C:\Windows\System32 from the path. The |
| 88 | +# choco/VS installers already register their dirs in the machine PATH (which |
| 89 | +# container processes inherit), and build-libnode.ps1 prepends the tool dirs |
| 90 | +# defensively at runtime. vcbuild locates VS itself via vswhere. |
| 91 | + |
| 92 | +# --------------------------------------------------------------------------- |
| 93 | +# 3. Build driver. |
| 94 | +# --------------------------------------------------------------------------- |
| 95 | +COPY build-libnode.ps1 C:\build-libnode.ps1 |
| 96 | + |
| 97 | +# Defaults; override any of these with `docker run -e ...`. |
| 98 | +# Default matches the Linux libnode-dev on Debian trixie (Node 20 -> V8 11.3) so |
| 99 | +# the same mod_v8 source compiles on both platforms. Bump for newer toolchains. |
| 100 | +ENV NODE_VERSION=v20.19.2 ` |
| 101 | + CONFIGS="Release Debug" ` |
| 102 | + ARCH=x64 ` |
| 103 | + PKG_PREFIX=libnode ` |
| 104 | + OUT_DIR=C:\artifacts ` |
| 105 | + NODE_REPO=https://github.com/nodejs/node.git |
| 106 | + |
| 107 | +ENTRYPOINT ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\build-libnode.ps1"] |
0 commit comments