hctbuild.cmd 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. if "%1"=="-dxc-cmake-extra-args" (
  154. set CMAKE_OPTS=%CMAKE_OPTS% %~2
  155. shift /1
  156. shift /1
  157. )
  158. if "%1"=="-dxc-cmake-begins-include" (
  159. set CMAKE_OPTS=%CMAKE_OPTS% -DDXC_CMAKE_BEGINS_INCLUDE=%2
  160. shift /1
  161. shift /1
  162. )
  163. if "%1"=="-dxc-cmake-ends-include" (
  164. set CMAKE_OPTS=%CMAKE_OPTS% -DDXC_CMAKE_ENDS_INCLUDE=%2
  165. shift /1
  166. shift /1
  167. )
  168. rem If only VS 2017 is available, pick that by default.
  169. if "%BUILD_VS_VER%"=="2015" (
  170. reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\vs\Servicing\14.0\devenv /v Install /reg:32 1>nul 2>nul
  171. if errorlevel 1 (
  172. echo Visual Studio 2015 not available, setting up build for Visual Studio 2017.
  173. set BUILD_GENERATOR=Visual Studio 15 2017
  174. set BUILD_VS_VER=2017
  175. )
  176. )
  177. rem Begin SPIRV change
  178. if "%1"=="-spirv" (
  179. echo SPIR-V codegen is enabled.
  180. set SPIRV=ON
  181. shift /1
  182. )
  183. if "%1"=="-spirvtest" (
  184. echo Building SPIR-V tests is enabled.
  185. set SPV_TEST=ON
  186. shift /1
  187. )
  188. rem End SPIRV change
  189. set BUILD_ARM_CROSSCOMPILING=0
  190. if /i "%BUILD_ARCH%"=="Win32" (
  191. if "%BUILD_VS_VER%"=="2019" (
  192. set VS2019ARCH=-AWin32
  193. )
  194. )
  195. if /i "%BUILD_ARCH%"=="x64" (
  196. set BUILD_GENERATOR=%BUILD_GENERATOR% %BUILD_ARCH:x64=Win64%
  197. if "%BUILD_VS_VER%"=="2019" (
  198. set BUILD_GENERATOR=%BUILD_GENERATOR%
  199. set VS2019ARCH=-Ax64
  200. )
  201. )
  202. if /i "%BUILD_ARCH%"=="arm" (
  203. set BUILD_GENERATOR_PLATFORM=ARM
  204. set BUILD_ARM_CROSSCOMPILING=1
  205. if "%BUILD_VS_VER%"=="2019" (
  206. set VS2019ARCH=-AARM
  207. )
  208. )
  209. if /i "%BUILD_ARCH%"=="arm64" (
  210. set BUILD_GENERATOR_PLATFORM=ARM64
  211. set BUILD_ARM_CROSSCOMPILING=1
  212. if "%BUILD_VS_VER%"=="2019" (
  213. set VS2019ARCH=-AARM64
  214. )
  215. )
  216. if "%1"=="-ninja" (
  217. set BUILD_GENERATOR=Ninja
  218. shift /1
  219. )
  220. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_OPTIONAL_PROJS_IN_DEFAULT:BOOL=%ALL_DEFS%
  221. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_ANALYZE:BOOL=%ANALYZE%
  222. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_OFFICIAL_BUILD:BOOL=%OFFICIAL%
  223. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_FIXED_VER:BOOL=%FIXED_VER%
  224. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_FIXED_VER:BOOL=%FIXED_VER% -DHLSL_FIXED_VERSION_LOCATION:STRING=%FIXED_LOC%
  225. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_BUILD_DXILCONV:BOOL=%DXILCONV%
  226. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_VENDOR:STRING=%VENDOR%
  227. set CMAKE_OPTS=%CMAKE_OPTS% -DENABLE_SPIRV_CODEGEN:BOOL=%SPIRV%
  228. set CMAKE_OPTS=%CMAKE_OPTS% -DSPIRV_BUILD_TESTS:BOOL=%SPV_TEST%
  229. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_ENABLE_ARCMT:BOOL=OFF
  230. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF
  231. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_INCLUDE_TESTS:BOOL=OFF -DLLVM_INCLUDE_TESTS:BOOL=OFF
  232. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_INCLUDE_TESTS:BOOL=ON
  233. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_TARGETS_TO_BUILD:STRING=None
  234. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_INCLUDE_DOCS:BOOL=OFF -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF
  235. set CMAKE_OPTS=%CMAKE_OPTS% -DLIBCLANG_BUILD_STATIC:BOOL=ON
  236. rem set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON
  237. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_OPTIMIZED_TABLEGEN:BOOL=OFF
  238. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_REQUIRES_EH:BOOL=ON
  239. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_APPEND_VC_REV:BOOL=ON
  240. rem Enable exception handling (which requires RTTI).
  241. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_RTTI:BOOL=ON
  242. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_EH:BOOL=ON
  243. rem Setup a specific, stable triple for HLSL.
  244. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_DEFAULT_TARGET_TRIPLE:STRING=dxil-ms-dx
  245. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_BUILD_EXAMPLES:BOOL=OFF
  246. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_REQUIRES_RTTI:BOOL=ON
  247. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_CL:BOOL=OFF
  248. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_SYSTEM_VERSION=10.0.14393.0
  249. set CMAKE_OPTS=%CMAKE_OPTS% -DDXC_BUILD_ARCH=%BUILD_ARCH%
  250. rem ARM cross-compile setup
  251. if %BUILD_ARM_CROSSCOMPILING% == 0 goto :after-cross-compile
  252. rem The ARM build needs to have access to x86 or x64 build of clang-tblgen and llvm-tblgen tools.
  253. call :verify-tblgen %BUILD_TBLGEN_PATH%
  254. if errorlevel 1 (
  255. echo Cannot find x86/x64 version clang-tblgen and llvm-tblgen tools.
  256. echo Please set BUILD_TBLGEN_PATH or use hctbuild -tblgen option to specify location of x86/x64 build of DXC.
  257. call :handlefail
  258. exit /b 1
  259. )
  260. echo TableGen path: %BUILD_TBLGEN_PATH%
  261. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_CROSSCOMPILING=True
  262. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_GENERATOR_PLATFORM=%BUILD_GENERATOR_PLATFORM%
  263. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_TABLEGEN=%BUILD_TBLGEN_PATH%\llvm-tblgen.exe
  264. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_TABLEGEN=%BUILD_TBLGEN_PATH%\clang-tblgen.exe
  265. echo Cross-compiling enabled.
  266. :after-cross-compile
  267. rem This parameter is used with vcvarsall to force use of 64-bit build tools
  268. rem instead of 32-bit tools that run out of memory.
  269. if /i "%BUILD_ARCH%"=="Win32" (
  270. set BUILD_TOOLS=amd64_x86
  271. ) else if /i "%BUILD_ARCH%"=="x64" (
  272. set BUILD_TOOLS=amd64
  273. ) else if /i "%BUILD_ARCH%"=="ARM" (
  274. set BUILD_TOOLS=amd64_arm
  275. ) else if /i "%BUILD_ARCH%"=="ARM64" (
  276. set BUILD_TOOLS=amd64_arm64
  277. )
  278. call :configandbuild %BUILD_CONFIG% %BUILD_ARCH% %HLSL_BLD_DIR% "%BUILD_GENERATOR%" "%VS2019ARCH%"
  279. if errorlevel 1 exit /b 1
  280. if "%BUILD_GENERATOR%"=="Ninja" (
  281. echo Success - files are available at %HLSL_BLD_DIR%\bin
  282. ) else (
  283. echo Success - files are available at %HLSL_BLD_DIR%\%BUILD_CONFIG%\bin
  284. )
  285. call :handlesuccess
  286. exit /b 0
  287. :showhelp
  288. echo Builds HLSL solutions and the product and test binaries for the current
  289. echo flavor and architecture.
  290. echo.
  291. 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]
  292. echo.
  293. echo -s creates the projects only, without building
  294. echo -b builds the existing project
  295. echo.
  296. echo -alldef adds optional projects to the default build
  297. echo -analyze adds /analyze option
  298. echo -official will generate official version for build
  299. echo -fv fixes the resource version for release (utils\version\version.inc)
  300. echo -fvloc <path> directory with the version.inc file
  301. echo -rel builds release rather than debug
  302. echo -dont-speak disables audible build confirmation
  303. echo -no-parallel disables parallel build
  304. echo -no-dxilconv disables build of DXBC to DXIL converter and tools
  305. echo.
  306. echo current BUILD_ARCH=%BUILD_ARCH%. Override with:
  307. echo -x86 targets an x86 build (aka. Win32)
  308. echo -x64 targets an x64 build (aka. Win64)
  309. echo -arm targets an ARM build
  310. echo -arm64 targets an ARM64 build
  311. echo.
  312. echo Generator:
  313. echo -ninja use Ninja as the generator
  314. echo.
  315. echo AppVeyor Support
  316. echo -Release builds release
  317. echo -Debug builds debug
  318. echo -vs2015 uses Visual Studio 2015 to build; ARM64 not supported
  319. echo.
  320. echo ARM build support
  321. echo -tblgen sets path to x86 or x64 versions of clang-tblgen and llvm-tblgen tools
  322. echo.
  323. if not "%HLSL_BLD_DIR%"=="" (
  324. echo The solution file is at %HLSL_BLD_DIR%\LLVM.sln
  325. echo.
  326. )
  327. goto :eof
  328. :configandbuild
  329. rem Configure and build a specific configuration, typically Debug or Release.
  330. rem %1 - the conf name
  331. rem %2 - the platform name
  332. rem %3 - the build directory
  333. rem %4 - the generator name
  334. rem %5 - the vs2019 architecture name
  335. if not exist %3 (
  336. mkdir %3
  337. if errorlevel 1 (
  338. echo Unable to create %3
  339. call :handlefail
  340. exit /b 1
  341. )
  342. )
  343. cd /d %3
  344. if "%DO_SETUP%"=="1" (
  345. echo Creating solution files for %2, logging to %3\cmake-log.txt
  346. if "%BUILD_GENERATOR%"=="Ninja" (
  347. echo Running cmake -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% > %3\cmake-log.txt
  348. cmake -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  349. ) else (
  350. rem -DCMAKE_BUILD_TYPE:STRING=%1 is not necessary for multi-config generators like VS
  351. echo Running cmake %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% > %3\cmake-log.txt
  352. cmake %CMAKE_OPTS% -G %4 %5 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  353. )
  354. if errorlevel 1 (
  355. echo Failed to configure cmake projects.
  356. echo ===== begin cmake-log.txt =====
  357. type %3\cmake-log.txt
  358. echo ===== end cmake-log.txt =====
  359. echo Run 'cmake %HLSL_SRC_DIR%' in %3 will continue project generation after fixing the issue.
  360. cmake --version | findstr 3.4
  361. if errorlevel 1 (
  362. echo CMake 3.4 is the currently supported version - your installed cmake may be out of date.
  363. echo See README.md at the root for an explanation of dependencies.
  364. )
  365. findstr -c:"Could NOT find D3D12" %3\cmake-log.txt >NUL
  366. if errorlevel 1 (
  367. rem D3D12 has been found, nothing to diagnose here.
  368. ) else (
  369. echo D3D12 has not been found. Confirm that you have installed the Windows 10 SDK.
  370. echo See README.md at the root for an explanation of dependencies.
  371. echo Run hctclean after installing the SDK to completely rebuild the projects.
  372. )
  373. call :handlefail
  374. exit /b 1
  375. )
  376. )
  377. if "%DO_BUILD%" neq "1" (
  378. exit /b 0
  379. )
  380. rem Should add support for the non-x86-qualified programfiles.
  381. echo Building solution files for %2 with %1 configuration.
  382. if "%BUILD_GENERATOR%" NEQ "Ninja" (
  383. if "%BUILD_VS_VER%"=="2015" (
  384. if exist "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" (
  385. call :buildvs_x86dir %1 %2 %3
  386. goto :donebuild
  387. )
  388. )
  389. )
  390. rem Just defer to cmake for now.
  391. cmake --build . --config %1 -- %PARALLEL_OPT%
  392. goto :donebuild
  393. :donebuild
  394. if errorlevel 1 (
  395. echo Failed to build projects.
  396. echo After fixing, run 'cmake --build --config %1 .' in %2
  397. call :handlefail
  398. exit /b 1
  399. )
  400. endlocal
  401. exit /b 0
  402. :buildvs_x86dir
  403. rem Build with the VS tools in the x86 program files directory, maxcpucount makes this goes much faster.
  404. rem 1 - config
  405. rem 2 - platform
  406. rem 3 - build directory
  407. setlocal
  408. call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %BUILD_TOOLS%
  409. rem Add /ds for a detailed summary at the end.
  410. echo Logging to %3\msbuild-log.txt
  411. MSBuild.exe /nologo /property:Configuration=%1 /property:Platform=%2 /maxcpucount:2 %3\LLVM.sln /consoleloggerparameters:Summary;Verbosity=minimal /fileloggerparameters:LogFile=%3\msbuild-log.txt
  412. if NOT "%ERRORLEVEL%"=="0" (
  413. exit /b 1
  414. )
  415. endlocal
  416. exit /b 0
  417. :verify-tblgen
  418. if exist %1\clang-tblgen.exe (
  419. if exist %1\llvm-tblgen.exe exit /b 0
  420. )
  421. exit /b 1
  422. :handlefail
  423. if %SPEAK%==1 (
  424. cscript.exe //Nologo %HLSL_SRC_DIR%\utils\hct\hctspeak.js /say:"build failed"
  425. )
  426. exit /b 0
  427. :handlesuccess
  428. if %SPEAK%==1 (
  429. cscript.exe //Nologo %HLSL_SRC_DIR%\utils\hct\hctspeak.js /say:"build succeeded"
  430. )
  431. exit /b 0