Skip to content

Commit 9aacc1a

Browse files
authored
Unify x64 and arm64 build process in build_llvm_release.bat (#131687)
This patch unifies x64 and arm64 build process in Windows release script by consolidating common functionality while preserving architecture specific requirements. Key changes include: - Combined x64 and arm64 build logic into do_build_64_common - Added PGO support for arm64 builds - Added flang and mlir projects to x64 builds - Remove LLDB from stage 0 builds and consolidate common LLDB flags - Build sanitizers for x64 while disable them on arm64. - Use LLVM_ENABLE_RUNTIMES for including runtime projects
1 parent 9ba54ca commit 9aacc1a

File tree

1 file changed

+56
-94
lines changed

1 file changed

+56
-94
lines changed

llvm/utils/release/build_llvm_release.bat

100755100644
Lines changed: 56 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,14 @@ set common_cmake_flags=^
156156
-DLLVM_BUILD_LLVM_C_DYLIB=ON ^
157157
-DPython3_FIND_REGISTRY=NEVER ^
158158
-DPACKAGE_VERSION=%package_version% ^
159-
-DLLDB_RELOCATABLE_PYTHON=1 ^
160-
-DLLDB_EMBED_PYTHON_HOME=OFF ^
161159
-DCMAKE_CL_SHOWINCLUDES_PREFIX="Note: including file: " ^
162160
-DLLVM_ENABLE_LIBXML2=FORCE_ON ^
163-
-DLLDB_ENABLE_LIBXML2=OFF ^
164161
-DCLANG_ENABLE_LIBXML2=OFF ^
165162
-DCMAKE_C_FLAGS="%common_compiler_flags%" ^
166163
-DCMAKE_CXX_FLAGS="%common_compiler_flags%" ^
167164
-DLLVM_ENABLE_RPMALLOC=ON ^
168-
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;lldb;openmp"
165+
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" ^
166+
-DLLVM_ENABLE_RUNTIMES="compiler-rt;openmp"
169167

170168
if "%force-msvc%" == "" (
171169
where /q clang-cl
@@ -185,15 +183,20 @@ if "%force-msvc%" == "" (
185183
)
186184
)
187185

186+
set common_lldb_flags=^
187+
-DLLDB_RELOCATABLE_PYTHON=1 ^
188+
-DLLDB_EMBED_PYTHON_HOME=OFF ^
189+
-DLLDB_ENABLE_LIBXML2=OFF
190+
188191
set cmake_profile_flags=""
189192

190193
REM Preserve original path
191194
set OLDPATH=%PATH%
192195

193196
REM Build the 32-bits and/or 64-bits binaries.
194197
if "%x86%" == "true" call :do_build_32 || exit /b 1
195-
if "%x64%" == "true" call :do_build_64 || exit /b 1
196-
if "%arm64%" == "true" call :do_build_arm64 || exit /b 1
198+
if "%x64%" == "true" call :do_build_64_common amd64 %python64_dir% || exit /b 1
199+
if "%arm64%" == "true" call :do_build_64_common arm64 %pythonarm64_dir% || exit /b 1
197200
exit /b 0
198201

199202
::==============================================================================
@@ -212,8 +215,6 @@ set "stage0_bin_dir=%build_dir%/build32_stage0/bin"
212215
set cmake_flags=^
213216
%common_cmake_flags% ^
214217
-DLLVM_ENABLE_RPMALLOC=OFF ^
215-
-DLLDB_TEST_COMPILER=%stage0_bin_dir%/clang.exe ^
216-
-DPYTHON_HOME=%PYTHONHOME% ^
217218
-DPython3_ROOT_DIR=%PYTHONHOME% ^
218219
-DLIBXML2_INCLUDE_DIR=%libxmldir%/include/libxml2 ^
219220
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib
@@ -231,6 +232,9 @@ REM CMake expects the paths that specifies the compiler and linker to be
231232
REM with forward slash.
232233
set all_cmake_flags=^
233234
%cmake_flags% ^
235+
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;" ^
236+
%common_lldb_flags% ^
237+
-DPYTHON_HOME=%PYTHONHOME% ^
234238
-DCMAKE_C_COMPILER=%stage0_bin_dir%/clang-cl.exe ^
235239
-DCMAKE_CXX_COMPILER=%stage0_bin_dir%/clang-cl.exe ^
236240
-DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^
@@ -254,32 +258,42 @@ exit /b 0
254258
::==============================================================================
255259

256260
::==============================================================================
257-
:: Build 64-bits binaries.
261+
:: Build 64-bits binaries (common function for both x64 and arm64)
258262
::==============================================================================
259-
:do_build_64
260-
call :set_environment %python64_dir% || exit /b 1
261-
call "%vsdevcmd%" -arch=amd64 || exit /b 1
263+
:do_build_64_common
264+
set arch=%1
265+
set python_dir=%2
266+
267+
call :set_environment %python_dir% || exit /b 1
268+
call "%vsdevcmd%" -arch=%arch% || exit /b 1
262269
@echo on
263-
mkdir build64_stage0
264-
cd build64_stage0
270+
mkdir build_%arch%_stage0
271+
cd build_%arch%_stage0
265272
call :do_build_libxml || exit /b 1
266273

267274
REM Stage0 binaries directory; used in stage1.
268-
set "stage0_bin_dir=%build_dir%/build64_stage0/bin"
275+
set "stage0_bin_dir=%build_dir%/build_%arch%_stage0/bin"
269276
set cmake_flags=^
270277
%common_cmake_flags% ^
271-
-DLLDB_TEST_COMPILER=%stage0_bin_dir%/clang.exe ^
272-
-DPYTHON_HOME=%PYTHONHOME% ^
273278
-DPython3_ROOT_DIR=%PYTHONHOME% ^
274279
-DLIBXML2_INCLUDE_DIR=%libxmldir%/include/libxml2 ^
275-
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib
280+
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib ^
281+
-DCLANG_DEFAULT_LINKER=lld
282+
if "%arch%"=="arm64" (
283+
set cmake_flags=%cmake_flags% ^
284+
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
285+
)
276286

277-
cmake -GNinja %cmake_flags% %llvm_src%\llvm || exit /b 1
287+
cmake -GNinja %cmake_flags% ^
288+
-DLLVM_TARGETS_TO_BUILD=Native ^
289+
%llvm_src%\llvm || exit /b 1
278290
ninja || ninja || ninja || exit /b 1
279291
ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
280292
ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
281293
ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1
282-
ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1
294+
if "%arch%"=="amd64" (
295+
ninja check-runtimes || ninja check-runtimes || ninja check-runtimes || exit /b 1
296+
)
283297
ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1
284298
ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b 1
285299
cd..
@@ -293,24 +307,40 @@ set all_cmake_flags=^
293307
-DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^
294308
-DCMAKE_AR=%stage0_bin_dir%/llvm-lib.exe ^
295309
-DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe
310+
if "%arch%"=="arm64" (
311+
set all_cmake_flags=%all_cmake_flags% ^
312+
-DCPACK_SYSTEM_NAME=woa64
313+
)
296314
set cmake_flags=%all_cmake_flags:\=/%
297315

298-
299-
mkdir build64
300-
cd build64
316+
mkdir build_%arch%
317+
cd build_%arch%
301318
call :do_generate_profile || exit /b 1
302-
cmake -GNinja %cmake_flags% %cmake_profile_flags% %llvm_src%\llvm || exit /b 1
319+
cmake -GNinja %cmake_flags% ^
320+
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;flang;mlir" ^
321+
%common_lldb_flags% ^
322+
-DPYTHON_HOME=%PYTHONHOME% ^
323+
%cmake_profile_flags% %llvm_src%\llvm || exit /b 1
303324
ninja || ninja || ninja || exit /b 1
304325
ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
305326
ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
306327
ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1
307-
ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1
328+
if "%arch%"=="amd64" (
329+
ninja check-runtimes || ninja check-runtimes || ninja check-runtimes || exit /b 1
330+
)
308331
ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1
309332
ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b 1
333+
REM ninja check-flang || ninja check-flang || ninja check-flang || exit /b 1
334+
REM ninja check-mlir || ninja check-mlir || ninja check-mlir || exit /b 1
335+
REM ninja check-lldb || ninja check-lldb || ninja check-lldb || exit /b 1
310336
ninja package || exit /b 1
311337

312338
:: generate tarball with install toolchain only off
313-
set filename=clang+llvm-%version%-x86_64-pc-windows-msvc
339+
if "%arch%"=="amd64" (
340+
set filename=clang+llvm-%version%-x86_64-pc-windows-msvc
341+
) else (
342+
set filename=clang+llvm-%version%-aarch64-pc-windows-msvc
343+
)
314344
cmake -GNinja %cmake_flags% %cmake_profile_flags% -DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF ^
315345
-DCMAKE_INSTALL_PREFIX=%build_dir%/%filename% ..\llvm-project\llvm || exit /b 1
316346
ninja install || exit /b 1
@@ -320,75 +350,7 @@ cd ..
320350
7z a -ttar -so %filename%.tar %filename% | 7z a -txz -si %filename%.tar.xz
321351

322352
exit /b 0
323-
::==============================================================================
324-
325-
::==============================================================================
326-
:: Build arm64 binaries.
327-
::==============================================================================
328-
:do_build_arm64
329-
call :set_environment %pythonarm64_dir% || exit /b 1
330-
call "%vsdevcmd%" -host_arch=x64 -arch=arm64 || exit /b 1
331-
@echo on
332-
mkdir build_arm64_stage0
333-
cd build_arm64_stage0
334-
call :do_build_libxml || exit /b 1
335-
336-
REM Stage0 binaries directory; used in stage1.
337-
set "stage0_bin_dir=%build_dir%/build_arm64_stage0/bin"
338-
set cmake_flags=^
339-
%common_cmake_flags% ^
340-
-DCLANG_DEFAULT_LINKER=lld ^
341-
-DLIBXML2_INCLUDE_DIR=%libxmldir%/include/libxml2 ^
342-
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib ^
343-
-DPython3_ROOT_DIR=%PYTHONHOME% ^
344-
-DCOMPILER_RT_BUILD_PROFILE=OFF ^
345-
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
346-
347-
REM We need to build stage0 compiler-rt with clang-cl (msvc lacks some builtins).
348-
cmake -GNinja %cmake_flags% ^
349-
-DCMAKE_C_COMPILER=clang-cl.exe ^
350-
-DCMAKE_CXX_COMPILER=clang-cl.exe ^
351-
%llvm_src%\llvm || exit /b 1
352-
ninja || exit /b 1
353-
::ninja check-llvm || exit /b 1
354-
::ninja check-clang || exit /b 1
355-
::ninja check-lld || exit /b 1
356-
::ninja check-sanitizer || exit /b 1
357-
::ninja check-clang-tools || exit /b 1
358-
::ninja check-clangd || exit /b 1
359-
cd..
360-
361-
REM CMake expects the paths that specifies the compiler and linker to be
362-
REM with forward slash.
363-
REM CPACK_SYSTEM_NAME is set to have a correct name for installer generated.
364-
set all_cmake_flags=^
365-
%cmake_flags% ^
366-
-DCMAKE_C_COMPILER=%stage0_bin_dir%/clang-cl.exe ^
367-
-DCMAKE_CXX_COMPILER=%stage0_bin_dir%/clang-cl.exe ^
368-
-DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^
369-
-DCMAKE_AR=%stage0_bin_dir%/llvm-lib.exe ^
370-
-DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe ^
371-
-DCPACK_SYSTEM_NAME=woa64
372-
set cmake_flags=%all_cmake_flags:\=/%
373353

374-
mkdir build_arm64
375-
cd build_arm64
376-
cmake -GNinja %cmake_flags% %llvm_src%\llvm || exit /b 1
377-
ninja || exit /b 1
378-
REM Check but do not fail on errors.
379-
ninja check-lldb
380-
::ninja check-llvm || exit /b 1
381-
::ninja check-clang || exit /b 1
382-
::ninja check-lld || exit /b 1
383-
::ninja check-sanitizer || exit /b 1
384-
::ninja check-clang-tools || exit /b 1
385-
::ninja check-clangd || exit /b 1
386-
ninja package || exit /b 1
387-
cd ..
388-
389-
exit /b 0
390-
::==============================================================================
391-
::
392354
::==============================================================================
393355
:: Set PATH and some environment variables.
394356
::==============================================================================

0 commit comments

Comments
 (0)