Skip to content
Permalink
Browse files
Simplify build chain and use VS 2022
  • Loading branch information
big-r81 committed Mar 25, 2022
1 parent 4d70590 commit 594690f586fac1c23992faafd22c51d5bb1e04d7
Showing 5 changed files with 140 additions and 64 deletions.
@@ -4,14 +4,13 @@ Glazier is a set of batch files, scripts and toolchains designed to
ease building CouchDB on Windows. It's as fully automated as
possible, with most of the effort required only once.

Glazier uses the MS Visual Studio 2017 toolchain as much as possible,
Glazier uses the MS Visual Studio 2022 toolchain as much as possible,
to ensure a quality Windows experience and to execute all binary
dependencies within the same runtime.

We hope Glazier simplifies using Erlang and CouchDB for you, giving
a consistent, repeatable build environment.


# Base Requirements

Note that the scripts you'll run will modify your system extensively. We recommend a *dedicated build machine or VM image* for this work:
@@ -26,11 +25,12 @@ Note that the scripts you'll run will modify your system extensively. We recomme
Start an Administrative PowerShell console. Enter the following:

```powershell
mkdir C:\Relax\
cd C:\Relax\
mkdir C:\relax\
cd C:\relax\
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n allowGlobalConfirmation
choco install git
git config --global auto.crlf false
git clone https://github.com/apache/couchdb-glazier
&.\couchdb-glazier\bin\install_dependencies.ps1
```
@@ -39,30 +39,20 @@ You should go get lunch. The last step will take over an hour, even on a speedy

At this point, you should have the following installed:

* Visual Studio 2017 (Build Tools, Visual C++ workload, native desktop workload)
* Windows 10 SDK (10.1)
* Visual Studio 2022 (Build Tools, Visual C++ workload, native desktop workload)
* Windows 10 SDK (by native desktop workload; 10.0.19041.0)
* NodeJS (LTS version)
* wget.exe
* NASM
* Cyg-get (for cygwin)
* WiX Toolset
* Python 3
* Python packages sphinx, docutils, pygments, nose, hypothesis, and `sphinx_rtd_theme`
* GNU Make
* Python packages sphinx, sphinx_rtd_theme and pygments
* NSSM
* GPG4Win (for signing releases)
* checksum
* archiver
* Dependency Walker
* unzip
* NSIS
* Make
* NuGet
* VSSetup
* MozillaBuild setup (3.3)
* VSWhere
* MozillaBuild setup
* VCPkg (https://github.com/Microsoft/vcpkg), which built and installed:
* OpenSSL (at time of writing, 1.1.1)
* ICU (at time of writing, 61)
* Cygwin (used for building Erlang), plus some packages required for Erlang builds
* ICU (at time of writing, 69.1)

# Building Erlang

@@ -131,42 +121,47 @@ del Precompiled.zip
# Building SpiderMonkey

This section is not currently automated, due to the need for Mozilla's separate build
environment. It should be possible to automate (PRs welcome!)
environment. It should be possible to automate (PRs welcome!). At time of writing, we
use the `esr91` branch of spidermonkey.

From the same PowerShell prompt, enter the following:

```
```powershell
C:\mozilla-build\start-shell.bat
```

At the MozillaBuild prompt, enter the following:

```
C:\mozilla-build\start-shell.bat
```bash
cd /c/relax
git clone https://github.com/mozilla/gecko-dev
cd gecko-dev
git checkout esr60
cd js/src
sed -i -E "s/(VC\.Tools\.x86\.x64')/\1, '-products', '*'/g" ../../build/moz.configure/toolchain.configure
autoconf-2.13
mkdir build_OPT.OBJ
cd build_OPT.OBJ
../configure --disable-ctypes --disable-ion --disable-jemalloc --enable-optimize --enable-hardening --with-intl-api --build-backends=RecursiveMake --with-visual-studio-version=2017 --with-system-icu --disable-debug --enable-gczeal --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32 --prefix=/c/relax/vcpkg/installed/x64-windows
mozmake
exit
git checkout esr91
./mach bootstrap --application-choice js
```

The `sed` command adds support for building with just the VS Build Tools, which are
sufficient for just SpiderMonkey. (Otherwise, you need to download an additional 9GB of
Visual Studio. Bleah.) The build should take about 15 minutes.
Please answer the following question of `./mach boostrap`. You need this only for the first run.
It downloads a complete build toolchain for Spidermonkey.

* Would you like to create this directory? (Yn): Y
* Would you like to run a few configuration steps to ensure Git is optimally configured? (Yn): Y
* Will you be submitting commits to Mozilla? (Yn): n
* Would you like to enable build system telemetry? (Yn):n

Back in PowerShell, copy the binaries to where our build process expects them:

```bash
export MOZCONFIG=/c/relax/couchdb-glazier/moz/sm-opt
./mach build
exit
```
copy C:\relax\gecko-dev\js\src\build_OPT.OBJ\js\src\build\*.pdb C:\relax\vcpkg\installed\x64-windows\bin
copy C:\relax\gecko-dev\js\src\build_OPT.OBJ\dist\bin\*.dll C:\relax\vcpkg\installed\x64-windows\bin
copy C:\relax\gecko-dev\js\src\build_OPT.OBJ\dist\include\* C:\relax\vcpkg\installed\x64-windows\include -Recurse -ErrorAction SilentlyContinue
Now you should have built Spidermonkey.
Back in PowerShell, copy the binaries to where our build process expects them:

```powershell
copy C:\relax\gecko-dev\sm-obj-opt\js\src\build\*.pdb C:\relax\vcpkg\installed\x64-windows\bin
copy C:\relax\gecko-dev\sm-obj-opt\js\src\build\*.lib C:\relax\vcpkg\installed\x64-windows\lib
copy C:\relax\gecko-dev\sm-obj-opt\dist\bin\*.dll C:\relax\vcpkg\installed\x64-windows\bin
copy C:\relax\gecko-dev\sm-obj-opt\dist\include\* C:\relax\vcpkg\installed\x64-windows\include -Recurse -ErrorAction SilentlyContinue
```

# Building CouchDB itself
@@ -10,36 +10,53 @@
# License for the specific language governing permissions and limitations under
# the License.

# requires English language pack installed
choco install visualstudio2017buildtools "--passive --locale en-US"
choco install visualstudio2017-workload-vctools --package-parameters "--includeRecommended --add Microsoft.VisualStudio.Component.VC.ATLMFC"
choco install visualstudio2017-workload-nativedesktop
choco install windows-sdk-10.1 nodejs-lts wget nasm cyg-get wixtoolset python3 make nssm gpg4win checksum archiver dependencywalker unzip
choco install nsis --version=2.51
# Sourcing variable definitions
. ${PSScriptRoot}\variables.ps1

# Exclude c:\relax from MS defender to speed up things
Add-MpPreference -ExclusionPath "C:\relax"

# Install build tools - requires English language pack installed
choco install visualstudio2022buildtools "--passive --locale en-US"
choco install visualstudio2022-workload-vctools --package-parameters "--add Microsoft.VisualStudio.Component.VC.ATL --add Microsoft.VisualStudio.Component.VC.Redist.MSM"
#choco install visualstudio2022-workload-nativedesktop
choco install nodejs-lts wixtoolset make nssm python3 vswhere
#choco install windows-sdk-10.1 nodejs-lts wget nasm cyg-get wixtoolset python3 make nssm gpg4win checksum archiver dependencywalker unzip
#choco install nsis --version=2.51
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module VSSetup -Scope CurrentUser -Force
python -m pip install --upgrade pip
pip install --upgrade sphinx docutils pygments nose hypothesis sphinx_rtd_theme
cyg-get -upgrade p7zip autoconf binutils bison gcc-code gcc-g++ gdb git libtool make patchutils pkg-config readline file renameutils socat time tree util-linux wget
pip install --upgrade sphinx sphinx_rtd_theme pygments #docutils nose hypothesis

wget.exe https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.3.exe
.\MozillaBuildSetup-3.3.exe /S
# Hide the Download-StatusBar and improve download speed of wget-Cmdlet
$ProgressPreference = 'SilentlyContinue'

# Download and install MozillaBuild environment
# DON'T USE MozillaBuild 4.0. At time of writing, it fails even to start building sm
wget -Uri $mozBuildUri -OutFile $mozBuildFile
Start-Process -Filepath "$mozBuildFile" -ArgumentList "/S"
sleep 120
del MozillaBuildSetup-3.3.exe

# Download and install Erlang/OTP 23
wget -Uri $erlBuildUri -OutFile $erlBuildFile
Start-Process -Filepath "$erlBuildFile" -ArgumentList "/S /D=${erlInstallPath}"
sleep 120

# Download and install Elixier
wget -Uri $elxBuildUri -OutFile $elxBuildFile
Expand-Archive -Path $elxBuildFile -DestinationPath "c:\relax\elixir"
copy "c:\relax\elixir\*" ${erlInstallPath} -Recurse -Force

# Download and install VCPkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat -disableMetrics -win64
.\bootstrap-vcpkg.bat -disableMetrics
.\vcpkg integrate install --triplet x64-windows
.\vcpkg remove openssl icu curl[openssl,tool]
.\vcpkg install openssl icu curl[openssl,tool] --triplet x64-windows
.\vcpkg install icu --triplet x64-windows
cd ..

# below is for Erlang compile to be successful - not required for too long, see:
# https://github.com/erlang/otp/pull/2456

New-Item -Path C:\relax\vcpkg\installed\x64-windows\lib\libeay32.lib -ItemType HardLink -Value C:\relax\vcpkg\installed\x64-windows\lib\libcrypto.lib
New-Item -Path C:\relax\vcpkg\installed\x64-windows\lib\ssleay32.lib -ItemType HardLink -Value C:\relax\vcpkg\installed\x64-windows\lib\libssl.lib
New-Item -Path C:\relax\vcpkg\installed\x64-windows\lib\VC -ItemType SymbolicLink -Value C:\relax\vcpkg\installed\x64-windows\lib
# we know what we are doing (, do we really?)
Set-ExecutionPolicy Bypass -Scope CurrentUser -Force

# start shell
. ${PSScriptRoot}\shell.ps1
@@ -10,7 +10,15 @@
# License for the specific language governing permissions and limitations under
# the License.

$installationPath = vswhere.exe -prerelease -products Microsoft.VisualStudio.Product.BuildTools -version '[15.0,16.0)' -property InstallationPath
# Sourcing variable definitions
. ${PSScriptRoot}\variables.ps1

# Visual Studio Version Numbers:
# 2015: 15.x
# 2019: 16.x
# 2022: 17.x

$installationPath = vswhere.exe -prerelease -products Microsoft.VisualStudio.Product.BuildTools -version '[17.0,18.0)' -property InstallationPath
if ($installationPath -and (test-path "$installationPath\Common7\Tools\vsdevcmd.bat")) {
& "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -arch=amd64 -no_logo && set" | foreach-object {
$name, $value = $_ -split '=', 2
@@ -20,12 +28,12 @@ if ($installationPath -and (test-path "$installationPath\Common7\Tools\vsdevcmd.
Import-Module ${PSScriptRoot}\which.psm1

$env:VCPKG_BIN = "C:\relax\vcpkg\installed\x64-windows\bin"
$env:PATH += ";C:\Program Files\erl9.3.3.14\bin"
$env:PATH += ";${erlInstallPath}\bin"
$env:PATH += ";C:\relax\vcpkg\installed\x64-windows\bin"
$env:PATH += ";C:\Program Files (x86)\WiX Toolset v3.11\bin"

$env:LIB = "C:\relax\vcpkg\installed\x64-windows\lib;" + $env:LIB
$env:INCLUDE = "C:\relax\vcpkg\installed\x64-windows\include;" + $env:INCLUDE
$env:LIBPATH = "C:\relax\vcpkg\installed\x64-windows\lib;" + $env:LIBPATH

Set-ExecutionPolicy Bypass -Scope Process -Force

@@ -0,0 +1,32 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# MOZILLA BUILD SETTINGS

# Download location of the Mozilla Build Environment for Windows
$mozBuildUri = "https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-3.4.exe"
$mozBuildFile = Split-Path $mozBuildUri -Leaf

# ERLANG BUILD SETTINGS

# Download location of the Erlang/OTP Environment for Windows (x64)
$erlBuildUri = "https://github.com/erlang/otp/releases/download/OTP-23.3.4.12/otp_win64_23.3.4.12.exe"
$erlBuildFile = Split-Path $erlBuildUri -Leaf
$erlDir = "erl23"
$erlInstallPath = "C:\Program Files\${erlDir}"

# ERLANG BUILD SETTINGS

# Download location of the Elixier binaries for Windows (x64)
$elxBuildUri = "https://github.com/elixir-lang/elixir/releases/download/v1.13.3/Precompiled.zip"
$elxBuildFile = Split-Path $elxBuildUri -Leaf

@@ -0,0 +1,24 @@
# Build only the JS shell
ac_add_options --enable-application=js

# Enable optimization for speed
ac_add_options --enable-optimize

# Disable debug checks to better match a release build of Firefox.
ac_add_options --disable-debug

ac_add_options --disable-ctypes
ac_add_options --disable-jit
ac_add_options --disable-jemalloc
ac_add_options --enable-hardening
ac_add_options --with-intl-api
ac_add_options --build-backends=RecursiveMake
#ac_add_options --with-system-icu
ac_add_options --enable-gczeal
#ac_add_options --target=x86_64-pc-mingw32
#ac_add_options --host=x86_64-pc-mingw32

# Use a separate objdir for optimized builds to allow easy
# switching between optimized and debug builds while developing.

mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/sm-obj-opt

0 comments on commit 594690f

Please sign in to comment.