OpenCL build.bat: library detection without parentheses in blocks (Program Files (x86) broke the parser)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
igneum-labs 2026-10-03 17:04:39 +00:00
parent a63ab440c4
commit 36447d1bef

View file

@ -8,7 +8,7 @@ rem OCL_ROOT the old AMD APP SDK layout: %OCL_ROOT%\include and %OCL_ROO
rem The runtime itself (OpenCL.dll in System32 plus the vendor ICD) comes with the AMD Adrenalin driver; no SDK needed to run.
rem Usage: build.bat [pack]
rem pack directory name under ..\proto-cuda\packs\ (default igneum-genesis-mh)
setlocal enabledelayedexpansion
setlocal
cd /d "%~dp0"
set PACK=%1
@ -50,23 +50,29 @@ if "%LIB%"=="" (
echo using headers %INC% and import library %LIB%
rem Find the MSVC runtime libraries and the Windows SDK libraries ourselves, in case the prompt did not set LIB
rem (seen on a Visual Studio 2026 install where vcvarsall reported success but linking could not find LIBCMT.lib).
set EXTRALIB=
set MSVCLIB=
for /f "delims=" %%D in ('dir /b /ad /o-n "%VCINSTALLDIR%Tools\MSVC" 2^>nul') do (
if "!MSVCLIB!"=="" if exist "%VCINSTALLDIR%Tools\MSVC\%%D\lib\x64\libcmt.lib" set MSVCLIB=%VCINSTALLDIR%Tools\MSVC\%%D\lib\x64
)
if "%MSVCLIB%"=="" for /f "delims=" %%D in ('dir /b /ad /o-n "C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC" 2^>nul') do (
if "!MSVCLIB!"=="" if exist "C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\%%D\lib\x64\libcmt.lib" set MSVCLIB=C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\%%D\lib\x64
)
set SDKLIB=
for /f "delims=" %%D in ('dir /b /ad /o-n "C:\Program Files (x86)\Windows Kits\10\Lib" 2^>nul') do (
if "!SDKLIB!"=="" if exist "C:\Program Files (x86)\Windows Kits\10\Lib\%%D\ucrt\x64\libucrt.lib" set SDKLIB=C:\Program Files (x86)\Windows Kits\10\Lib\%%D
)
if not "%MSVCLIB%"=="" set EXTRALIB=%EXTRALIB% /LIBPATH:"%MSVCLIB%"
if not "%SDKLIB%"=="" set EXTRALIB=%EXTRALIB% /LIBPATH:"%SDKLIB%\ucrt\x64" /LIBPATH:"%SDKLIB%\um\x64"
if "%MSVCLIB%"=="" echo warning: could not find libcmt.lib under any MSVC toolset; install "Desktop development with C++" in the Visual Studio Installer.
if "%SDKLIB%"=="" echo warning: could not find the Windows 10/11 SDK libraries under C:\Program Files ^(x86^)\Windows Kits\10\Lib.
echo libraries: MSVC=%MSVCLIB% SDK=%SDKLIB%
set "EXTRALIB="
set "MSVCLIB="
set "SDKLIB="
set "VSVC=%VCINSTALLDIR%"
if "%VSVC%"=="" set "VSVC=C:\Program Files\Microsoft Visual Studio\18\Community\VC\"
set "KITS=C:\Program Files (x86)\Windows Kits\10\Lib"
for /f "delims=" %%D in ('dir /b /ad /o-n "%VSVC%Tools\MSVC" 2^>nul') do call :msvc "%%D"
for /f "delims=" %%D in ('dir /b /ad /o-n "%KITS%" 2^>nul') do call :sdk "%%D"
goto :found
:msvc
if not "%MSVCLIB%"=="" goto :eof
if exist "%VSVC%Tools\MSVC\%~1\lib\x64\libcmt.lib" set "MSVCLIB=%VSVC%Tools\MSVC\%~1\lib\x64"
goto :eof
:sdk
if not "%SDKLIB%"=="" goto :eof
if exist "%KITS%\%~1\ucrt\x64\libucrt.lib" set "SDKLIB=%KITS%\%~1"
goto :eof
:found
if not "%MSVCLIB%"=="" set "EXTRALIB=/LIBPATH:"%MSVCLIB%""
if not "%SDKLIB%"=="" set "EXTRALIB=%EXTRALIB% /LIBPATH:"%SDKLIB%\ucrt\x64" /LIBPATH:"%SDKLIB%\um\x64""
if "%MSVCLIB%"=="" echo warning: no libcmt.lib under any MSVC toolset. Install "Desktop development with C++" in the Visual Studio Installer.
if "%SDKLIB%"=="" echo warning: no Windows SDK libraries under "%KITS%".
echo libraries: MSVC="%MSVCLIB%" SDK="%SDKLIB%"
echo cl /nologo /O2 /W3 /std:c11 /I "%INC%" /I "%PACKDIR%" /DIGNEUM_KERNEL_PATH="\"%PACKDIR:\=/%/kernel.cl\"" /Fe:igneum-bench-cl-%PACK%.exe host.c /link "%LIB%" %EXTRALIB%
cl /nologo /O2 /W3 /std:c11 /I "%INC%" /I "%PACKDIR%" /DIGNEUM_KERNEL_PATH="\"%PACKDIR:\=/%/kernel.cl\"" /Fe:igneum-bench-cl-%PACK%.exe host.c /link "%LIB%" %EXTRALIB%
if errorlevel 1 (