build.bat 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. @echo OFF
  2. setlocal enabledelayedexpansion
  3. set "FullScriptPath=%~dp0"
  4. set "FullExecPath=%cd%"
  5. if not exist "%FullScriptPath%..\..\..\DesktopPrivate" (
  6. echo.
  7. echo This script is for building the production version of Telegram Desktop.
  8. echo.
  9. echo For building custom versions please visit the build instructions page at:
  10. echo https://github.com/telegramdesktop/tdesktop/#build-instructions
  11. exit /b
  12. )
  13. FOR /F "tokens=1* delims= " %%i in (%FullScriptPath%target) do set "BuildTarget=%%i"
  14. set "Build64=0"
  15. set "BuildARM=0"
  16. set "BuildUWP=0"
  17. if "%BuildTarget%" equ "win64" (
  18. set "Build64=1"
  19. ) else if "%BuildTarget%" equ "winarm" (
  20. set "BuildARM=1"
  21. ) else if "%BuildTarget%" equ "uwp" (
  22. set "BuildUWP=1"
  23. ) else if "%BuildTarget%" equ "uwp64" (
  24. set "Build64=1"
  25. set "BuildUWP=1"
  26. ) else if "%BuildTarget%" equ "uwparm" (
  27. set "BuildARM=1"
  28. set "BuildUWP=1"
  29. )
  30. if %Build64% neq 0 (
  31. if "%Platform%" neq "x64" (
  32. echo Bad environment. Make sure to run from 'x64 Native Tools Command Prompt for VS 2022'.
  33. exit /b
  34. ) else if "%VSCMD_ARG_HOST_ARCH%" neq "x64" (
  35. echo Bad environment. Make sure to run from 'x64 Native Tools Command Prompt for VS 2022'.
  36. exit /b
  37. ) else if "%VSCMD_ARG_TGT_ARCH%" neq "x64" (
  38. echo Bad environment. Make sure to run from 'x64 Native Tools Command Prompt for VS 2022'.
  39. exit /b
  40. )
  41. ) else if %BuildARM% neq 0 (
  42. if "%Platform%" neq "arm64" (
  43. echo Bad environment. Make sure to run from 'ARM64 Native Tools Command Prompt for VS 2022'.
  44. exit /b
  45. ) else if "%VSCMD_ARG_HOST_ARCH%" neq "arm64" (
  46. echo Bad environment. Make sure to run from 'ARM64 Native Tools Command Prompt for VS 2022'.
  47. exit /b
  48. ) else if "%VSCMD_ARG_TGT_ARCH%" neq "arm64" (
  49. echo Bad environment. Make sure to run from 'ARM64 Native Tools Command Prompt for VS 2022'.
  50. exit /b
  51. )
  52. ) else (
  53. if "%Platform%" neq "x86" (
  54. echo Bad environment. Make sure to run from 'x86 Native Tools Command Prompt for VS 2022'.
  55. exit /b
  56. ) else if "%VSCMD_ARG_HOST_ARCH%" neq "x86" (
  57. echo Bad environment. Make sure to run from 'x86 Native Tools Command Prompt for VS 2022'.
  58. exit /b
  59. ) else if "%VSCMD_ARG_TGT_ARCH%" neq "x86" (
  60. echo Bad environment. Make sure to run from 'x86 Native Tools Command Prompt for VS 2022'.
  61. exit /b
  62. )
  63. )
  64. FOR /F "tokens=1,2* delims= " %%i in (%FullScriptPath%version) do set "%%i=%%j"
  65. set "VersionForPacker=%AppVersion%"
  66. if %AlphaVersion% neq 0 (
  67. set "AppVersion=%AlphaVersion%"
  68. set "AppVersionStrFull=%AppVersionStr%_%AlphaVersion%"
  69. set "AlphaBetaParam=-alpha %AlphaVersion%"
  70. set "AlphaKeyFile=talpha_%AlphaVersion%_key"
  71. ) else (
  72. if %BetaChannel% neq 0 (
  73. set "AlphaBetaParam=-beta"
  74. set "AppVersionStrFull=%AppVersionStr%.beta"
  75. ) else (
  76. set "AlphaBetaParam="
  77. set "AppVersionStrFull=%AppVersionStr%"
  78. )
  79. )
  80. echo.
  81. if %BuildUWP% neq 0 (
  82. if %Build64% neq 0 (
  83. echo Building version %AppVersionStrFull% for UWP 64 bit..
  84. ) else if %BuildARM% neq 0 (
  85. echo Building version %AppVersionStrFull% for UWP ARM..
  86. ) else (
  87. echo Building version %AppVersionStrFull% for UWP..
  88. )
  89. ) else (
  90. if %Build64% neq 0 (
  91. echo Building version %AppVersionStrFull% for Windows 64 bit..
  92. ) else if %BuildARM% neq 0 (
  93. echo Building version %AppVersionStrFull% for Windows on ARM..
  94. ) else (
  95. echo Building version %AppVersionStrFull% for Windows..
  96. )
  97. )
  98. echo.
  99. set "HomePath=%FullScriptPath%.."
  100. set "ResourcesPath=%HomePath%\Resources"
  101. set "SolutionPath=%HomePath%\..\out"
  102. if %Build64% neq 0 (
  103. set "UpdateFile=tx64upd%AppVersion%"
  104. set "SetupFile=tsetup-x64.%AppVersionStrFull%.exe"
  105. set "PortableFile=tportable-x64.%AppVersionStrFull%.zip"
  106. set "DumpSymsPath=%SolutionPath%\..\..\Libraries\win64\breakpad\src\tools\windows\dump_syms\Release\dump_syms.exe"
  107. ) else if %BuildARM% neq 0 (
  108. set "UpdateFile=tarm64upd%AppVersion%"
  109. set "SetupFile=tsetup-arm64.%AppVersionStrFull%.exe"
  110. set "PortableFile=tportable-arm64.%AppVersionStrFull%.zip"
  111. set "DumpSymsPath=%SolutionPath%\..\..\Libraries\breakpad\src\tools\windows\dump_syms\Release\dump_syms.exe"
  112. ) else (
  113. set "UpdateFile=tupdate%AppVersion%"
  114. set "SetupFile=tsetup.%AppVersionStrFull%.exe"
  115. set "PortableFile=tportable.%AppVersionStrFull%.zip"
  116. set "DumpSymsPath=%SolutionPath%\..\..\Libraries\breakpad\src\tools\windows\dump_syms\Release\dump_syms.exe"
  117. )
  118. set "ReleasePath=%SolutionPath%\Release"
  119. set "DeployPath=%ReleasePath%\deploy\%AppVersionStrMajor%\%AppVersionStrFull%"
  120. set "SignPath=%HomePath%\..\..\DesktopPrivate\Sign.bat"
  121. set "BinaryName=Telegram"
  122. set "DropboxSymbolsPath=Y:\Telegram\symbols"
  123. set "DropboxSymbolsPathFallback=%HomePath%\..\..\Dropbox\Telegram\symbols"
  124. set "FinalReleasePath=Z:\Projects\backup\tdesktop"
  125. set "FinalReleasePathFallback=%HomePath%\..\..\Projects\backup\tdesktop"
  126. if not exist %DropboxSymbolsPath% (
  127. if exist %DropboxSymbolsPathFallback% (
  128. set "DropboxSymbolsPath=%DropboxSymbolsPathFallback%"
  129. ) else (
  130. echo Dropbox path %DropboxSymbolsPath% not found!
  131. exit /b 1
  132. )
  133. )
  134. if not exist %FinalReleasePath% (
  135. if exist %FinalReleasePathFallback% (
  136. set "FinalReleasePath=%FinalReleasePathFallback%"
  137. ) else (
  138. echo Release path %FinalReleasePath% not found!
  139. exit /b 1
  140. )
  141. )
  142. if %BuildUWP% neq 0 (
  143. if exist %ReleasePath%\AppX\ (
  144. echo Result folder out\Release\AppX already exists!
  145. exit /b 1
  146. )
  147. )
  148. if %AlphaVersion% neq 0 (
  149. if exist %DeployPath%\ (
  150. echo Deploy folder for version %AppVersionStr% already exists!
  151. exit /b 1
  152. )
  153. if exist %ReleasePath%\%AlphaKeyFile% (
  154. echo Alpha version key file for version %AppVersion% already exists!
  155. exit /b 1
  156. )
  157. ) else (
  158. if exist %ReleasePath%\deploy\%AppVersionStrMajor%\%AppVersionStr%.alpha\ (
  159. echo Deploy folder for version %AppVersionStr%.alpha already exists!
  160. exit /b 1
  161. )
  162. if exist %ReleasePath%\deploy\%AppVersionStrMajor%\%AppVersionStr%.beta\ (
  163. echo Deploy folder for version %AppVersionStr%.beta already exists!
  164. exit /b 1
  165. )
  166. if exist %ReleasePath%\deploy\%AppVersionStrMajor%\%AppVersionStr%\ (
  167. echo Deploy folder for version %AppVersionStr% already exists!
  168. exit /b 1
  169. )
  170. if exist %ReleasePath%\tupdate%AppVersion% (
  171. echo Update file for version %AppVersion% already exists!
  172. exit /b 1
  173. )
  174. )
  175. cd "%HomePath%"
  176. call configure.bat
  177. if %errorlevel% neq 0 goto error
  178. cd "%SolutionPath%"
  179. call cmake --build . --config Release --target Telegram
  180. if %errorlevel% neq 0 goto error
  181. echo.
  182. echo Version %AppVersionStrFull% build successfull. Preparing..
  183. echo.
  184. if not exist "%DumpSymsPath%" (
  185. echo Utility dump_syms not found!
  186. exit /b 1
  187. )
  188. echo Dumping debug symbols..
  189. call "%DumpSymsPath%" "%ReleasePath%\%BinaryName%.pdb" > "%ReleasePath%\%BinaryName%.sym"
  190. echo Done!
  191. set "PATH=%PATH%;C:\Program Files\7-Zip;C:\Program Files (x86)\Inno Setup 5"
  192. cd "%ReleasePath%"
  193. :sign1
  194. call "%SignPath%" "%BinaryName%.exe"
  195. if %errorlevel% neq 0 (
  196. timeout /t 3
  197. goto sign1
  198. )
  199. if %BuildUWP% equ 0 (
  200. :sign2
  201. call "%SignPath%" "Updater.exe"
  202. if %errorlevel% neq 0 (
  203. timeout /t 3
  204. goto sign2
  205. )
  206. if %AlphaVersion% equ 0 (
  207. iscc /dMyAppVersion=%AppVersionStrSmall% /dMyAppVersionZero=%AppVersionStr% /dMyAppVersionFull=%AppVersionStrFull% "/dReleasePath=%ReleasePath%" "/dMyBuildTarget=%BuildTarget%" "%FullScriptPath%setup.iss"
  208. if %errorlevel% neq 0 goto error
  209. if not exist "%SetupFile%" goto error
  210. )
  211. if %BuildARM% neq 0 (
  212. call Packer.exe -version %VersionForPacker% -path %BinaryName%.exe -path Updater.exe -target %BuildTarget% %AlphaBetaParam%
  213. ) else (
  214. call Packer.exe -version %VersionForPacker% -path %BinaryName%.exe -path Updater.exe -path "modules\%Platform%\d3d\d3dcompiler_47.dll" -target %BuildTarget% %AlphaBetaParam%
  215. )
  216. if %errorlevel% neq 0 goto error
  217. if %AlphaVersion% neq 0 (
  218. if not exist "%ReleasePath%\%AlphaKeyFile%" (
  219. echo Alpha version key file not found!
  220. exit /b 1
  221. )
  222. FOR /F "tokens=1* delims= " %%i in (%ReleasePath%\%AlphaKeyFile%) do set "AlphaSignature=%%i"
  223. )
  224. if %errorlevel% neq 0 goto error
  225. if %AlphaVersion% neq 0 (
  226. set "UpdateFile=!UpdateFile!_!AlphaSignature!"
  227. set "PortableFile=talpha!AlphaVersion!_!AlphaSignature!.zip"
  228. )
  229. ) else (
  230. :sign2
  231. call "%SignPath%" "StartupTask.exe"
  232. if %errorlevel% neq 0 (
  233. timeout /t 3
  234. goto sign2
  235. )
  236. )
  237. for /f ^"usebackq^ eol^=^
  238. ^ delims^=^" %%a in (%ReleasePath%\%BinaryName%.sym) do (
  239. set "SymbolsHashLine=%%a"
  240. goto symbolslinedone
  241. )
  242. :symbolslinedone
  243. FOR /F "tokens=1,2,3,4* delims= " %%i in ("%SymbolsHashLine%") do set "SymbolsHash=%%l"
  244. echo Copying %BinaryName%.sym to %DropboxSymbolsPath%\%BinaryName%.pdb\%SymbolsHash%
  245. if not exist %DropboxSymbolsPath%\%BinaryName%.pdb mkdir %DropboxSymbolsPath%\%BinaryName%.pdb
  246. if not exist %DropboxSymbolsPath%\%BinaryName%.pdb\%SymbolsHash% mkdir %DropboxSymbolsPath%\%BinaryName%.pdb\%SymbolsHash%
  247. move "%ReleasePath%\%BinaryName%.sym" %DropboxSymbolsPath%\%BinaryName%.pdb\%SymbolsHash%\
  248. echo Done!
  249. if %BuildUWP% neq 0 (
  250. cd "%HomePath%"
  251. if %BuildARM% equ 0 (
  252. mkdir "%ReleasePath%\AppX\modules\%Platform%\d3d"
  253. )
  254. xcopy "Resources\uwp\AppX\*" "%ReleasePath%\AppX\" /E
  255. set "ResourcePath=%ReleasePath%\AppX\AppxManifest.xml"
  256. call :repl "Argument= (ProcessorArchitecture=)"ARCHITECTURE"/ $1"%Platform%"" "Filename=!ResourcePath!" || goto error
  257. makepri new /pr Resources\uwp\AppX\ /cf Resources\uwp\priconfig.xml /mn %ReleasePath%\AppX\AppxManifest.xml /of %ReleasePath%\AppX\resources.pri
  258. if %errorlevel% neq 0 goto error
  259. xcopy "%ReleasePath%\%BinaryName%.exe" "%ReleasePath%\AppX\"
  260. xcopy "%ReleasePath%\StartupTask.exe" "%ReleasePath%\AppX\"
  261. if %BuildARM% equ 0 (
  262. xcopy "%ReleasePath%\modules\%Platform%\d3d\d3dcompiler_47.dll" "%ReleasePath%\AppX\modules\%Platform%\d3d\"
  263. )
  264. MakeAppx.exe pack /d "%ReleasePath%\AppX" /l /p ..\out\Release\%BinaryName%.%Platform%.appx
  265. if %errorlevel% neq 0 goto error
  266. if not exist "%ReleasePath%\deploy" mkdir "%ReleasePath%\deploy"
  267. if not exist "%ReleasePath%\deploy\%AppVersionStrMajor%" mkdir "%ReleasePath%\deploy\%AppVersionStrMajor%"
  268. mkdir "%DeployPath%"
  269. move "%ReleasePath%\%BinaryName%.pdb" "%DeployPath%\"
  270. move "%ReleasePath%\%BinaryName%.%Platform%.appx" "%DeployPath%\"
  271. move "%ReleasePath%\%BinaryName%.exe" "%DeployPath%\"
  272. if "%AlphaBetaParam%" equ "" (
  273. move "%ReleasePath%\AppX" "%DeployPath%\AppX"
  274. ) else (
  275. echo Leaving result in out\Release\AppX_arch for now..
  276. )
  277. ) else (
  278. if not exist "%ReleasePath%\deploy" mkdir "%ReleasePath%\deploy"
  279. if not exist "%ReleasePath%\deploy\%AppVersionStrMajor%" mkdir "%ReleasePath%\deploy\%AppVersionStrMajor%"
  280. mkdir "%DeployPath%\%BinaryName%\modules\%Platform%\d3d"
  281. if %errorlevel% neq 0 goto error
  282. move "%ReleasePath%\%BinaryName%.exe" "%DeployPath%\%BinaryName%\"
  283. xcopy "%ReleasePath%\modules\%Platform%\d3d\d3dcompiler_47.dll" "%DeployPath%\%BinaryName%\modules\%Platform%\d3d\"
  284. move "%ReleasePath%\Updater.exe" "%DeployPath%\"
  285. move "%ReleasePath%\%BinaryName%.pdb" "%DeployPath%\"
  286. move "%ReleasePath%\Updater.pdb" "%DeployPath%\"
  287. if %AlphaVersion% equ 0 (
  288. move "%ReleasePath%\%SetupFile%" "%DeployPath%\"
  289. ) else (
  290. move "%ReleasePath%\%AlphaKeyFile%" "%DeployPath%\"
  291. )
  292. move "%ReleasePath%\%UpdateFile%" "%DeployPath%\"
  293. if %errorlevel% neq 0 goto error
  294. cd "%DeployPath%"
  295. 7z a -mx9 %PortableFile% %BinaryName%\
  296. if %errorlevel% neq 0 goto error
  297. move "%DeployPath%\%BinaryName%\%BinaryName%.exe" "%DeployPath%\"
  298. rmdir "%DeployPath%\%BinaryName%"
  299. if %errorlevel% neq 0 goto error
  300. )
  301. if %Build64% neq 0 (
  302. set "FinalDeployPath=%FinalReleasePath%\%AppVersionStrMajor%\%AppVersionStrFull%\tx64"
  303. ) else if %BuildARM% neq 0 (
  304. set "FinalDeployPath=%FinalReleasePath%\%AppVersionStrMajor%\%AppVersionStrFull%\tarm64"
  305. ) else (
  306. set "FinalDeployPath=%FinalReleasePath%\%AppVersionStrMajor%\%AppVersionStrFull%\tsetup"
  307. )
  308. if %BuildUWP% equ 0 (
  309. echo.
  310. echo Version %AppVersionStrFull% is ready for deploy!
  311. echo.
  312. if not exist "%DeployPath%\%UpdateFile%" goto error
  313. if not exist "%DeployPath%\%PortableFile%" goto error
  314. if %AlphaVersion% equ 0 (
  315. if not exist "%DeployPath%\%SetupFile%" goto error
  316. )
  317. if not exist "%DeployPath%\%BinaryName%.pdb" goto error
  318. if not exist "%DeployPath%\Updater.exe" goto error
  319. if not exist "%DeployPath%\Updater.pdb" goto error
  320. md "%FinalDeployPath%"
  321. xcopy "%DeployPath%\%UpdateFile%" "%FinalDeployPath%\" /Y
  322. xcopy "%DeployPath%\%PortableFile%" "%FinalDeployPath%\" /Y
  323. if %AlphaVersion% equ 0 (
  324. xcopy "%DeployPath%\%SetupFile%" "%FinalDeployPath%\" /Y
  325. ) else (
  326. xcopy "%DeployPath%\%AlphaKeyFile%" "%FinalDeployPath%\" /Y
  327. )
  328. )
  329. echo Version %AppVersionStrFull% is ready!
  330. cd "%FullExecPath%"
  331. exit /b
  332. :error
  333. (
  334. set ErrorCode=%errorlevel%
  335. if !ErrorCode! neq 0 (
  336. echo Error !ErrorCode!
  337. ) else (
  338. echo Error 666
  339. set ErrorCode=666
  340. )
  341. cd "%FullExecPath%"
  342. exit /b !ErrorCode!
  343. )
  344. :repl
  345. (
  346. set %1
  347. set %2
  348. set "TempFilename=!Filename!__tmp__"
  349. cscript //Nologo "%FullScriptPath%replace.vbs" "Replace" "!Argument!" < "!Filename!" > "!TempFilename!" || goto :repl_finish
  350. xcopy /Y !TempFilename! !Filename! >NUL || goto :repl_finish
  351. goto :repl_finish
  352. )
  353. :repl_finish
  354. (
  355. set ErrorCode=%errorlevel%
  356. if !ErrorCode! neq 0 (
  357. echo Replace error !ErrorCode!
  358. echo While replacing "%Replace%"
  359. echo In file "%Filename%"
  360. )
  361. del %TempFilename%
  362. exit /b !ErrorCode!
  363. )