Merge pull request #15 from big-r81/vs2022

Simplified build chain and updated build scripts to VS 2022
diff --git a/README.OLD.md b/README.OLD.md
new file mode 100644
index 0000000..a14a1cd
--- /dev/null
+++ b/README.OLD.md
@@ -0,0 +1,290 @@
+# Glazier
+
+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,
+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:
+
+- 64-bit Windows 7+. *As of CouchDB 2.0 we only support a 64-bit build of CouchDB*.
+  - We like 64-bit Windows 10 Enterprise N (missing Media Player, etc.) from MSDN.
+  - Apply Windows Updates and reboot until no more updates appear.
+  - If using a VM, shutdown and snapshot your VM at this point.
+
+# Install Dependencies
+
+Start an Administrative PowerShell console. Enter the following:
+
+```powershell
+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 clone https://github.com/apache/couchdb-glazier
+&.\couchdb-glazier\bin\install_dependencies.ps1
+```
+
+You should go get lunch. The last step will take over an hour, even on a speedy Internet connection.
+
+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)
+* 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
+* NSSM
+* GPG4Win (for signing releases)
+* checksum
+* archiver
+* Dependency Walker
+* unzip
+* NSIS
+* NuGet
+* VSSetup
+* MozillaBuild setup (3.3)
+* 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
+
+# Building Erlang
+
+This section is not presently automated because it requires switching between PowerShell
+and Cygwin. It should be possible to automate (PRs welcome!)
+
+We generally need to build a version of Erlang that is not distributed directly
+by Ericsson. This may be because we require patches that are released after the
+binaries are built.
+
+For CouchDB 3.0, we build against Erlang 20.3.8.25.
+
+In the same PowerShell session, enter the following:
+
+```powershell
+cd c:\relax
+cygwin
+git clone https://github.com/erlang/otp
+cd otp
+git checkout OTP-20.3.8.25
+export PATH="/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.8 Tools/x64:/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64:/cygdrive/c/Program Files (x86)/NSIS:/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64:$PATH"
+which cl link mc lc mt nmake rc
+```
+
+This should produce the following output:
+
+```
+/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl
+/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/link
+/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/mc
+/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.8 Tools/x64/lc
+/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/mt
+/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/nmake
+/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/rc
+```
+
+Continue by entering the following. This takes a while, maybe 30-60 minutes at the `otp_build` steps, so be sure to have your favourite beverage on hand while you watch.
+
+```
+cd /cygdrive/c/relax/otp
+eval `./otp_build env_win32 x64`
+./otp_build autoconf 2>&1 | tee build_autoconf.txt
+./otp_build configure --with-ssl=/cygdrive/c/relax/vcpkg/installed/x64-windows --without-javac --without-debugger --without-wx --without-ic --without-odbc --without-et --without-cosEvent --without-cosEventDomain --without-cosFileTransfer --without-cosNotification --without-cosProperty --without-cosTime --without-cosTransactions --without-orber --without-observer 2>&1 | tee build_configure.txt
+./otp_build boot -a  2>&1 | tee build_boot.txt
+./otp_build release -a  2>&1 | tee build_release.txt
+./otp_build installer_win32  2>&1 | tee build_installer_win32.txt
+release/win32/otp_win64_*.exe /S
+exit
+```
+
+You now have a full install of Erlang on your system.
+
+# Installing Elixir
+
+CouchDB uses Elixir for tests. If you intend to run the test suite (you should!), install
+Elixir now by running the following in the same PowerShell prompt:
+
+```
+wget.exe https://github.com/elixir-lang/elixir/releases/download/v1.9.4/Precompiled.zip
+arc unarchive .\Precompiled.zip
+copy .\Precompiled\* 'C:\Program Files\erl9.3.3.14\' -Recurse  -Force
+del Precompiled -Recurse
+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!)
+
+From the same PowerShell prompt, enter the following:
+
+```
+C:\mozilla-build\start-shell.bat
+```
+
+At the MozillaBuild prompt, enter the following:
+
+```
+C:\mozilla-build\start-shell.bat
+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
+```
+
+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.
+
+Back in PowerShell, copy the binaries to where our build process expects them:
+
+```
+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
+```
+
+# Building CouchDB itself
+
+You're finally ready. You should snapshot your VM at this point!
+
+Open a new PowerShell window. Set up your shell correctly (this step works if you've
+closed your PowerShell window before any of the previous steps, too):
+
+```
+&c:\relax\couchdb-glazier\bin\shell.ps1
+```
+
+Then, start the process:
+
+```
+cd c:\relax
+git clone https://github.com/apache/couchdb
+cd couchdb
+git checkout <tag or branch of interest goes here>
+&.\configure.ps1 -SpiderMonkeyVersion 60
+make -f Makefile.win
+```
+
+You now have built CouchDB!
+
+To run the tests:
+
+```
+make -f Makefile.win check
+```
+
+Finally, to build a CouchDB installer:
+
+```
+make -f Makefile.win release
+cd c:\relax
+&couchdb-glazier\bin\build_installer.ps1
+```
+
+The installer will be placed in your current working directory.
+
+You made it! Time to relax. :D
+
+If you're a release engineer, you may find the following commands useful too:
+
+```
+checksum -t sha256 apache-couchdb.#.#.#-RC#.tar.gz
+checksum -t sha512 apache-couchdb.#.#.#-RC#.tar.gz
+gpg --verify apache-couchdb.#.#.#-RC#.tar.gz.asc
+```
+
+# Appendices
+
+## Why Glazier?
+
+@dch first got involved with CouchDB around 0.7. Only having a low-spec Windows
+PC to develop on, and no CouchDB Cloud provider being available, he tried
+to build CouchDB himself. It was hard going, and most of the frustration was
+trying to get the core Erlang environment set up and compiling without needing
+to buy Microsoft's expensive but excellent Visual Studio tools. Once
+Erlang was working he found many of the pre-requisite modules such as cURL,
+Zlib, OpenSSL, Mozilla's SpiderMonkey JavaScript engine, and IBM's ICU were
+not available at a consistent compiler and VC runtime release.
+
+There is a branch of glazier that has been used to build each CouchDB release.
+
+## UNIX-friendly shell details
+
+Our goal is to get the path set up in this order:
+
+1. erlang and couchdb build helper scripts
+2. Microsoft VC compiler, linker, etc from Windows SDK
+3. cygwin path for other build tools like make, autoconf, libtool
+4. the remaining windows system path
+
+It seems this is a challenge for most environments, so `glazier` gets this all right for
+you by running the MSVC environment, then tacking on the things Erlang expects at the end
+of the path.
+
+Overall, the desired order for your $PATH is:
+
+- Erlang build helper scripts
+- Visual C++ / .NET framework / SDK
+- Ancillary Erlang and CouchDB packaging tools
+- Usual cygwin unix tools such as make, gcc
+- Ancillary glazier/relax tools for building dependent libraries
+- Usual Windows folders `%windir%;%windir%\system32` etc
+- Various settings form the `otp_build` script
+
+More details are at [erlang INSTALL-Win32.md on github](https://github.com/erlang/otp/blob/master/HOWTO/INSTALL-WIN32.md)
+
+## Windows silent installs
+
+Here are some sample commands, supporting the new features of the 3.0 installer.
+
+Install CouchDB without a service, but with an admin user:password of `admin:hunter2`:
+
+```
+msiexec /i apache-couchdb-3.0.0.msi /quiet ADMINUSER=admin ADMINPASSWORD=hunter2 /norestart
+```
+
+The same as above, but also install and launch CouchDB as a service:
+
+```
+msiexec /i apache-couchdb-3.0.0.msi /quiet INSTALLSERVICE=1 ADMINUSER=admin ADMINPASSWORD=hunter2 /norestart
+```
+
+Unattended uninstall of CouchDB:
+
+```
+msiexec /x apache-couchdb-3.0.0.msi /quiet /norestart
+```
+
+Unattended uninstall if the installer file is unavailable:
+
+```
+msiexec /x {4CD776E0-FADF-4831-AF56-E80E39F34CFC} /quiet /norestart
+```
+
+Add `/l* log.txt` to any of the above to generate a useful logfile for debugging.
diff --git a/README.md b/README.md
index a14a1cd..661e72e 100644
--- a/README.md
+++ b/README.md
@@ -4,13 +4,16 @@
 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.
 
+Of course, you can also use our [previous script collection](README.OLD.md)
+to create CouchDB for Windows. Please note that this is currently no longer
+tested.
 
 # Base Requirements
 
@@ -26,11 +29,12 @@
 Start an Administrative PowerShell console. Enter the following:
 
 ```powershell
-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'))
+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://community.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,134 +43,66 @@
 
 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, pygments, nose2 and hypothesis
 * NSSM
-* GPG4Win (for signing releases)
-* checksum
-* archiver
-* Dependency Walker
-* unzip
-* NSIS
+* GNU make
 * NuGet
 * VSSetup
-* MozillaBuild setup (3.3)
+* VSWhere
+* GNU CoreUtils (cp, rm, rmdir, ...)
+* 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
-
-# Building Erlang
-
-This section is not presently automated because it requires switching between PowerShell
-and Cygwin. It should be possible to automate (PRs welcome!)
-
-We generally need to build a version of Erlang that is not distributed directly
-by Ericsson. This may be because we require patches that are released after the
-binaries are built.
-
-For CouchDB 3.0, we build against Erlang 20.3.8.25.
-
-In the same PowerShell session, enter the following:
-
-```powershell
-cd c:\relax
-cygwin
-git clone https://github.com/erlang/otp
-cd otp
-git checkout OTP-20.3.8.25
-export PATH="/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.8 Tools/x64:/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64:/cygdrive/c/Program Files (x86)/NSIS:/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64:$PATH"
-which cl link mc lc mt nmake rc
-```
-
-This should produce the following output:
-
-```
-/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl
-/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/link
-/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/mc
-/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.8 Tools/x64/lc
-/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/mt
-/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/nmake
-/cygdrive/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/rc
-```
-
-Continue by entering the following. This takes a while, maybe 30-60 minutes at the `otp_build` steps, so be sure to have your favourite beverage on hand while you watch.
-
-```
-cd /cygdrive/c/relax/otp
-eval `./otp_build env_win32 x64`
-./otp_build autoconf 2>&1 | tee build_autoconf.txt
-./otp_build configure --with-ssl=/cygdrive/c/relax/vcpkg/installed/x64-windows --without-javac --without-debugger --without-wx --without-ic --without-odbc --without-et --without-cosEvent --without-cosEventDomain --without-cosFileTransfer --without-cosNotification --without-cosProperty --without-cosTime --without-cosTransactions --without-orber --without-observer 2>&1 | tee build_configure.txt
-./otp_build boot -a  2>&1 | tee build_boot.txt
-./otp_build release -a  2>&1 | tee build_release.txt
-./otp_build installer_win32  2>&1 | tee build_installer_win32.txt
-release/win32/otp_win64_*.exe /S
-exit
-```
-
-You now have a full install of Erlang on your system.
-
-# Installing Elixir
-
-CouchDB uses Elixir for tests. If you intend to run the test suite (you should!), install
-Elixir now by running the following in the same PowerShell prompt:
-
-```
-wget.exe https://github.com/elixir-lang/elixir/releases/download/v1.9.4/Precompiled.zip
-arc unarchive .\Precompiled.zip
-copy .\Precompiled\* 'C:\Program Files\erl9.3.3.14\' -Recurse  -Force
-del Precompiled -Recurse
-del Precompiled.zip
-```
+  * ICU (at time of writing, 69.1)
 
 # 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
+git checkout esr91
+./mach bootstrap --application-choice js
+```
+
+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
+
+
+```bash
+export MOZCONFIG=/c/relax/couchdb-glazier/moz/sm-opt
+./mach build
 exit
 ```
-
-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.
-
+Now you should have built Spidermonkey.
 Back in PowerShell, copy the binaries to where our build process expects them:
 
-```
-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
+```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
@@ -176,7 +112,7 @@
 Open a new PowerShell window. Set up your shell correctly (this step works if you've
 closed your PowerShell window before any of the previous steps, too):
 
-```
+```powershell
 &c:\relax\couchdb-glazier\bin\shell.ps1
 ```
 
@@ -187,7 +123,7 @@
 git clone https://github.com/apache/couchdb
 cd couchdb
 git checkout <tag or branch of interest goes here>
-&.\configure.ps1 -SpiderMonkeyVersion 60
+&.\configure.ps1 -SpiderMonkeyVersion 91
 make -f Makefile.win
 ```
 
@@ -234,31 +170,6 @@
 
 There is a branch of glazier that has been used to build each CouchDB release.
 
-## UNIX-friendly shell details
-
-Our goal is to get the path set up in this order:
-
-1. erlang and couchdb build helper scripts
-2. Microsoft VC compiler, linker, etc from Windows SDK
-3. cygwin path for other build tools like make, autoconf, libtool
-4. the remaining windows system path
-
-It seems this is a challenge for most environments, so `glazier` gets this all right for
-you by running the MSVC environment, then tacking on the things Erlang expects at the end
-of the path.
-
-Overall, the desired order for your $PATH is:
-
-- Erlang build helper scripts
-- Visual C++ / .NET framework / SDK
-- Ancillary Erlang and CouchDB packaging tools
-- Usual cygwin unix tools such as make, gcc
-- Ancillary glazier/relax tools for building dependent libraries
-- Usual Windows folders `%windir%;%windir%\system32` etc
-- Various settings form the `otp_build` script
-
-More details are at [erlang INSTALL-Win32.md on github](https://github.com/erlang/otp/blob/master/HOWTO/INSTALL-WIN32.md)
-
 ## Windows silent installs
 
 Here are some sample commands, supporting the new features of the 3.0 installer.
diff --git a/THANKS b/THANKS
index 1cf752a..0acc22f 100644
--- a/THANKS
+++ b/THANKS
@@ -7,3 +7,7 @@
 Oliver Tonnhofer
 Nick North
 Peng Hui Jiang
+Jan Lenhardt
+Olivia Hugger
+Will Young
+Ronny Berndt
diff --git a/bin/build_installer.ps1 b/bin/build_installer.ps1
index 2bde102..d528125 100644
--- a/bin/build_installer.ps1
+++ b/bin/build_installer.ps1
@@ -69,9 +69,10 @@
 candle -arch x64 "-dCouchDir=${CouchDB}" couchdbfiles.wxs
 candle -arch x64 -ext WiXUtilExtension couchdb_wixui.wxs
 candle -arch x64 -ext WiXUtilExtension adminprompt.wxs
+candle -arch x64 -ext WiXUtilExtension cookieprompt.wxs
 candle -arch x64 -ext WiXUtilExtension customexit.wxs
 candle -arch x64 -ext WiXUtilExtension CouchInstallDirDlg.wxs
-light -sw1076 -sice:ICE17 -ext WixUIExtension -ext WiXUtilExtension "-cultures:en-us;en;neutral" adminprompt.wixobj couchdb.wixobj couchdbfiles.wixobj couchdb_wixui.wixobj customexit.wixobj CouchInstallDirDlg.wixobj -out apache-couchdb-${CouchDBVersion}.msi
+light -sw1076 -sice:ICE17 -ext WixUIExtension -ext WiXUtilExtension "-cultures:en-us;en;neutral" adminprompt.wixobj cookieprompt.wixobj couchdb.wixobj couchdbfiles.wixobj couchdb_wixui.wixobj customexit.wixobj CouchInstallDirDlg.wixobj -out apache-couchdb-${CouchDBVersion}.msi
 
 Pop-Location
 
diff --git a/bin/install_dependencies.ps1 b/bin/install_dependencies.ps1
index b1b4162..3c145fe 100644
--- a/bin/install_dependencies.ps1
+++ b/bin/install_dependencies.ps1
@@ -10,36 +10,49 @@
 # 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 --add Microsoft.Net.Component.4.8.TargetingPack"
+choco install nodejs-lts wixtoolset make nssm python3 vswhere gnuwin32-coreutils.portable
 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 nose2 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 $elxInstallPath
+
+# 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
+# we know what we are doing (, do we really?)
+Set-ExecutionPolicy Bypass -Scope CurrentUser -Force
 
-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
-
+# start shell
 . ${PSScriptRoot}\shell.ps1
diff --git a/bin/shell.ps1 b/bin/shell.ps1
index acb1405..84235ed 100644
--- a/bin/shell.ps1
+++ b/bin/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,7 +28,8 @@
 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 += ";${elxInstallPath}\bin" 
 $env:PATH += ";C:\relax\vcpkg\installed\x64-windows\bin"
 $env:PATH += ";C:\Program Files (x86)\WiX Toolset v3.11\bin"
 
@@ -28,4 +37,4 @@
 $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
+
diff --git a/bin/variables.ps1 b/bin/variables.ps1
new file mode 100644
index 0000000..828e4c3
--- /dev/null
+++ b/bin/variables.ps1
@@ -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.13/otp_win64_23.3.4.13.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.12.3/Precompiled.zip"
+$elxBuildFile = Split-Path $elxBuildUri -Leaf
+$elxInstallPath = "C:\relax\elixir"
diff --git a/installer/CustomAction/CouchIniAction.cs b/installer/CustomAction/CouchIniAction.cs
index 0b7e0ff..4a82e3f 100644
--- a/installer/CustomAction/CouchIniAction.cs
+++ b/installer/CustomAction/CouchIniAction.cs
@@ -3,101 +3,194 @@
 using System.IO;
 using System.Security.Cryptography;
 using System.Text;
+using System.Text.RegularExpressions;
 using Microsoft.Deployment.WindowsInstaller;
 
 namespace CustomAction
 {
-   public class CustomActions
-   {
-      [CustomAction] public static ActionResult WriteAdminIniFile(Session session)
-      {
-         try
-         {
-            if (!File.Exists(session.CustomActionData["ADMINCONFIGFILE"])) {
-               using (StreamWriter writer = new StreamWriter(session.CustomActionData["ADMINCONFIGFILE"]))
-               {
-                  writer.WriteLine("; CouchDB Windows installer-generated admin user");
-                  writer.WriteLine("[admins]");
-                  writer.WriteLine($"{session.CustomActionData["ADMINUSER"]} = {session.CustomActionData["ADMINPASSWORD"]}");
-               }
-            }
-         }
-         catch (Exception ex)
-         {
-            session.Log("ERROR in custom action WriteAdminIniFile {0}",
-                  ex.ToString());
-            return ActionResult.Failure;
-         }
-
-         return ActionResult.Success;
-      }
-
-      [CustomAction] public static ActionResult MaybeCopyIniFiles(Session session)
-      {
-         try
-         {
-            string[] files = new string[2];
-            files[0] = "vm.args";
-            files[1] = "local.ini";
-
-            foreach (string file in files)
+    public class CustomActions
+    {
+        [CustomAction]
+        public static ActionResult InitCookieValue(Session session)
+        {
+            try
             {
-               if (!File.Exists(Path.Combine(session.CustomActionData["ETCDIR"], file)))
-               {
-                  File.Copy(
-                        Path.Combine(session.CustomActionData["ETCDIR"], file + ".dist"),
-                        Path.Combine(session.CustomActionData["ETCDIR"], file)
-                        );
-               }
+                byte[] buffer = new byte[16];
+                RandomNumberGenerator rng = RNGCryptoServiceProvider.Create();
+                rng.GetBytes(buffer);
+                session["COOKIEVALUE"] = BitConverter.ToString(buffer).Replace("-", String.Empty);
             }
-         }
-         catch (Exception ex)
-         {
-            session.Log("ERROR in custom action MaybeCopyIniFiles {0}",
-                  ex.ToString());
-            return ActionResult.Failure;
-         }
-         return ActionResult.Success;
-      }
-
-      [CustomAction] public static ActionResult MaybeRemoveUserConfig(Session session)
-      {
-         try
-         {
-            string[] files = new string[2];
-            files[0] = "vm.args";
-            files[1] = "local.ini";
-
-            foreach (string file in files)
+            catch (Exception ex)
             {
-               if (File.Exists(Path.Combine(session.CustomActionData["ETCDIR"], file)) &&
-                     File.Exists(Path.Combine(session.CustomActionData["ETCDIR"], file + ".dist")))
-               {
-                  if (GetChecksum(Path.Combine(session.CustomActionData["ETCDIR"], file)) ==
-                        GetChecksum(Path.Combine(session.CustomActionData["ETCDIR"], file + ".dist")))
-                  {
-                     File.Delete(Path.Combine(session.CustomActionData["ETCDIR"], file));
-                  }
-               }
+                session.Log("ERROR in custom action InitCookieValue {0}",
+                      ex.ToString());
+                return ActionResult.Failure;
             }
-         }
-         catch (Exception ex)
-         {
-            session.Log("ERROR in custom action MaybeRemoveUserConfig {0}",
-                  ex.ToString());
-            return ActionResult.Failure;
-         }
-         return ActionResult.Success;
-      }
 
-      private static string GetChecksum(string file)
-      {
-         using (FileStream stream = File.OpenRead(file))
-         {
-            SHA256Managed sha = new SHA256Managed();
-            byte[] checksum = sha.ComputeHash(stream);
-            return BitConverter.ToString(checksum).Replace("-", String.Empty);
-         }
-      }
-   }
+            return ActionResult.Success;
+        }
+        [CustomAction]
+        public static ActionResult WriteAdminIniFile(Session session)
+        {
+            try
+            {
+                if (!File.Exists(session.CustomActionData["ADMINCONFIGFILE"]))
+                {
+                    using (StreamWriter writer = new StreamWriter(session.CustomActionData["ADMINCONFIGFILE"]))
+                    {
+                        writer.WriteLine("; CouchDB Windows installer-generated admin user");
+                        writer.WriteLine("[admins]");
+                        writer.WriteLine($"{session.CustomActionData["ADMINUSER"]} = {session.CustomActionData["ADMINPASSWORD"]}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                session.Log("ERROR in custom action WriteAdminIniFile {0}",
+                      ex.ToString());
+                return ActionResult.Failure;
+            }
+
+            return ActionResult.Success;
+        }
+
+        [CustomAction]
+        public static ActionResult WriteCookieToVmArgs(Session session)
+        {
+            try
+            {
+                string VMARGSFILE = Path.Combine(session.CustomActionData["ETCDIR"], "vm.args");
+                if (File.Exists(VMARGSFILE))
+                {
+                    session.Log("Patching erlang cookie in existing vm.args file");
+                    PatchErlangCookie(session, VMARGSFILE);
+                }
+
+                string VMFile = Path.Combine(session.CustomActionData["ETCDIR"], "vm.args.dist");
+                byte[] VMBuffer = File.ReadAllBytes(VMFile);
+                string VMText = Regex.Replace(Encoding.UTF8.GetString(VMBuffer), @"# -setcookie", $"-setcookie {session.CustomActionData["COOKIEVALUE"]}");
+                File.WriteAllBytes(VMFile, Encoding.UTF8.GetBytes(VMText));
+            }
+            catch (Exception ex)
+            {
+                session.Log("ERROR in custom action WriteCookieToVmArgs {0}",
+                      ex.ToString());
+                return ActionResult.Failure;
+            }
+
+            return ActionResult.Success;
+        }
+
+        private static void PatchErlangCookie(Session session, string file)
+        {
+            //Patching erlang cookie
+            byte[] VMBuffer = File.ReadAllBytes(file);
+            string VMText = Regex.Replace(Encoding.UTF8.GetString(VMBuffer), @"-setcookie \S*", $"-setcookie {session.CustomActionData["COOKIEVALUE"]}");
+            File.WriteAllBytes(file, Encoding.UTF8.GetBytes(VMText));
+        }
+
+        private static void PatchErlangInterface(Session session, string file)
+        {
+            byte[] VMBuffer = File.ReadAllBytes(file);
+
+            //Patching erlang interface
+            string pattern = @"-kernel inet_dist_use_interface";
+            string input = Encoding.UTF8.GetString(VMBuffer);
+            Match m = Regex.Match(input, pattern, RegexOptions.IgnoreCase);
+            if (!m.Success)
+            {
+                session.Log("Pattern \"inet_dist_use_interface\" not found, appending fix.");
+
+                using (StreamWriter sw = File.AppendText(file))
+                {
+                    sw.WriteLine();
+                    sw.WriteLine("# Which interfaces should the node listen on?");
+                    sw.WriteLine("-kernel inet_dist_use_interface {127,0,0,1}");
+                    sw.Close();
+                }
+            }
+            else
+            {
+                session.Log("Pattern \"inet_dist_use_interface\" found, skipping.");
+            }
+        }
+
+        [CustomAction]
+        public static ActionResult MaybeCopyIniFiles(Session session)
+        {
+            try
+            {
+                string[] files = new string[2];
+                files[0] = "vm.args";
+                files[1] = "local.ini";
+
+                string VMARGSFILE = Path.Combine(session.CustomActionData["ETCDIR"], files[0]);
+
+                if (File.Exists(VMARGSFILE))
+                {
+                    session.Log("Patching erlang interface in existing vm.args file");
+                    PatchErlangInterface(session, VMARGSFILE);
+                }
+
+                foreach (string file in files)
+                {
+                    if (!File.Exists(Path.Combine(session.CustomActionData["ETCDIR"], file)))
+                    {
+                        File.Copy(
+                              Path.Combine(session.CustomActionData["ETCDIR"], file + ".dist"),
+                              Path.Combine(session.CustomActionData["ETCDIR"], file)
+                              );
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                session.Log("ERROR in custom action MaybeCopyIniFiles {0}",
+                      ex.ToString());
+                return ActionResult.Failure;
+            }
+            return ActionResult.Success;
+        }
+
+        [CustomAction]
+        public static ActionResult MaybeRemoveUserConfig(Session session)
+        {
+            try
+            {
+                string[] files = new string[2];
+                files[0] = "vm.args";
+                files[1] = "local.ini";
+
+                foreach (string file in files)
+                {
+                    if (File.Exists(Path.Combine(session.CustomActionData["ETCDIR"], file)) &&
+                          File.Exists(Path.Combine(session.CustomActionData["ETCDIR"], file + ".dist")))
+                    {
+                        if (GetChecksum(Path.Combine(session.CustomActionData["ETCDIR"], file)) ==
+                              GetChecksum(Path.Combine(session.CustomActionData["ETCDIR"], file + ".dist")))
+                        {
+                            File.Delete(Path.Combine(session.CustomActionData["ETCDIR"], file));
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                session.Log("ERROR in custom action MaybeRemoveUserConfig {0}",
+                      ex.ToString());
+                return ActionResult.Failure;
+            }
+            return ActionResult.Success;
+        }
+
+        private static string GetChecksum(string file)
+        {
+            using (FileStream stream = File.OpenRead(file))
+            {
+                SHA256Managed sha = new SHA256Managed();
+                byte[] checksum = sha.ComputeHash(stream);
+                return BitConverter.ToString(checksum).Replace("-", String.Empty);
+            }
+        }
+    }
 }
diff --git a/installer/CustomAction/CustomAction.config b/installer/CustomAction/CustomAction.config
index 16a542b..6bf9448 100644
--- a/installer/CustomAction/CustomAction.config
+++ b/installer/CustomAction/CustomAction.config
@@ -7,6 +7,6 @@
  -->
   <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
-        <supportedRuntime version="v2.0.50727" />
+        <supportedRuntime version="v4.0" />
      </startup>
   </configuration>
diff --git a/installer/CustomAction/CustomAction.csproj b/installer/CustomAction/CustomAction.csproj
index 7b6bd51..80399ef 100644
--- a/installer/CustomAction/CustomAction.csproj
+++ b/installer/CustomAction/CustomAction.csproj
@@ -10,7 +10,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>CustomAction</RootNamespace>
     <AssemblyName>CouchIniAction</AssemblyName>
-    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <WixCATargetsPath Condition=" '$(WixCATargetsPath)' == '' ">C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix.ca.targets</WixCATargetsPath>
   </PropertyGroup>
diff --git a/installer/cookieprompt.wxs b/installer/cookieprompt.wxs
new file mode 100644
index 0000000..844ef85
--- /dev/null
+++ b/installer/cookieprompt.wxs
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+   <Fragment>
+      <Property Id="COOKIEVALUE" Hidden="yes" />
+      <UI>
+         <Dialog Id="CookiePromptDlg" Width="370" Height="270" Title="Set Cookie value">
+            <Control Id="Title" Type="Text" X="20" Y="20" Width="220" Height="30" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Emphasized}Set Cookie value" />
+            <Control Id="Description" Type="Text" X="20" Y="50" Width="220" Height="40" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Emphasized}For security reasons, the cookie value that CouchDB instances use to communicate between each other needs to be set even in standalone mode." />
+            <Control Id="Label" Type="Text" Width="322" Height="10" X="20" Y="110" Text="Cookie value:" />
+            <Control Id="Textbox" Type="Edit" Width="200" Height="15" X="20" Y="123" Property="COOKIEVALUE" />
+	    <Control Id="Validate" Type="PushButton" Width="100" Height="15" X="140" Y="180" Text="Validate Cookie" />
+	    <Control Id="Random" Type="PushButton" Width="100" Height="15" X="20" Y="180" Text="Random Cookie">
+               <Publish Event="DoAction" Value="InitCookieValue">1</Publish>
+               <Publish Property="COOKIEVALUE" Value="[COOKIEVALUE]">1</Publish>
+	    </Control>
+            <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
+            <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
+            <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)">
+               <Condition Action="disable"><![CDATA[(COOKIEVALUE = "") OR (COOKIEVALUE >< " ")]]></Condition>
+               <Condition Action="enable"><![CDATA[(COOKIEVALUE <> "") AND NOT (COOKIEVALUE >< " ")]]></Condition>
+
+               <Publish Property="COOKIEVALUE" Value="[COOKIEVALUE]">1</Publish>
+            </Control>
+            <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
+               <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
+            </Control>
+         </Dialog>
+      </UI>
+   </Fragment>
+</Wix>
+
diff --git a/installer/couchdb.wxs.in b/installer/couchdb.wxs.in
index 390ac23..f979547 100644
--- a/installer/couchdb.wxs.in
+++ b/installer/couchdb.wxs.in
@@ -48,7 +48,7 @@
       </Directory>
 
       <DirectoryRef Id="TARGETDIR">
-         <Merge Id="VCRedist141" SourceFile="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Redist\MSVC\14.16.27012\MergeModules\Microsoft_VC141_CRT_x64.msm" DiskId="1" Language="0"/>
+         <Merge Id="VCRedist143" SourceFile="C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Redist\MSVC\14.31.31103\MergeModules\Microsoft_VC143_CRT_x64.msm" DiskId="1" Language="0"/>
       </DirectoryRef>
 
       <SetProperty Id="ARPINSTALLLOCATION" Value="[APPLICATIONFOLDER]"
@@ -105,8 +105,8 @@
          <ComponentGroupRef Id="CouchDBFilesGroup" />
       </Feature>
 
-      <Feature Id="VCRedist141" Title="Visual C++ 14.1 Runtime" AllowAdvertise="no" Display="hidden" Level="1">
-         <MergeRef Id="VCRedist141"/>
+      <Feature Id="VCRedist143" Title="Microsoft Visual C++ 2015-2022 Redistributable (x64)" AllowAdvertise="no" Display="hidden" Level="1">
+         <MergeRef Id="VCRedist143"/>
       </Feature>
 
       <!--Custom actions and execute sequences-->
@@ -119,6 +119,19 @@
          Value="ADMINCONFIGFILE=[APPLICATIONFOLDER]etc\local.d\10-admins.ini;ADMINUSER=[ADMINUSER];ADMINPASSWORD=[ADMINPASSWORD]"
          />
       <CustomAction
+         Id="SetCookieValueInVmArgsPropertyValues"
+         Property="WriteCookieToVmArgs"
+         Value="ETCDIR=[APPLICATIONFOLDER]etc;COOKIEVALUE=[COOKIEVALUE]"
+         />
+      <CustomAction
+         Id="InitCookieValue"
+         Return="check"
+         DllEntry="InitCookieValue"
+         HideTarget="yes"
+         BinaryKey="CouchIniActionDll" 
+         Impersonate="no"
+         />
+      <CustomAction
          Id="WriteAdminIniFile"
          Return="check"
          Execute="deferred"
@@ -127,6 +140,15 @@
          BinaryKey="CouchIniActionDll" 
          Impersonate="no"
          />
+      <CustomAction
+         Id="WriteCookieToVmArgs"
+         Return="check"
+         Execute="deferred"
+         DllEntry="WriteCookieToVmArgs"
+         HideTarget="yes"
+         BinaryKey="CouchIniActionDll" 
+         Impersonate="no"
+         />
 
       <CustomAction
          Id="SetMaybeCopyIniFilesValues"
@@ -252,8 +274,10 @@
       <Property Id="SCHEDULEREBOOT" Value="0" />
       <InstallExecuteSequence>
          <Custom Action="SetAdminIniCustomActionPropertyValues" After="InstallFiles">NOT Installed AND NOT REMOVE</Custom>
-         <Custom Action="WriteAdminIniFile" After="SetAdminIniCustomActionPropertyValues">NOT Installed AND NOT REMOVE</Custom>
-         <Custom Action="SetMaybeCopyIniFilesValues" After="WriteAdminIniFile">NOT Installed AND NOT REMOVE</Custom>
+         <Custom Action="SetCookieValueInVmArgsPropertyValues" After="SetAdminIniCustomActionPropertyValues">NOT Installed AND NOT REMOVE</Custom>
+         <Custom Action="WriteAdminIniFile" After="SetCookieValueInVmArgsPropertyValues">NOT Installed AND NOT REMOVE</Custom>
+         <Custom Action="WriteCookieToVmArgs" After="WriteAdminIniFile">NOT Installed AND NOT REMOVE</Custom>
+         <Custom Action="SetMaybeCopyIniFilesValues" After="WriteCookieToVmArgs">NOT Installed AND NOT REMOVE</Custom>
          <Custom Action="MaybeCopyIniFiles" After="SetMaybeCopyIniFilesValues">NOT Installed AND NOT REMOVE</Custom>
          <Custom Action="InstallCouchDBService" After="MaybeCopyIniFiles">INSTALLSERVICE AND NOT Installed AND NOT REMOVE</Custom>
          <Custom Action="StartCouchDBService" After="InstallCouchDBService">INSTALLSERVICE AND NOT Installed AND NOT REMOVE</Custom>
diff --git a/installer/couchdb_wixui.wxs b/installer/couchdb_wixui.wxs
index 453777f..336d5f3 100644
--- a/installer/couchdb_wixui.wxs
+++ b/installer/couchdb_wixui.wxs
@@ -44,9 +44,11 @@
             <Publish Dialog="CouchInstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
 
             <Publish Dialog="AdminPromptDlg" Control="Back" Event="NewDialog" Value="CouchInstallDirDlg">1</Publish>
-            <Publish Dialog="AdminPromptDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
+            <Publish Dialog="AdminPromptDlg" Control="Next" Event="NewDialog" Value="CookiePromptDlg">1</Publish>
+            <Publish Dialog="CookiePromptDlg" Control="Back" Event="NewDialog" Value="AdminPromptDlg">1</Publish>
+            <Publish Dialog="CookiePromptDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
             
-            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="AdminPromptDlg" Order="1">NOT Installed</Publish>
+            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="CookiePromptDlg" Order="1">NOT Installed</Publish>
             <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
             <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>
 
diff --git a/moz/sm-opt b/moz/sm-opt
new file mode 100644
index 0000000..822cc54
--- /dev/null
+++ b/moz/sm-opt
@@ -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