hctbuild.cmd 11 KB

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