Repository: bitcoin/bitcoin
File: .github/ci-windows.py (Python)

Code before:
#!/usr/bin/env python3
# Copyright (c) The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

import argparse
import os
import shlex
import subprocess
import sys


def run(cmd, **kwargs):
    print("+ " + shlex.join(cmd), flush=True)
    kwargs.setdefault("check", True)
    try:
        return subprocess.run(cmd, **kwargs)
    except Exception as e:
        sys.exit(str(e))


GENERATE_OPTIONS = {
    "standard": [
        "-DBUILD_BENCH=ON",
        "-DBUILD_KERNEL_LIB=ON",
        "-DBUILD_UTIL_CHAINSTATE=ON",
        "-DWERROR=ON",
    ],
    "fuzz": [
        "-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON",
        "-DVCPKG_MANIFEST_FEATURES=wallet",
        "-DBUILD_GUI=OFF",
        "-DWITH_ZMQ=OFF",
        "-DBUILD_FOR_FUZZING=ON",
        "-DWERROR=ON",
    ],
}


def generate(ci_type):
    toolchain_file = os.path.join(
        os.environ.get("VCPKG_INSTALLATION_ROOT"),
        "scripts",
        "buildsystems",
        "vcpkg.cmake",
    )
    command = [
        "cmake",

Review comment (performance):
In fae5e78e1fe

As we are moving this from ci yaml config, which I thoroughly agree with, I woudl prefer to see this go into _CMakePresets.json_ instead, where it can be (re-)used by anybody without needing to use (and likely modify) this python script?

It's possible to inherit inside of a preset file, so this might look something like (untested etc.):

```diff
diff --git a/.github/ci-windows.py b/.github/ci-windows.py
index adf5437f870..5855e60c915 100755
--- a/.github/ci-windows.py
+++ b/.github/ci-windows.py
@@ -19,21 +19,9 @@ def run(cmd, **kwargs):
         sys.exit(str(e))
 
 
-GENERATE_OPTIONS = {
-    "standard": [
-        "-DBUILD_BENCH=ON",
-        "-DBUILD_KERNEL_LIB=ON",
-        "-DBUILD_UTIL_CHAINSTATE=ON",
-        "-DWERROR=ON",
-    ],
-    "fuzz": [
-        "-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON",
-        "-DVCPKG_MANIFEST_FEATURES=wallet",
-        "-DBUILD_GUI=OFF",
-        "-DWITH_ZMQ=OFF",
-        "-DBUILD_FOR_FUZZING=ON",
-        "-DWERROR=ON",
-    ],
+CI_PRESETS = {
+    "standard": "vs2022-ci-standard",
+    "fuzz": "vs2022-ci-fuzz",
 }
 
 
@@ -48,11 +36,10 @@ def generate(ci_type):
         "cmake",
         "-B",
         "build",
-        "-Werror=dev",
         "--preset",
-        "vs2022",
+        CI_PRESETS[ci_type],
         f"-DCMAKE_TOOLCHAIN_FILE={toolchain_file}",
-    ] + GENERATE_OPTIONS[ci_type]
+    ]
     run(command)
 
 
@@ -72,7 +59,7 @@ def build():
 
 def main():
     parser = argparse.ArgumentParser(description="Utility to run Windows CI steps.")
-    parser.add_argument("ci_type", choices=GENERATE_OPTIONS, help="CI type to run.")
+    parser.add_argument("ci_type", choices=CI_PRESETS, help="CI type to run.")
     steps = ["generate", "build"]
     parser.add_argument("step", choices=steps, help="CI step to perform.")
     args = parser.parse_args()
diff --git a/CMakePresets.json b/CMakePresets.json
index ae9d06dafa4..fa5b8b87b59 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -18,6 +18,30 @@
         "WITH_ZMQ": "ON"
       }
     },
+    {
+      "name": "vs2022-ci-standard",
+      "inherits": "vs2022",
+      "errors": {"dev": true},
+      "cacheVariables": {
+        "BUILD_BENCH": "ON",
+        "BUILD_KERNEL_LIB": "ON",
+        "BUILD_UTIL_CHAINSTATE": "ON",
+        "WERROR": "ON"
+      }
+    },
+    {
+      "name": "vs2022-ci-fuzz",
+      "inherits": "vs2022",
+      "errors": {"dev": true},
+      "cacheVariables": {
+        "VCPKG_MANIFEST_NO_DEFAULT_FEATURES": "ON",
+        "VCPKG_MANIFEST_FEATURES": "wallet",
+        "BUILD_GUI": "OFF",
+        "WITH_ZMQ": "OFF",
+        "BUILD_FOR_FUZZING": "ON",
+        "WERROR": "ON"
+      }
+    },
     {
       "name": "vs2022-static",
       "displayName": "Build using 'Visual Studio 17 2022' generator and 'x64-windows-static' triplet",
```

IMO this takes the same improvement to the codebase, but makes it much more re-usable outside of the CI.

Code after:
#!/usr/bin/env python3
# Copyright (c) The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

import argparse
import os
import shlex
import subprocess
import sys
from pathlib import Path


def run(cmd, **kwargs):
    print("+ " + shlex.join(cmd), flush=True)
    kwargs.setdefault("check", True)
    try:
        return subprocess.run(cmd, **kwargs)
    except Exception as e:
        sys.exit(str(e))


GENERATE_OPTIONS = {
    "standard": [
        "-DBUILD_BENCH=ON",
        "-DBUILD_KERNEL_LIB=ON",
        "-DBUILD_UTIL_CHAINSTATE=ON",
        "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
    ],
    "fuzz": [
        "-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON",
        "-DVCPKG_MANIFEST_FEATURES=wallet",
        "-DBUILD_GUI=OFF",
        "-DWITH_ZMQ=OFF",
        "-DBUILD_FOR_FUZZING=ON",
        "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
    ],
}


def generate(ci_type):
    command = [
        "cmake",
        "-B",
        "build",
        "-Werror=dev",
        "--preset",
        "vs2022",