hctbuild.cmd 14 KB

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