Index: llvm/utils/release/build_llvm_release.bat =================================================================== --- llvm/utils/release/build_llvm_release.bat +++ llvm/utils/release/build_llvm_release.bat @@ -1,32 +1,32 @@ @echo off setlocal -if "%1"=="" goto usage -goto begin - -:usage -echo Script for building the LLVM installer on Windows, -echo used for the releases at https://github.com/llvm/llvm-project/releases -echo. -echo Usage: build_llvm_release.bat ^ -echo. -echo Example: build_llvm_release.bat 14.0.4 -echo. -exit /b +REM Script for building the LLVM installer on Windows. +REM +REM Run the script with administrator permissions. +if not exist %SYSTEMROOT%\SYSTEM32\WDI\LOGFILES ( + echo The script requires administrator permissions. + exit /b +) -:begin +REM Check number of arguments. +if "%1" == "" ( + call :print_usage + exit /b +) REM Prerequisites: REM REM Visual Studio 2019, CMake, Ninja, GNUWin32, SWIG, Python 3, REM NSIS with the strlen_8192 patch, -REM Visual Studio 2019 SDK and Nuget (for the clang-format plugin), -REM Perl (for the OpenMP run-time). -REM +REM Visual Studio 2019 SDK +REM Perl (for the OpenMP run-time), 7-Zip. REM REM For LLDB, SWIG version <= 3.0.8 needs to be used to work around REM https://github.com/swig/swig/issues/769 +REM Having VSSDKINSTALL set makes devenv *not* find the SDK for some reason. +set VSSDKINSTALL= REM You need to modify the paths below: set vsdevcmd=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat @@ -34,26 +34,72 @@ set python32_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310-32 set python64_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310 -set revision=llvmorg-%1 -set package_version=%1 -set build_dir=llvm_package_%package_version% +REM Specify building tool. +set build_tool=ninja + +REM Holders for command line options. +set "version=" +set "b32=" +set "b64=" +set "t32=" +set "t64=" +set "p32=" +set "p64=" +set "output=" +set "trace=" -echo Revision: %revision% +REM Parse arguments. +call :parse_args %* + +REM Validate command line options. +if not defined output ( + echo Missing output directory. + exit /b +) + +set location=https://github.com/llvm/llvm-project/archive/refs/heads/main.zip +set "revision=99.9.9" + +if defined version ( + if not "%version%"=="true" ( + set location=https://github.com/llvm/llvm-project/archive/llvmorg-%version%.zip + set "revision=%version%" + ) +) + +set "package_version=%revision%" +set "build_dir=%output%\llvm_package_%revision%" + +echo Revision: %revision% +echo Location: %location% echo Package version: %package_version% -echo Build dir: %build_dir% +echo. +echo Build dir: %build_dir% +echo Python 32: %python32_dir% +echo Python 64: %python64_dir% +echo Build Tool: %build_tool% +echo. +echo Build 32-bits: %b32% +echo Build 64-bits: %b64% +echo Test 32-bits: %t32% +echo Test 64-bits: %t64% +echo Package 32-bits: %p32% +echo Package 64-bits: %p64% echo. pause +if exist %build_dir% rd /s /q %build_dir% mkdir %build_dir% cd %build_dir% -echo Checking out %revision% -curl -L https://github.com/llvm/llvm-project/archive/%revision%.zip -o src.zip || exit /b -7z x src.zip || exit /b +call :print_trace_message Checking out %location% + +curl -L %location% -o src.zip || exit /b +7z x -y src.zip || exit /b mv llvm-project-* llvm-project || exit /b REM Setting CMAKE_CL_SHOWINCLUDES_PREFIX to work around PR27226. -set cmake_flags=^ +set common_cmake_flags=^ -DCMAKE_BUILD_TYPE=Release ^ -DLLVM_ENABLE_ASSERTIONS=OFF ^ -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON ^ @@ -62,74 +108,249 @@ -DPython3_FIND_REGISTRY=NEVER ^ -DPACKAGE_VERSION=%package_version% ^ -DLLDB_RELOCATABLE_PYTHON=1 ^ - -DLLDB_EMBED_PYTHON_HOME=OFF ^ - -DLLDB_TEST_COMPILER=%cd%\build32_stage0\bin\clang.exe ^ -DCMAKE_CL_SHOWINCLUDES_PREFIX="Note: including file: " ^ - -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;lldb;openmp" + -DLLVM_LIT_ARGS="-s" ^ + -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;openmp;lldb" + +REM Build the 32-bits and/or 64-bits binaries. +if defined b32 call :build_32 +if defined b64 call :build_64 +goto :eof + +::============================================================================== +:: Build 32-bits binaries. +::============================================================================== +:build_32 +REM Preserve original path +set original_path=%PATH% + +REM Set Python environment +set PYTHONHOME=%python32_dir% +set PYTHONPATH=%PYTHONHOME%\lib +set PATH=%PATH%;%PYTHONHOME% -REM TODO: Run the "check-all" tests. +set cmake_flags=^ + %common_cmake_flags% ^ + -DLLDB_TEST_COMPILER=%build_dir%\build32_stage0\bin\clang.exe ^ + -DPYTHON_HOME=%python32_dir% ^ + -DPYTHON_EXECUTABLE=%python32_dir%\python.exe -set OLDPATH=%PATH% +call :print_trace_message Build32 - Stage0 -set "VSCMD_START_DIR=%CD%" +set "VSCMD_START_DIR=%build_dir%" call "%vsdevcmd%" -arch=x86 -set PATH=%python32_dir%;%PATH% -set CC= -set CXX= mkdir build32_stage0 cd build32_stage0 -cmake -GNinja %cmake_flags% -DPYTHON_HOME=%python32_dir% -DPython3_ROOT_DIR=%python32_dir% ..\llvm-project\llvm || exit /b -ninja || ninja || ninja || exit /b -REM ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b -REM ninja check-clang || ninja check-clang || ninja check-clang || exit /b -ninja check-lld || ninja check-lld || ninja check-lld || exit /b -ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b -REM ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b +cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1 +%build_tool% all || exit /b 1 + +REM Run all the available tests. +if defined t32 ( + call :print_trace_message Build32 Stage0 - Testing + call :run_tests +) cd.. +call :print_trace_message Build32 - Stage1 + +REM CMake expects the paths that specifies the compiler and linker to be +REM with forward slash. +set all_cmake_flags=^ + %cmake_flags% ^ + -DCMAKE_C_FLAGS="-Wno-nonportable-include-path" ^ + -DCMAKE_CXX_FLAGS="-Wno-nonportable-include-path" ^ + -DCMAKE_C_COMPILER=%build_dir%/build32_stage0/bin/clang-cl.exe ^ + -DCMAKE_CXX_COMPILER=%build_dir%/build32_stage0/bin/clang-cl.exe ^ + -DCMAKE_LINKER=%build_dir%/build32_stage0/bin/lld-link.exe +set cmake_flags=%all_cmake_flags:\=/% + mkdir build32 cd build32 -set CC=..\build32_stage0\bin\clang-cl -set CXX=..\build32_stage0\bin\clang-cl -cmake -GNinja %cmake_flags% -DPYTHON_HOME=%python32_dir% -DPython3_ROOT_DIR=%python32_dir% ..\llvm-project\llvm || exit /b -ninja || ninja || ninja || exit /b -REM ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b -REM ninja check-clang || ninja check-clang || ninja check-clang || exit /b -ninja check-lld || ninja check-lld || ninja check-lld || exit /b -ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b -REM ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b -ninja package || exit /b +cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1 +%build_tool% all || exit /b 1 + +REM Run all the available tests. +if defined t32 ( + call :print_trace_message Build32 Stage1 - Testing + call :run_tests +) + +REM Create the binary package. +if defined p32 ( + call :print_trace_message Build32 - Packaging + + %build_tool% package || exit /b 1 + + 7z x -y LLVM-%package_version%-win32.exe -orepack + rmdir /s /q repack\$PLUGINSDIR + del repack\Uninstall.exe + 7z a LLVM-%package_version%-win32.zip .\repack\* -mx9 +) cd .. -set "VSCMD_START_DIR=%CD%" -set PATH=%OLDPATH% +REM Restore original path +set PATH=%original_path% + +exit /b 0 +::============================================================================== + +::============================================================================== +:: Build 64-bits binaries. +::============================================================================== +:build_64 +REM Preserve original path +set original_path=%PATH% + +REM Set Python environment +set PYTHONHOME=%python64_dir% +set PYTHONPATH=%PYTHONHOME%\lib +set PATH=%PATH%;%PYTHONHOME% + +set cmake_flags=^ + %common_cmake_flags% ^ + -DLLDB_TEST_COMPILER=%build_dir%\build64_stage0\bin\clang.exe ^ + -DPYTHON_HOME=%python64_dir% ^ + -DPYTHON_EXECUTABLE=%python64_dir%\python.exe + +call :print_trace_message Build64 - Stage0 + +set "VSCMD_START_DIR=%build_dir%" call "%vsdevcmd%" -arch=amd64 -set PATH=%python64_dir%;%PATH% -set CC= -set CXX= mkdir build64_stage0 cd build64_stage0 -cmake -GNinja %cmake_flags% -DPYTHON_HOME=%python64_dir% -DPython3_ROOT_DIR=%python64_dir% ..\llvm-project\llvm || exit /b -ninja || ninja || ninja || exit /b -ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b -ninja check-clang || ninja check-clang || ninja check-clang || exit /b -ninja check-lld || ninja check-lld || ninja check-lld || exit /b -ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b -ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b -ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b +cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1 +%build_tool% all || exit /b 1 + +REM Run all the available tests. +if defined t64 ( + call :print_trace_message Build64 Stage0 - Testing + call :run_tests +) cd.. +call :print_trace_message Build64 - Stage1 + +REM CMake expects the paths that specifies the compiler and linker to be +REM with forward slash. +set all_cmake_flags=^ + %cmake_flags% ^ + -DCMAKE_C_FLAGS="-Wno-nonportable-include-path" ^ + -DCMAKE_CXX_FLAGS="-Wno-nonportable-include-path" ^ + -DCMAKE_C_COMPILER=%build_dir%/build64_stage0/bin/clang-cl.exe ^ + -DCMAKE_CXX_COMPILER=%build_dir%/build64_stage0/bin/clang-cl.exe ^ + -DCMAKE_LINKER=%build_dir%/build64_stage0/bin/lld-link.exe +set cmake_flags=%all_cmake_flags:\=/% + mkdir build64 cd build64 -set CC=..\build64_stage0\bin\clang-cl -set CXX=..\build64_stage0\bin\clang-cl -cmake -GNinja %cmake_flags% -DPYTHON_HOME=%python64_dir% -DPython3_ROOT_DIR=%python64_dir% ..\llvm-project\llvm || exit /b -ninja || ninja || ninja || exit /b -ninja check-llvm || ninja check-llvm || ninja check-llvm || exit /b -ninja check-clang || ninja check-clang || ninja check-clang || exit /b -ninja check-lld || ninja check-lld || ninja check-lld || exit /b -ninja check-sanitizer || ninja check-sanitizer || ninja check-sanitizer || exit /b -ninja check-clang-tools || ninja check-clang-tools || ninja check-clang-tools || exit /b -ninja check-clangd || ninja check-clangd || ninja check-clangd || exit /b -ninja package || exit /b +cmake -GNinja %cmake_flags% ..\llvm-project\llvm || exit /b 1 +%build_tool% all || exit /b 1 + +REM Run all the available tests. +if defined t64 ( + call :print_trace_message Build64 Stage1 - Testing + call :run_tests +) + +REM Create the binary package. +if defined p64 ( + call :print_trace_message Build64 - Packaging + + %build_tool% package || exit /b 1 + + 7z x -y LLVM-%package_version%-win64.exe -orepack + rmdir /s /q repack\$PLUGINSDIR + del repack\Uninstall.exe + 7z a LLVM-%package_version%-win64.zip .\repack\* -mx9 +) cd .. + +REM Restore original path +set PATH=%original_path% + +exit /b 0 +::============================================================================== + +::============================================================================= +:: Run all the available tests. +::============================================================================= +:run_tests + %build_tool% check + %build_tool% check-clang + %build_tool% check-llvm + %build_tool% check-lld + %build_tool% check-sanitizer + %build_tool% check-clang-tools + %build_tool% check-clangd + +exit /b 0 +::============================================================================== + +::============================================================================= +:: Parse command line arguments. +::============================================================================= +:parse_args + set "arg_name=" + :parse_args_start + if "%1" == "" ( + :: Set a seen boolean argument. + if "%arg_name%" neq "" ( + set "%arg_name%=true" + ) + goto :parse_args_done + ) + set aux=%1 + if "%aux:~0,2%" == "--" ( + :: Set a seen boolean argument. + if "%arg_name%" neq "" ( + set "%arg_name%=true" + ) + set "arg_name=%aux:~2,250%" + ) else ( + set "%arg_name%=%1" + set "arg_name=" + ) + shift + goto :parse_args_start + +:parse_args_done +exit /b 0 +::============================================================================== + +::============================================================================== +:: Print usage. +::============================================================================== +:print_usage + echo. + echo Script for building the LLVM installer on Windows, used for + echo the releases at https://github.com/llvm/llvm-project/releases + echo. + echo Usage: build_llvm_release.bat ^ + echo. + echo options: + echo --version [^] Version number (i.e. 14.0.4) + echo --output ^ Output directory + echo. + echo --b32 build 32-bit binaries + echo --b64 build 64-bit binaries + echo --t32 run 32-bits tests + echo --t64 run 64-bits tests + echo --p32 create 32-bits binary package + echo --p64 create 64-bits binary package + echo. + echo --trace Debugging trace +exit /b 0 +::============================================================================== + +::============================================================================== +:: Print a trace message. +::============================================================================== +:print_trace_message + if defined trace ( + echo. + echo ================================ + echo %* + echo ================================ + ) +exit /b 0 +::==============================================================================