[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / utils / release / build_llvm_release.bat
blobce942220e94bfe7014273159982a4ce6ef9da814
1 @echo off\r
2 setlocal enabledelayedexpansion\r
3 \r
4 if "%1"=="" goto usage\r
5 goto begin\r
6 \r
7 :usage\r
8 echo Script for building the LLVM installer on Windows,\r
9 echo used for the releases at https://github.com/llvm/llvm-project/releases\r
10 echo.\r
11 echo Usage: build_llvm_release.bat ^<version^>\r
12 echo.\r
13 echo Example: build_llvm_release.bat 14.0.4\r
14 echo.\r
15 exit /b 1\r
17 :begin\r
19 REM Note:\r
20 REM   7zip versions 21.x and higher will try to extract the symlinks in\r
21 REM   llvm's git archive, which requires running as administrator.\r
23 REM Check 7-zip version and/or administrator permissions.\r
24 for /f "delims=" %%i in ('7z.exe ^| findstr /r "2[1-9].[0-9][0-9]"') do set version=%%i\r
25 if not "%version%"=="" (\r
26   REM Unique temporary filename to use by the 'mklink' command.\r
27   set "link_name=%temp%\%username%_%random%_%random%.tmp"\r
29   REM As the 'mklink' requires elevated permissions, the symbolic link\r
30   REM creation will fail if the script is not running as administrator.\r
31   mklink /d "!link_name!" . 1>nul 2>nul\r
32   if errorlevel 1 (\r
33     echo.\r
34     echo Script requires administrator permissions, or a 7-zip version 20.x or older.\r
35     echo Current version is "%version%"\r
36     exit /b 1\r
37   ) else (\r
38     REM Remove the temporary symbolic link.\r
39     rd "!link_name!"\r
40   )\r
41 )\r
43 REM Prerequisites:\r
44 REM\r
45 REM   Visual Studio 2019, CMake, Ninja, GNUWin32, SWIG, Python 3,\r
46 REM   NSIS with the strlen_8192 patch,\r
47 REM   Visual Studio 2019 SDK and Nuget (for the clang-format plugin),\r
48 REM   Perl (for the OpenMP run-time).\r
49 REM\r
50 REM\r
51 REM   For LLDB, SWIG version <= 3.0.8 needs to be used to work around\r
52 REM   https://github.com/swig/swig/issues/769\r
55 REM You need to modify the paths below:\r
56 set vsdevcmd=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat\r
58 set python32_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310-32\r
59 set python64_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310\r
61 set revision=llvmorg-%1\r
62 set package_version=%1\r
63 set build_dir=%cd%\llvm_package_%package_version%\r
65 echo Revision: %revision%\r
66 echo Package version: %package_version%\r
67 echo Build dir: %build_dir%\r
68 echo.\r
69 pause\r
71 if exist %build_dir% (\r
72   echo Build directory already exists: %build_dir%\r
73   exit /b 1\r
74 )\r
75 mkdir %build_dir%\r
76 cd %build_dir%\r
78 echo Checking out %revision%\r
79 curl -L https://github.com/llvm/llvm-project/archive/%revision%.zip -o src.zip || exit /b 1\r
80 7z x src.zip || exit /b 1\r
81 mv llvm-project-* llvm-project || exit /b 1\r
83 curl -O https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.9.12/libxml2-v2.9.12.tar.gz || exit /b 1\r
84 tar zxf libxml2-v2.9.12.tar.gz\r
86 REM Setting CMAKE_CL_SHOWINCLUDES_PREFIX to work around PR27226.\r
87 REM Common flags for both 32/64 builds.\r
88 set common_cmake_flags=^\r
89   -DCMAKE_BUILD_TYPE=Release ^\r
90   -DLLVM_ENABLE_ASSERTIONS=OFF ^\r
91   -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON ^\r
92   -DLLVM_BUILD_LLVM_C_DYLIB=ON ^\r
93   -DCMAKE_INSTALL_UCRT_LIBRARIES=ON ^\r
94   -DPython3_FIND_REGISTRY=NEVER ^\r
95   -DPACKAGE_VERSION=%package_version% ^\r
96   -DLLDB_RELOCATABLE_PYTHON=1 ^\r
97   -DLLDB_EMBED_PYTHON_HOME=OFF ^\r
98   -DCMAKE_CL_SHOWINCLUDES_PREFIX="Note: including file: " ^\r
99   -DLLVM_ENABLE_LIBXML2=FORCE_ON ^\r
100   -DLLDB_ENABLE_LIBXML2=OFF ^\r
101   -DCMAKE_C_FLAGS="-DLIBXML_STATIC" ^\r
102   -DCMAKE_CXX_FLAGS="-DLIBXML_STATIC" ^\r
103   -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;lldb;openmp"\r
105 REM Preserve original path\r
106 set OLDPATH=%PATH%\r
108 REM Build the 32-bits and/or 64-bits binaries.\r
109 call :do_build_32 || exit /b 1\r
110 call :do_build_64 || exit /b 1\r
111 exit /b 0\r
113 ::==============================================================================\r
114 :: Build 32-bits binaries.\r
115 ::==============================================================================\r
116 :do_build_32\r
117 REM Restore original path\r
118 set PATH=%OLDPATH%\r
120 REM TODO: Run the "check-all" tests.\r
122 REM Set Python environment\r
123 set PYTHONHOME=%python32_dir%\r
124 set PATH=%PYTHONHOME%;%PATH%\r
126 set "VSCMD_START_DIR=%build_dir%"\r
127 call "%vsdevcmd%" -arch=x86\r
128 mkdir build32_stage0\r
129 cd build32_stage0\r
131 mkdir libxmlbuild\r
132 cd libxmlbuild\r
133 cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DBUILD_SHARED_LIBS=OFF -DLIBXML2_WITH_C14N=OFF -DLIBXML2_WITH_CATALOG=OFF -DLIBXML2_WITH_DEBUG=OFF -DLIBXML2_WITH_DOCB=OFF -DLIBXML2_WITH_FTP=OFF -DLIBXML2_WITH_HTML=OFF -DLIBXML2_WITH_HTTP=OFF -DLIBXML2_WITH_ICONV=OFF -DLIBXML2_WITH_ICU=OFF -DLIBXML2_WITH_ISO8859X=OFF -DLIBXML2_WITH_LEGACY=OFF -DLIBXML2_WITH_LZMA=OFF -DLIBXML2_WITH_MEM_DEBUG=OFF -DLIBXML2_WITH_MODULES=OFF -DLIBXML2_WITH_OUTPUT=ON -DLIBXML2_WITH_PATTERN=OFF -DLIBXML2_WITH_PROGRAMS=OFF -DLIBXML2_WITH_PUSH=OFF -DLIBXML2_WITH_PYTHON=OFF -DLIBXML2_WITH_READER=OFF -DLIBXML2_WITH_REGEXPS=OFF -DLIBXML2_WITH_RUN_DEBUG=OFF -DLIBXML2_WITH_SAX1=OFF -DLIBXML2_WITH_SCHEMAS=OFF -DLIBXML2_WITH_SCHEMATRON=OFF -DLIBXML2_WITH_TESTS=OFF -DLIBXML2_WITH_THREADS=ON -DLIBXML2_WITH_THREAD_ALLOC=OFF -DLIBXML2_WITH_TREE=ON -DLIBXML2_WITH_VALID=OFF -DLIBXML2_WITH_WRITER=OFF -DLIBXML2_WITH_XINCLUDE=OFF -DLIBXML2_WITH_XPATH=OFF -DLIBXML2_WITH_XPTR=OFF -DLIBXML2_WITH_ZLIB=OFF ../../libxml2-v2.9.12 || exit /b 1\r
134 ninja install || exit /b 1\r
135 set libxmldir=%cd%\install\r
136 set "libxmldir=%libxmldir:\=/%"\r
137 cd ..\r
139 REM Stage0 binaries directory; used in stage1.\r
140 set "stage0_bin_dir=%build_dir%/build32_stage0/bin"\r
141 set cmake_flags=^\r
142   %common_cmake_flags% ^\r
143   -DLLDB_TEST_COMPILER=%stage0_bin_dir%/clang.exe ^\r
144   -DPYTHON_HOME=%PYTHONHOME% ^\r
145   -DPython3_ROOT_DIR=%PYTHONHOME% ^\r
146   -DLIBXML2_INCLUDE_DIRS=%libxmldir%/include/libxml2 ^\r
147   -DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib\r
149 cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1\r
150 ninja || ninja || ninja || exit /b 1\r
151 REM ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1\r
152 REM ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1\r
153 ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1\r
154 ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1\r
155 REM ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1\r
156 cd..\r
158 REM CMake expects the paths that specifies the compiler and linker to be\r
159 REM with forward slash.\r
160 set all_cmake_flags=^\r
161   %cmake_flags% ^\r
162   -DCMAKE_C_COMPILER=%stage0_bin_dir%/clang-cl.exe ^\r
163   -DCMAKE_CXX_COMPILER=%stage0_bin_dir%/clang-cl.exe ^\r
164   -DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^\r
165   -DCMAKE_AR=%stage0_bin_dir%/llvm-lib.exe ^\r
166   -DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe\r
167 set cmake_flags=%all_cmake_flags:\=/%\r
169 mkdir build32\r
170 cd build32\r
171 cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1\r
172 ninja || ninja || ninja || exit /b 1\r
173 REM ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1\r
174 REM ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1\r
175 ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1\r
176 ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1\r
177 REM ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1\r
178 ninja package || exit /b 1\r
179 cd ..\r
181 exit /b 0\r
182 ::==============================================================================\r
184 ::==============================================================================\r
185 :: Build 64-bits binaries.\r
186 ::==============================================================================\r
187 :do_build_64\r
188 REM Restore original path\r
189 set PATH=%OLDPATH%\r
191 REM Set Python environment\r
192 set PYTHONHOME=%python64_dir%\r
193 set PATH=%PYTHONHOME%;%PATH%\r
195 set "VSCMD_START_DIR=%build_dir%"\r
196 call "%vsdevcmd%" -arch=amd64\r
197 mkdir build64_stage0\r
198 cd build64_stage0\r
200 mkdir libxmlbuild\r
201 cd libxmlbuild\r
202 cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DBUILD_SHARED_LIBS=OFF -DLIBXML2_WITH_C14N=OFF -DLIBXML2_WITH_CATALOG=OFF -DLIBXML2_WITH_DEBUG=OFF -DLIBXML2_WITH_DOCB=OFF -DLIBXML2_WITH_FTP=OFF -DLIBXML2_WITH_HTML=OFF -DLIBXML2_WITH_HTTP=OFF -DLIBXML2_WITH_ICONV=OFF -DLIBXML2_WITH_ICU=OFF -DLIBXML2_WITH_ISO8859X=OFF -DLIBXML2_WITH_LEGACY=OFF -DLIBXML2_WITH_LZMA=OFF -DLIBXML2_WITH_MEM_DEBUG=OFF -DLIBXML2_WITH_MODULES=OFF -DLIBXML2_WITH_OUTPUT=ON -DLIBXML2_WITH_PATTERN=OFF -DLIBXML2_WITH_PROGRAMS=OFF -DLIBXML2_WITH_PUSH=OFF -DLIBXML2_WITH_PYTHON=OFF -DLIBXML2_WITH_READER=OFF -DLIBXML2_WITH_REGEXPS=OFF -DLIBXML2_WITH_RUN_DEBUG=OFF -DLIBXML2_WITH_SAX1=OFF -DLIBXML2_WITH_SCHEMAS=OFF -DLIBXML2_WITH_SCHEMATRON=OFF -DLIBXML2_WITH_TESTS=OFF -DLIBXML2_WITH_THREADS=ON -DLIBXML2_WITH_THREAD_ALLOC=OFF -DLIBXML2_WITH_TREE=ON -DLIBXML2_WITH_VALID=OFF -DLIBXML2_WITH_WRITER=OFF -DLIBXML2_WITH_XINCLUDE=OFF -DLIBXML2_WITH_XPATH=OFF -DLIBXML2_WITH_XPTR=OFF -DLIBXML2_WITH_ZLIB=OFF ../../libxml2-v2.9.12 || exit /b 1\r
203 ninja install || exit /b 1\r
204 set libxmldir=%cd%\install\r
205 set "libxmldir=%libxmldir:\=/%"\r
206 cd ..\r
208 REM Stage0 binaries directory; used in stage1.\r
209 set "stage0_bin_dir=%build_dir%/build64_stage0/bin"\r
210 set cmake_flags=^\r
211   %common_cmake_flags% ^\r
212   -DLLDB_TEST_COMPILER=%stage0_bin_dir%/clang.exe ^\r
213   -DPYTHON_HOME=%PYTHONHOME% ^\r
214   -DPython3_ROOT_DIR=%PYTHONHOME% ^\r
215   -DLIBXML2_INCLUDE_DIRS=%libxmldir%/include/libxml2 ^\r
216   -DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib\r
218 cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1\r
219 ninja || ninja || ninja || exit /b 1\r
220 ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1\r
221 ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1\r
222 ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1\r
223 ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1\r
224 ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1\r
225 ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b 1\r
226 cd..\r
228 REM CMake expects the paths that specifies the compiler and linker to be\r
229 REM with forward slash.\r
230 set all_cmake_flags=^\r
231   %cmake_flags% ^\r
232   -DCMAKE_C_COMPILER=%stage0_bin_dir%/clang-cl.exe ^\r
233   -DCMAKE_CXX_COMPILER=%stage0_bin_dir%/clang-cl.exe ^\r
234   -DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^\r
235   -DCMAKE_AR=%stage0_bin_dir%/llvm-lib.exe ^\r
236   -DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe\r
237 set cmake_flags=%all_cmake_flags:\=/%\r
239 mkdir build64\r
240 cd build64\r
241 cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1\r
242 ninja || ninja || ninja || exit /b 1\r
243 ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1\r
244 ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1\r
245 ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1\r
246 ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1\r
247 ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1\r
248 ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b 1\r
249 ninja package || exit /b 1\r
250 cd ..\r
252 exit /b 0\r
253 ::==============================================================================\r