#!/usr/bin/env python3 """Build the served kstar.c UNMODIFIED with the shipped Win32 pthread shim, then the witness tool. python build.py # -> shim/pthread.h from pthread-shim.h, then kstar.exe, witness4288.exe Adjust VS_ROOT if the Build Tools live elsewhere; POSIX users can instead run the served file as shipped: cc -O2 -o kstar kstar.c -lpthread (the shim is only needed for MSVC, which has pthreads neither in its CRT nor in the Windows SDK). """ import os import shutil import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) VS_ROOT = r"C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" def main() -> int: shim = os.path.join(HERE, "shim") os.makedirs(shim, exist_ok=True) shutil.copyfile(os.path.join(HERE, "pthread-shim.h"), os.path.join(shim, "pthread.h")) vcvars = os.path.join(VS_ROOT, "VC", "Auxiliary", "Build", "vcvars64.bat") if not os.path.isfile(vcvars): print("vcvars64.bat not found at %s -- edit VS_ROOT" % vcvars) return 2 flags = "/nologo /O2 /std:c11 /W3 /I shim" cmds = ['cl %s kstar.c /Fe:kstar.exe' % flags, 'cl %s witness4288.c /Fe:witness4288.exe' % flags] cmd = 'call "%s" >nul && %s' % (vcvars, " && ".join(cmds)) rc = subprocess.call(["cmd", "/c", cmd], cwd=HERE) print("build exit", rc) return rc if __name__ == "__main__": sys.exit(main())