hctbuild.cmd 13 KB

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