hctbuild.cmd 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. @echo off
  2. if "%1"=="/?" goto :showhelp
  3. if "%1"=="-?" goto :showhelp
  4. if "%1"=="-help" goto :showhelp
  5. if "%1"=="--help" goto :showhelp
  6. setlocal
  7. if "%HLSL_SRC_DIR%"=="" (
  8. echo Missing source directory.
  9. if exist %~dp0..\..\LLVMBuild.txt (
  10. set HLSL_SRC_DIR=%~dp0..\..
  11. echo Source directory deduced to be %~dp0..\..
  12. ) else (
  13. exit /b 1
  14. )
  15. )
  16. if "%1"=="/buildoutdir" (
  17. echo Build output directory set to %2
  18. set HLSL_BLD_DIR=%2
  19. shift /1
  20. shift /1
  21. )
  22. if "%HLSL_BLD_DIR%"=="" (
  23. echo Missing build directory.
  24. exit /b 1
  25. )
  26. where cmake.exe 1>nul 2>nul
  27. if errorlevel 1 (
  28. echo Unable to find cmake.exe on the path.
  29. echo cmake 3.4 is available from https://cmake.org/files/v3.4/cmake-3.4.0-win32-x86.exe
  30. exit /b 1
  31. )
  32. if "%BUILD_ARCH%"=="" (
  33. set BUILD_ARCH=Win32
  34. )
  35. set BUILD_GENERATOR=Visual Studio 15 2017
  36. set BUILD_VS_VER=2017
  37. set BUILD_CONFIG=Debug
  38. set DO_SETUP=1
  39. set DO_BUILD=1
  40. set CMAKE_OPTS=
  41. set SPEAK=1
  42. set PARALLEL_OPT=/m
  43. set ALL_DEFS=OFF
  44. set ANALYZE=OFF
  45. set OFFICIAL=OFF
  46. set FIXED_VER=OFF
  47. set FIXED_LOC=
  48. set VENDOR=
  49. set SPIRV=OFF
  50. set SPV_TEST=OFF
  51. set DXILCONV=ON
  52. if "%1"=="-s" (
  53. set DO_BUILD=0
  54. shift /1
  55. )
  56. if "%1"=="-b" (
  57. set DO_SETUP=0
  58. shift /1
  59. )
  60. if "%1"=="-alldef" (
  61. set ALL_DEFS=ON
  62. shift /1
  63. )
  64. if "%1"=="-analyze" (
  65. set ANALYZE=ON
  66. shift /1
  67. )
  68. if "%1"=="-official" (
  69. echo Will generate official version for build
  70. set OFFICIAL=ON
  71. shift /1
  72. )
  73. if "%1"=="-fv" (
  74. echo Fixed version flag set for build.
  75. set FIXED_VER=ON
  76. shift /1
  77. )
  78. if "%1"=="-fvloc" (
  79. echo Fixed version flag set for build, version file location: %2
  80. set FIXED_VER=ON
  81. set FIXED_LOC=%2
  82. shift /1
  83. shift /1
  84. )
  85. if "%1"=="-cv" (
  86. echo Set the CLANG_VENDOR value.
  87. set VENDOR=%2
  88. shift /1
  89. shift /1
  90. )
  91. if "%1"=="-rel" (
  92. set BUILD_CONFIG=Release
  93. shift /1
  94. )
  95. if "%1"=="-x86" (
  96. set BUILD_ARCH=Win32
  97. shift /1
  98. )
  99. if "%1"=="-x64" (
  100. set BUILD_ARCH=x64
  101. shift /1
  102. )
  103. if /i "%1"=="-arm" (
  104. set BUILD_ARCH=ARM
  105. shift /1
  106. )
  107. if /i "%1"=="-arm64" (
  108. set BUILD_ARCH=ARM64
  109. shift /1
  110. )
  111. if "%1"=="-Debug" (
  112. set BUILD_CONFIG=Debug
  113. shift /1
  114. )
  115. if "%1"=="-Release" (
  116. set BUILD_CONFIG=Release
  117. shift /1
  118. )
  119. if "%1"=="-vs2017" (
  120. shift /1
  121. )
  122. if "%1"=="-vs2015" (
  123. set BUILD_GENERATOR=Visual Studio 14 2015
  124. set BUILD_VS_VER=2015
  125. shift /1
  126. )
  127. if "%1"=="-vs2019" (
  128. set BUILD_GENERATOR=Visual Studio 16 2019
  129. set BUILD_VS_VER=2019
  130. shift /1
  131. )
  132. if "%1"=="-tblgen" (
  133. if "%2" == "" (
  134. echo Missing path argument after -tblgen.
  135. exit /b
  136. )
  137. set BUILD_TBLGEN_PATH=%2
  138. shift /1
  139. shift /1
  140. )
  141. if "%1"=="-dont-speak" (
  142. set SPEAK=0
  143. shift /1
  144. )
  145. if "%1"=="-no-parallel" (
  146. set PARALLEL_OPT=
  147. shift /1
  148. )
  149. if "%1"=="-no-dxilconv" (
  150. set DXILCONV=OFF
  151. shift /1
  152. )
  153. rem If only VS 2017 is available, pick that by default.
  154. if "%BUILD_VS_VER%"=="2015" (
  155. reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\vs\Servicing\14.0\devenv /v Install /reg:32 1>nul 2>nul
  156. if errorlevel 1 (
  157. echo Visual Studio 2015 not available, setting up build for Visual Studio 2017.
  158. set BUILD_GENERATOR=Visual Studio 15 2017
  159. set BUILD_VS_VER=2017
  160. )
  161. )
  162. rem Begin SPIRV change
  163. if "%1"=="-spirv" (
  164. echo SPIR-V codegen is enabled.
  165. set SPIRV=ON
  166. shift /1
  167. )
  168. if "%1"=="-spirvtest" (
  169. echo Building SPIR-V tests is enabled.
  170. set SPV_TEST=ON
  171. shift /1
  172. )
  173. rem End SPIRV change
  174. set BUILD_ARM_CROSSCOMPILING=0
  175. if /i "%BUILD_ARCH%"=="x64" (
  176. set BUILD_GENERATOR=%BUILD_GENERATOR% %BUILD_ARCH:x64=Win64%
  177. if "%BUILD_VS_VER%"=="2019" (
  178. set BUILD_GENERATOR=%BUILD_GENERATOR%
  179. set VS2019ARCH=-Ax64
  180. )
  181. )
  182. if /i "%BUILD_ARCH%"=="arm" (
  183. set BUILD_GENERATOR_PLATFORM=ARM
  184. set BUILD_ARM_CROSSCOMPILING=1
  185. )
  186. if /i "%BUILD_ARCH%"=="arm64" (
  187. set BUILD_GENERATOR_PLATFORM=ARM64
  188. set BUILD_ARM_CROSSCOMPILING=1
  189. )
  190. if "%1"=="-ninja" (
  191. set BUILD_GENERATOR=Ninja
  192. shift /1
  193. )
  194. set CMAKE_OPTS=-DHLSL_OPTIONAL_PROJS_IN_DEFAULT:BOOL=%ALL_DEFS%
  195. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_ANALYZE:BOOL=%ANALYZE%
  196. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_OFFICIAL_BUILD:BOOL=%OFFICIAL%
  197. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_FIXED_VER:BOOL=%FIXED_VER%
  198. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_FIXED_VER:BOOL=%FIXED_VER% -DHLSL_FIXED_VERSION_LOCATION:STRING=%FIXED_LOC%
  199. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_BUILD_DXILCONV:BOOL=%DXILCONV%
  200. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_VENDOR:STRING=%VENDOR%
  201. set CMAKE_OPTS=%CMAKE_OPTS% -DENABLE_SPIRV_CODEGEN:BOOL=%SPIRV%
  202. set CMAKE_OPTS=%CMAKE_OPTS% -DSPIRV_BUILD_TESTS:BOOL=%SPV_TEST%
  203. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_ENABLE_ARCMT:BOOL=OFF
  204. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF
  205. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_INCLUDE_TESTS:BOOL=OFF -DLLVM_INCLUDE_TESTS:BOOL=OFF
  206. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_INCLUDE_TESTS:BOOL=ON
  207. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_TARGETS_TO_BUILD:STRING=None
  208. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_INCLUDE_DOCS:BOOL=OFF -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF
  209. set CMAKE_OPTS=%CMAKE_OPTS% -DLIBCLANG_BUILD_STATIC:BOOL=ON
  210. rem set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON
  211. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_OPTIMIZED_TABLEGEN:BOOL=OFF
  212. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_REQUIRES_EH:BOOL=ON
  213. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_APPEND_VC_REV:BOOL=ON
  214. rem Enable exception handling (which requires RTTI).
  215. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_RTTI:BOOL=ON
  216. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_EH:BOOL=ON
  217. rem Setup a specific, stable triple for HLSL.
  218. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_DEFAULT_TARGET_TRIPLE:STRING=dxil-ms-dx
  219. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_BUILD_EXAMPLES:BOOL=OFF
  220. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_REQUIRES_RTTI:BOOL=ON
  221. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_CL:BOOL=OFF
  222. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_SYSTEM_VERSION=10.0.14393.0
  223. set CMAKE_OPTS=%CMAKE_OPTS% -DDXC_BUILD_ARCH=%BUILD_ARCH%
  224. rem ARM cross-compile setup
  225. if %BUILD_ARM_CROSSCOMPILING% == 0 goto :after-cross-compile
  226. rem The ARM build needs to have access to x86 or x64 build of clang-tblgen and llvm-tblgen tools.
  227. call :verify-tblgen %BUILD_TBLGEN_PATH%
  228. if errorlevel 1 (
  229. echo Cannot find x86/x64 version clang-tblgen and llvm-tblgen tools.
  230. echo Please set BUILD_TBLGEN_PATH or use hctbuild -tblgen option to specify location of x86/x64 build of DXC.
  231. call :handlefail
  232. exit /b 1
  233. )
  234. echo TableGen path: %BUILD_TBLGEN_PATH%
  235. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_CROSSCOMPILING=True
  236. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_GENERATOR_PLATFORM=%BUILD_GENERATOR_PLATFORM%
  237. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_TABLEGEN=%BUILD_TBLGEN_PATH%\llvm-tblgen.exe
  238. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_TABLEGEN=%BUILD_TBLGEN_PATH%\clang-tblgen.exe
  239. echo Cross-compiling enabled.
  240. :after-cross-compile
  241. rem This parameter is used with vcvarsall to force use of 64-bit build tools
  242. rem instead of 32-bit tools that run out of memory.
  243. if /i "%BUILD_ARCH%"=="Win32" (
  244. set BUILD_TOOLS=amd64_x86
  245. ) else if /i "%BUILD_ARCH%"=="x64" (
  246. set BUILD_TOOLS=amd64
  247. ) else if /i "%BUILD_ARCH%"=="ARM" (
  248. set BUILD_TOOLS=amd64_arm
  249. ) else if /i "%BUILD_ARCH%"=="ARM64" (
  250. set BUILD_TOOLS=amd64_arm64
  251. )
  252. call :configandbuild %BUILD_CONFIG% %BUILD_ARCH% %HLSL_BLD_DIR% "%BUILD_GENERATOR%" "%VS2019ARCH%"
  253. if errorlevel 1 exit /b 1
  254. if "%BUILD_GENERATOR%"=="Ninja" (
  255. echo Success - files are available at %HLSL_BLD_DIR%\bin
  256. ) else (
  257. echo Success - files are available at %HLSL_BLD_DIR%\%BUILD_CONFIG%\bin
  258. )
  259. call :handlesuccess
  260. exit /b 0
  261. :showhelp
  262. echo Builds HLSL solutions and the product and test binaries for the current
  263. echo flavor and architecture.
  264. echo.
  265. echo hctbuild [-s or -b] [-alldef] [-analyze] [-official] [-fv] [-fvloc <path>] [-rel] [-arm or -arm64 or -x86 or -x64] [-Release] [-Debug] [-vs2015] [-ninja] [-tblgen path] [-dont-speak] [-no-parallel] [-no-dxilconv]
  266. echo.
  267. echo -s creates the projects only, without building
  268. echo -b builds the existing project
  269. echo.
  270. echo -alldef adds optional projects to the default build
  271. echo -analyze adds /analyze option
  272. echo -official will generate official version for build
  273. echo -fv fixes the resource version for release (utils\version\version.inc)
  274. echo -fvloc <path> directory with the version.inc file
  275. echo -rel builds release rather than debug
  276. echo -dont-speak disables audible build confirmation
  277. echo -no-parallel disables parallel build
  278. echo -no-dxilconv disables build of DXBC to DXIL converter and tools
  279. echo.
  280. echo current BUILD_ARCH=%BUILD_ARCH%. Override with:
  281. echo -x86 targets an x86 build (aka. Win32)
  282. echo -x64 targets an x64 build (aka. Win64)
  283. echo -arm targets an ARM build
  284. echo -arm64 targets an ARM64 build
  285. echo.
  286. echo Generator:
  287. echo -ninja use Ninja as the generator
  288. echo.
  289. echo AppVeyor Support
  290. echo -Release builds release
  291. echo -Debug builds debug
  292. echo -vs2015 uses Visual Studio 2015 to build; ARM64 not supported
  293. echo.
  294. echo ARM build support
  295. echo -tblgen sets path to x86 or x64 versions of clang-tblgen and llvm-tblgen tools
  296. echo.
  297. if not "%HLSL_BLD_DIR%"=="" (
  298. echo The solution file is at %HLSL_BLD_DIR%\LLVM.sln
  299. echo.
  300. )
  301. goto :eof
  302. :configandbuild
  303. rem Configure and build a specific configuration, typically Debug or Release.
  304. rem %1 - the conf name
  305. rem %2 - the platform name
  306. rem %3 - the build directory
  307. rem %4 - the generator name
  308. if not exist %3 (
  309. mkdir %3
  310. if errorlevel 1 (
  311. echo Unable to create %3
  312. call :handlefail
  313. exit /b 1
  314. )
  315. )
  316. cd /d %3
  317. if "%DO_SETUP%"=="1" (
  318. echo Creating solution files for %2, logging to %3\cmake-log.txt
  319. if "%BUILD_GENERATOR%"=="Ninja" (
  320. echo Running cmake -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% > %3\cmake-log.txt
  321. cmake -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  322. ) else (
  323. rem -DCMAKE_BUILD_TYPE:STRING=%1 is not necessary for multi-config generators like VS
  324. if "%BUILD_VS_VER%"=="2019" (
  325. echo Running cmake %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% > %3\cmake-log.txt
  326. cmake %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  327. ) else (
  328. echo Running cmake %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% > %3\cmake-log.txt
  329. cmake %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  330. )
  331. )
  332. if errorlevel 1 (
  333. echo Failed to configure cmake projects.
  334. echo ===== begin cmake-log.txt =====
  335. type %3\cmake-log.txt
  336. echo ===== end cmake-log.txt =====
  337. echo Run 'cmake %HLSL_SRC_DIR%' in %3 will continue project generation after fixing the issue.
  338. cmake --version | findstr 3.4
  339. if errorlevel 1 (
  340. echo CMake 3.4 is the currently supported version - your installed cmake may be out of date.
  341. echo See README.md at the root for an explanation of dependencies.
  342. )
  343. findstr -c:"Could NOT find D3D12" %3\cmake-log.txt >NUL
  344. if errorlevel 1 (
  345. rem D3D12 has been found, nothing to diagnose here.
  346. ) else (
  347. echo D3D12 has not been found. Confirm that you have installed the Windows 10 SDK.
  348. echo See README.md at the root for an explanation of dependencies.
  349. echo Run hctclean after installing the SDK to completely rebuild the projects.
  350. )
  351. call :handlefail
  352. exit /b 1
  353. )
  354. )
  355. if "%DO_BUILD%" neq "1" (
  356. exit /b 0
  357. )
  358. rem Should add support for the non-x86-qualified programfiles.
  359. echo Building solution files for %2 with %1 configuration.
  360. if "%BUILD_GENERATOR%" NEQ "Ninja" (
  361. if "%BUILD_VS_VER%"=="2015" (
  362. if exist "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" (
  363. call :buildvs_x86dir %1 %2 %3
  364. goto :donebuild
  365. )
  366. )
  367. )
  368. rem Just defer to cmake for now.
  369. cmake --build . --config %1 -- %PARALLEL_OPT%
  370. goto :donebuild
  371. :donebuild
  372. if errorlevel 1 (
  373. echo Failed to build projects.
  374. echo After fixing, run 'cmake --build --config %1 .' in %2
  375. call :handlefail
  376. exit /b 1
  377. )
  378. endlocal
  379. exit /b 0
  380. :buildvs_x86dir
  381. rem Build with the VS tools in the x86 program files directory, maxcpucount makes this goes much faster.
  382. rem 1 - config
  383. rem 2 - platform
  384. rem 3 - build directory
  385. setlocal
  386. call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %BUILD_TOOLS%
  387. rem Add /ds for a detailed summary at the end.
  388. echo Logging to %3\msbuild-log.txt
  389. MSBuild.exe /nologo /property:Configuration=%1 /property:Platform=%2 /maxcpucount:2 %3\LLVM.sln /consoleloggerparameters:Summary;Verbosity=minimal /fileloggerparameters:LogFile=%3\msbuild-log.txt
  390. if NOT "%ERRORLEVEL%"=="0" (
  391. exit /b 1
  392. )
  393. endlocal
  394. exit /b 0
  395. :verify-tblgen
  396. if exist %1\clang-tblgen.exe (
  397. if exist %1\llvm-tblgen.exe exit /b 0
  398. )
  399. exit /b 1
  400. :handlefail
  401. if %SPEAK%==1 (
  402. cscript.exe //Nologo %HLSL_SRC_DIR%\utils\hct\hctspeak.js /say:"build failed"
  403. )
  404. exit /b 0
  405. :handlesuccess
  406. if %SPEAK%==1 (
  407. cscript.exe //Nologo %HLSL_SRC_DIR%\utils\hct\hctspeak.js /say:"build succeeded"
  408. )
  409. exit /b 0