Skip to content

Commit 7d892b9

Browse files
committed
Unify x64 and arm64 build process in build_llvm_release.bat
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.
1 parent 584f8cc commit 7d892b9

File tree

1 file changed

+71
-106
lines changed

1 file changed

+71
-106
lines changed

llvm/utils/release/build_llvm_release.bat

Lines changed: 71 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,20 @@ set common_cmake_flags=^
154154
-DLLVM_BUILD_LLVM_C_DYLIB=ON ^
155155
-DPython3_FIND_REGISTRY=NEVER ^
156156
-DPACKAGE_VERSION=%package_version% ^
157-
-DLLDB_RELOCATABLE_PYTHON=1 ^
158-
-DLLDB_EMBED_PYTHON_HOME=OFF ^
159157
-DCMAKE_CL_SHOWINCLUDES_PREFIX="Note: including file: " ^
160158
-DLLVM_ENABLE_LIBXML2=FORCE_ON ^
161-
-DLLDB_ENABLE_LIBXML2=OFF ^
162159
-DCLANG_ENABLE_LIBXML2=OFF ^
163160
-DCMAKE_C_FLAGS="%common_compiler_flags%" ^
164161
-DCMAKE_CXX_FLAGS="%common_compiler_flags%" ^
165162
-DLLVM_ENABLE_RPMALLOC=ON ^
166-
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;lldb;openmp"
163+
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" ^
164+
-DLLVM_ENABLE_RUNTIMES="compiler-rt;openmp"
165+
166+
set common_lldb_flags=^
167+
-DLLDB_RELOCATABLE_PYTHON=1 ^
168+
-DLLDB_EMBED_PYTHON_HOME=OFF ^
169+
-DLLDB_ENABLE_LIBXML2=OFF ^
170+
-DPYTHON_HOME=%PYTHONHOME%
167171

168172
set cmake_profile_flags=""
169173

@@ -172,8 +176,8 @@ set OLDPATH=%PATH%
172176

173177
REM Build the 32-bits and/or 64-bits binaries.
174178
if "%x86%" == "true" call :do_build_32 || exit /b 1
175-
if "%x64%" == "true" call :do_build_64 || exit /b 1
176-
if "%arm64%" == "true" call :do_build_arm64 || exit /b 1
179+
if "%x64%" == "true" call :do_build_64_common amd64 %python64_dir% || exit /b 1
180+
if "%arm64%" == "true" call :do_build_64_common arm64 %pythonarm64_dir% || exit /b 1
177181
exit /b 0
178182

179183
::==============================================================================
@@ -192,8 +196,6 @@ set "stage0_bin_dir=%build_dir%/build32_stage0/bin"
192196
set cmake_flags=^
193197
%common_cmake_flags% ^
194198
-DLLVM_ENABLE_RPMALLOC=OFF ^
195-
-DLLDB_TEST_COMPILER=%stage0_bin_dir%/clang.exe ^
196-
-DPYTHON_HOME=%PYTHONHOME% ^
197199
-DPython3_ROOT_DIR=%PYTHONHOME% ^
198200
-DLIBXML2_INCLUDE_DIR=%libxmldir%/include/libxml2 ^
199201
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib
@@ -211,6 +213,8 @@ REM CMake expects the paths that specifies the compiler and linker to be
211213
REM with forward slash.
212214
set all_cmake_flags=^
213215
%cmake_flags% ^
216+
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;" ^
217+
%common_lldb_flags% ^
214218
-DCMAKE_C_COMPILER=%stage0_bin_dir%/clang-cl.exe ^
215219
-DCMAKE_CXX_COMPILER=%stage0_bin_dir%/clang-cl.exe ^
216220
-DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^
@@ -234,34 +238,50 @@ exit /b 0
234238
::==============================================================================
235239

236240
::==============================================================================
237-
:: Build 64-bits binaries.
241+
:: Build 64-bits binaries (common function for both x64 and arm64)
238242
::==============================================================================
239-
:do_build_64
240-
call :set_environment %python64_dir% || exit /b 1
241-
call "%vsdevcmd%" -arch=amd64 || exit /b 1
243+
:do_build_64_common
244+
set arch=%1
245+
set python_dir=%2
246+
247+
if "%arch%"=="amd64" (
248+
set vs_arch=-arch=amd64
249+
) else (
250+
set vs_arch=-arch=arm64
251+
)
252+
253+
call :set_environment %python_dir% || exit /b 1
254+
call "%vsdevcmd%" %vs_arch% || exit /b 1
242255
@echo on
243-
mkdir build64_stage0
244-
cd build64_stage0
256+
mkdir build_%arch%_stage0
257+
cd build_%arch%_stage0
245258
call :do_build_libxml || exit /b 1
246259

247260
REM Stage0 binaries directory; used in stage1.
248-
set "stage0_bin_dir=%build_dir%/build64_stage0/bin"
261+
set "stage0_bin_dir=%build_dir%/build_%arch%_stage0/bin"
249262
set cmake_flags=^
250263
%common_cmake_flags% ^
251-
-DLLDB_TEST_COMPILER=%stage0_bin_dir%/clang.exe ^
252-
-DPYTHON_HOME=%PYTHONHOME% ^
253264
-DPython3_ROOT_DIR=%PYTHONHOME% ^
254265
-DLIBXML2_INCLUDE_DIR=%libxmldir%/include/libxml2 ^
255-
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib
266+
-DLIBXML2_LIBRARIES=%libxmldir%/lib/libxml2s.lib ^
267+
-DCLANG_DEFAULT_LINKER=lld
268+
if "%arch%"=="arm64" (
269+
set cmake_flags=%cmake_flags% ^
270+
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
271+
)
256272

257-
cmake -GNinja %cmake_flags% %llvm_src%\llvm || exit /b 1
258-
ninja || ninja || ninja || exit /b 1
259-
ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
260-
ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
261-
ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1
262-
ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1
263-
ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1
264-
ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b 1
273+
cmake -GNinja %cmake_flags% ^
274+
-DLLVM_TARGETS_TO_BUILD=Native ^
275+
-DCMAKE_C_COMPILER=clang-cl.exe ^
276+
-DCMAKE_CXX_COMPILER=clang-cl.exe ^
277+
%llvm_src%\llvm || exit /b 1
278+
ninja || exit /b 1
279+
ninja check-llvm || exit /b 1
280+
ninja check-clang || exit /b 1
281+
ninja check-lld || exit /b 1
282+
REM ninja check-runtimes || exit /b 1
283+
ninja check-clang-tools || exit /b 1
284+
ninja check-clangd || exit /b 1
265285
cd..
266286

267287
REM CMake expects the paths that specifies the compiler and linker to be
@@ -273,24 +293,37 @@ set all_cmake_flags=^
273293
-DCMAKE_LINKER=%stage0_bin_dir%/lld-link.exe ^
274294
-DCMAKE_AR=%stage0_bin_dir%/llvm-lib.exe ^
275295
-DCMAKE_RC=%stage0_bin_dir%/llvm-windres.exe
296+
if "%arch%"=="arm64" (
297+
set all_cmake_flags=%all_cmake_flags% ^
298+
-DCPACK_SYSTEM_NAME=woa64
299+
)
276300
set cmake_flags=%all_cmake_flags:\=/%
277301

278-
279-
mkdir build64
280-
cd build64
302+
mkdir build_%arch%
303+
cd build_%arch%
281304
call :do_generate_profile || exit /b 1
282-
cmake -GNinja %cmake_flags% %cmake_profile_flags% %llvm_src%\llvm || exit /b 1
283-
ninja || ninja || ninja || exit /b 1
284-
ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b 1
285-
ninja check-clang || ninja check-clang || ninja check-clang || exit /b 1
286-
ninja check-lld || ninja check-lld || ninja check-lld || exit /b 1
287-
ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b 1
288-
ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b 1
289-
ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b 1
305+
cmake -GNinja %cmake_flags% ^
306+
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;flang;mlir" ^
307+
%common_lldb_flags% ^
308+
%cmake_profile_flags% %llvm_src%\llvm || exit /b 1
309+
ninja || exit /b 1
310+
ninja check-llvm || exit /b 1
311+
ninja check-clang || exit /b 1
312+
ninja check-lld || exit /b 1
313+
REM ninja check-lldb || exit /b 1
314+
REM ninja check-runtimes || exit /b 1
315+
ninja check-clang-tools || exit /b 1
316+
ninja check-clangd || exit /b 1
317+
ninja check-flang || exit /b 1
318+
ninja check-mlir || exit /b 1
290319
ninja package || exit /b 1
291320

292321
:: generate tarball with install toolchain only off
293-
set filename=clang+llvm-%version%-x86_64-pc-windows-msvc
322+
if "%arch%"=="amd64" (
323+
set filename=clang+llvm-%version%-x86_64-pc-windows-msvc
324+
) else (
325+
set filename=clang+llvm-%version%-aarch64-pc-windows-msvc
326+
)
294327
cmake -GNinja %cmake_flags% %cmake_profile_flags% -DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF ^
295328
-DCMAKE_INSTALL_PREFIX=%build_dir%/%filename% ..\llvm-project\llvm || exit /b 1
296329
ninja install || exit /b 1
@@ -300,75 +333,7 @@ cd ..
300333
7z a -ttar -so %filename%.tar %filename% | 7z a -txz -si %filename%.tar.xz
301334

302335
exit /b 0
303-
::==============================================================================
304336

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

0 commit comments

Comments
 (0)