From 3107ee56f0db90c2df49bad36230e981aac7dfc5 Mon Sep 17 00:00:00 2001 From: Jan Kraemer Date: Wed, 12 Aug 2026 10:23:33 +0200 Subject: [PATCH 1/2] ci: replace msvc-dev-cmd with a python script In order to minimize 3rd party dependencies we replaced the msvc-dev-cmd action with a python script. Signed-off-by: Jan Kraemer --- .github/workflows/build-win.yml | 13 +++--- SilKit/ci/setup_msvc_env.py | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 SilKit/ci/setup_msvc_env.py diff --git a/.github/workflows/build-win.yml b/.github/workflows/build-win.yml index b4c0dc6d8..497fde56c 100644 --- a/.github/workflows/build-win.yml +++ b/.github/workflows/build-win.yml @@ -43,10 +43,8 @@ jobs: shell: powershell - name: Prepare build env on Windows - uses: ilammy/msvc-dev-cmd@v1.12.0 - with: - arch: x64 - toolset: 14.20 + run: | + python3 -u ./SilKit/ci/setup_msvc_env.py --arch x64 --hostarch x64 --vcvars_ver 14.2 - uses: ./.github/actions/build-cmake-preset with: @@ -78,10 +76,9 @@ jobs: shell: powershell - name: Prepare build env on Windows - uses: ilammy/msvc-dev-cmd@v1.12.0 - with: - arch: x86 - toolset: 14.20 + run: | + python3 -u ./SilKit/ci/setup_msvc_env.py --arch x86 --hostarch x64 --vcvars_ver 14.2 + - uses: ./.github/actions/build-cmake-preset with: diff --git a/SilKit/ci/setup_msvc_env.py b/SilKit/ci/setup_msvc_env.py new file mode 100644 index 000000000..9828f3c66 --- /dev/null +++ b/SilKit/ci/setup_msvc_env.py @@ -0,0 +1,75 @@ +#! /bin/env python3 + +# SPDX-FileCopyrightText: 2025 Vector Informatik GmbH +# +# SPDX-License-Identifier: MIT + +import subprocess +import json +import logging +import os +import argparse + +logger = logging.getLogger(__name__) +handler = logging.StreamHandler() +logger.addHandler(handler) +logger.setLevel(logging.DEBUG) + +from pathlib import Path + +def find_VsDevCmd() -> str: + + some_out = subprocess.run( + ["vswhere", "-latest", "-property", "InstallationPath"], + capture_output=True, encoding="utf-8", check=True) + + print(some_out.stdout) + + + return Path(some_out.stdout.rstrip()) / r'Common7\Tools\VsDevCmd.bat' + +def main(): + + parser = argparse.ArgumentParser(prog="Microsoft Dev Env Creator", + description="Setup the development environment under Windows") + parser.add_argument('--arch', type=str, default='x64', + help='The architecture for which to build the binary for') + parser.add_argument('--hostarch', type=str, default='x64', + help='The architecture of the host build machine') + parser.add_argument('--vcvars_ver', type=str, default='14.2', + help='The version of the toolset to be used') + args = parser.parse_args() + + vs_path = find_VsDevCmd() + + vsdevcmd = f'"{vsdevcmd_path}" -arch={args.arch} -host_arch={args.hostarch} -vcvars_ver={args.vcvars_ver}' + + logger.debug(f"Executing cmd:\n{vsdevcmd}") + + osenvcmd = '( python -c "import os, json; print(json.dumps(dict(os.environ)))" )' + print(f"Found at: {vsdevcmd_path}") + vsdevcmd_proc = subprocess.run( + executable=r'C:\Windows\System32\cmd.exe', + args=f'/S /C "( ( {vsdevcmd} >NUL 2>&1 ) && {osenvcmd} ) & exit"', + capture_output=True, encoding="utf-8", check=False) + + new_env = vsdevcmd_proc.stdout + logger.debug(f"New Env:\n{new_env}") + logger.debug(f"Old Env: \n{json.dumps(dict(os.environ), indent=2)}") + if not new_env: + logger.error("Could not acquire a new shell env!") + exit(1) + + environment = json.loads(vsdevcmd_proc.stdout) + + with open(os.environ['GITHUB_ENV'], 'a') as f: + for k, v in environment.items(): + logger.debug(f"updating environment variable {k!r} = {v!r}") + + if not v.startswith(('GITHUB_', 'RUNNER_', 'CI')): + f.write(f"{k}={v}\n") + + + +if __name__ == "__main__": + main() From 38ede59216aff6723afeb5b1380748a9b64111ad Mon Sep 17 00:00:00 2001 From: Jan Kraemer Date: Thu, 20 Aug 2026 15:57:07 +0200 Subject: [PATCH 2/2] fixup! ci: replace msvc-dev-cmd with a python script --- SilKit/ci/setup_msvc_env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SilKit/ci/setup_msvc_env.py b/SilKit/ci/setup_msvc_env.py index 9828f3c66..00e87009f 100644 --- a/SilKit/ci/setup_msvc_env.py +++ b/SilKit/ci/setup_msvc_env.py @@ -40,7 +40,7 @@ def main(): help='The version of the toolset to be used') args = parser.parse_args() - vs_path = find_VsDevCmd() + vsdevcmd_path = find_VsDevCmd() vsdevcmd = f'"{vsdevcmd_path}" -arch={args.arch} -host_arch={args.hostarch} -vcvars_ver={args.vcvars_ver}'