From b5dc6db387dc28740f76a29def89dd8b09377fe4 Mon Sep 17 00:00:00 2001
From: Jonah Beckford <9566106-jonahbeckford@users.noreply.gitlab.com>
Date: Wed, 22 Nov 2023 13:49:17 -0800
Subject: [PATCH] Add winget instructions

+ Add GitForTesting renew Git credentials instructions

Part of https://github.com/diskuv/dkml-installer-ocaml/issues/79
---
 DEVELOPERS.md                              | 42 +++++++++++++++++++---
 contributors/changes/v2.1.0.md             | 42 +++++++++++++++-------
 pkg/bump/WindowsSandbox/CMakeLists.txt     |  1 +
 pkg/bump/WindowsSandbox/install-winget.ps1 | 12 +++++++
 4 files changed, 80 insertions(+), 17 deletions(-)
 create mode 100644 pkg/bump/WindowsSandbox/install-winget.ps1

diff --git a/DEVELOPERS.md b/DEVELOPERS.md
index 18c6178c..2e860cc4 100644
--- a/DEVELOPERS.md
+++ b/DEVELOPERS.md
@@ -14,9 +14,13 @@
    the highest Stage number. Many stages require a re-configuration based on
    values obtained from the prior stages, so do not skip any targets.
 
+   Notes:
+   1. When you get to `Package-Stage10-GitPushForTesting`, make sure you do `git fetch` in
+      the `dkml` project to renew your Git credentials if you have leased Git credentials.
+
    Errata:
-   1. For Stage2-DuneFlavor, you may need to run it twice. The first time you
-      may encounter:
+   1. For Stage2-DuneFlavor, you may need to run it multiple times. The first times you
+      may encounter flakiness:
 
       ```text
       [build] [ERROR] Could not update repository "default": "...\\build\\pkg\\bump\\msys64\\usr\\bin\\mv.exe ...\\build\\pkg\\bump\\.ci\\o\\repo\\default.new ...\\build\\pkg\\bump\\.ci\\o\\repo\\default" exited with code 1 "/usr/bin/mv: cannot move '...\build\pkg\bump\.ci\o\repo\default.new' to '...\build\pkg\bump\.ci\o\repo\default': Permission denied"
@@ -28,9 +32,39 @@
 
       ```text
       [build] # File "installer/bin/runner_user.ml", line 1, characters 9-54:
-      [build] # 1 | let () = Dkml_component_network_ocamlcompiler.register ()
+      [build] # 1 | let () = Dkml_component_ocamlcompiler_common.register ()
       [build] #              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-      [build] # Error: Unbound module Dkml_component_network_ocamlcompiler
+      [build] # Error: Unbound module Dkml_component_ocamlcompiler_common
       ```
 
 6. Finish with the CMake target `-PublishAssets`.
+
+## Editing Source Code
+
+### Visual Studio Code
+
+You can edit OCaml code after you have built the `Package-Stage04-FullFlavor` target.
+
+In Visual Studio Code:
+
+1. Go to View > Command Palette and select `OCaml: Select a Sandbox for this Workspace`.
+2. Choose "Custom"
+3. Enter the following (with the paths changed to reflect your project directory, and the correct DkML version number):
+
+   ```powershell
+   Y:\source\dkml\build\pkg\bump\.ci\sd4\bs\bin\opam.exe list --switch 2.1.0 --root Y:/source/dkml/build/pkg/bump/.ci/o -- $prog $args
+   ```
+
+### Dune Build
+
+You can go into directories to build each project you want to edit. For example:
+
+```powershell
+cd build\_deps\dkml-runtime-apps-src
+Y:\source\dkml\build\pkg\bump\.ci\sd4\bs\bin\opam.exe exec --switch 2.1.0 --root Y:\source\dkml\build\pkg\bump\.ci\o -- dune build
+```
+
+### Git
+
+You can do `git commit` in each `build/_deps/*-src` directory. There are `Package-Stage*` targets that will push in changes
+at the appropriate times.
diff --git a/contributors/changes/v2.1.0.md b/contributors/changes/v2.1.0.md
index a1d4b0aa..156add16 100644
--- a/contributors/changes/v2.1.0.md
+++ b/contributors/changes/v2.1.0.md
@@ -18,7 +18,19 @@ for their GitHub Actions / GitLab CI:
 
 ### Major Changes
 
+* Installation directory has changed from `<LOCALAPPDATA>/Programs/DiskuvOCaml` to `<LOCALAPPDATA>/Programs/DkML`
 * Opam upgraded from 2.2.0 `alpha0` to 2.2.0 `alpha3`.
+* The installer no longer auto-installs Visual Studio Build Tools, and a `setup*.exe` installer is no longer provided.
+  Instead we use ["wget"](https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget) as described
+  in [New Install Steps](#new-install-steps):
+
+  > Windows Package Manager **winget** command-line tool is available on Windows 11 and
+  > modern versions of Windows 10 as a part of the **App Installer**.
+  >
+  > You can [get App Installer from the Microsoft Store].
+  > If it's already installed, make sure it is updated with the latest version.
+
+[get App Installer from the Microsoft Store]: https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab
 
 ### Known Issues
 
@@ -32,18 +44,7 @@ for their GitHub Actions / GitLab CI:
 
 ### New Install Steps
 
-The installer no longer auto-installs Visual Studio Build Tools, and a `setup*.exe` installer is no longer provided.
-Instead we use ["wget"](https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget):
-
-> Windows Package Manager **winget** command-line tool is available on Windows 11 and
-> modern versions of Windows 10 as a part of the **App Installer**.
->
-> You can [get App Installer from the Microsoft Store].
-> If it's already installed, make sure it is updated with the latest version.
-
-[get App Installer from the Microsoft Store]: https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab
-
-So Windows 11 users already have `winget`, but Windows 10 users will need to [get App Installer from the Microsoft Store].
+Windows 11 users already have `winget`, but Windows 10 users will need to [get App Installer from the Microsoft Store].
 
 Then run these three steps from the Command Prompt or PowerShell:
 
@@ -51,9 +52,10 @@ Then run these three steps from the Command Prompt or PowerShell:
 # Visual Studio 2019 Build Tools
 # ------------------------------
 #
+# You can change "--installPath" if you need disk space (3GB+), but do not use spaces or parentheses. Bad: C:\Program Files (x86)
 # You can review what components are installed at:
 #   https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2019
-winget install Microsoft.VisualStudio.2019.BuildTools --override "--wait --quiet --addProductLang En-us --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
+winget install Microsoft.VisualStudio.2019.BuildTools --override "--wait --quiet --installPath C:\VS --addProductLang En-us --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
 
 # Git for Windows
 # ---------------
@@ -74,6 +76,20 @@ The practical consequence is that the first time you run `opam`, `dune` or `dkml
 2. The opam root will be initialized.
 3. The global "playground" switch will be installed.
 
+You can do those steps now with a **new** Command Prompt or PowerShell windows:
+
+```powershell
+# IMPORTANT: If you run Windows in a VirtualBox, or have a computer manufactured before 2013 (ie. pre-Haswell or
+# pre-Piledriver CPU), run the following instead to avoid https://github.com/ocaml/ocaml/issues/12513:
+#   dkml init --system --enable-imprecise-c99-float-ops
+dkml init --system
+```
+
+Minor benefits of this new install approach:
+
+* System wide configuration options can be provided directly to `dkml init --system <more options>` rather than
+  through user-written configuration files.
+
 ### Internal Changes
 
 ### Upgraded Packages
diff --git a/pkg/bump/WindowsSandbox/CMakeLists.txt b/pkg/bump/WindowsSandbox/CMakeLists.txt
index 90a82be0..25e43e3d 100644
--- a/pkg/bump/WindowsSandbox/CMakeLists.txt
+++ b/pkg/bump/WindowsSandbox/CMakeLists.txt
@@ -7,6 +7,7 @@ cmake_path(NATIVE_PATH TOOLSDIR TOOLSDIR_NATIVE)
 configure_file(config.in.wsb config.wsb @ONLY)
 configure_file(installer-native.in.cmd ${TOOLSDIR}/installer-native.cmd @ONLY NEWLINE_STYLE DOS)
 configure_file(installer-byte.in.cmd ${TOOLSDIR}/installer-byte.cmd @ONLY NEWLINE_STYLE DOS)
+configure_file(install-winget.in.ps1 ${TOOLSDIR}/install-winget.ps1 @ONLY)
 configure_file(test.in.cmd ${TOOLSDIR}/test.cmd @ONLY NEWLINE_STYLE DOS)
 file(COPY proj1 proj2 script1 DESTINATION ${TOOLSDIR})
 
diff --git a/pkg/bump/WindowsSandbox/install-winget.ps1 b/pkg/bump/WindowsSandbox/install-winget.ps1
new file mode 100644
index 00000000..be03ddd7
--- /dev/null
+++ b/pkg/bump/WindowsSandbox/install-winget.ps1
@@ -0,0 +1,12 @@
+# https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox
+
+$progressPreference = 'silentlyContinue'
+Write-Information "Downloading WinGet and its dependencies..."
+Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
+Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
+Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -OutFile Microsoft.UI.Xaml.2.7.x64.appx
+Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx
+Add-AppxPackage Microsoft.UI.Xaml.2.7.x64.appx
+Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
+
+$progressPreference = 'Continue'