独立clang构建
This commit is contained in:
106
Languages/cpp/llvm/llvm-build1.bat
Normal file
106
Languages/cpp/llvm/llvm-build1.bat
Normal file
@@ -0,0 +1,106 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM =================================================================
|
||||
REM Stage 1: Bootstrap Compiler (using MSVC as host compiler)
|
||||
REM =================================================================
|
||||
REM Builds basic Clang + LLD without runtime libraries
|
||||
REM =================================================================
|
||||
|
||||
echo ================================================================
|
||||
echo Stage 1: Building Bootstrap Compiler
|
||||
echo ================================================================
|
||||
|
||||
REM =============== CONFIGURATION ===============
|
||||
set LLVM_SOURCE_DIR=E:\llvm-project-llvmorg-22.1.5
|
||||
set BUILD_DIR=E:\llvm-build-stage1
|
||||
set INSTALL_DIR=E:\llvm-stage1
|
||||
set PARALLEL_JOBS=3
|
||||
set CMAKE_GENERATOR=Ninja
|
||||
REM ==============================================
|
||||
|
||||
echo.
|
||||
echo Configuration:
|
||||
echo Source: %LLVM_SOURCE_DIR%
|
||||
echo Build: %BUILD_DIR%
|
||||
echo Install: %INSTALL_DIR%
|
||||
echo Generator: %CMAKE_GENERATOR%
|
||||
echo Jobs: %PARALLEL_JOBS%
|
||||
echo.
|
||||
|
||||
REM Check if source directory exists
|
||||
if not exist "%LLVM_SOURCE_DIR%\llvm\CMakeLists.txt" (
|
||||
echo ERROR: Source directory not found or invalid!
|
||||
echo Please set LLVM_SOURCE_DIR to your llvm-project directory
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Clean previous build if exists
|
||||
if exist "%BUILD_DIR%" (
|
||||
echo Removing previous build directory...
|
||||
rmdir /s /q "%BUILD_DIR%"
|
||||
)
|
||||
|
||||
REM Create directories
|
||||
mkdir "%BUILD_DIR%"
|
||||
mkdir "%INSTALL_DIR%"
|
||||
|
||||
REM Navigate to build directory
|
||||
cd /d "%BUILD_DIR%"
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo Configuring with CMake...
|
||||
echo ================================================================
|
||||
|
||||
REM Configure with CMake
|
||||
cmake -G "%CMAKE_GENERATOR%" ^
|
||||
-DCMAKE_BUILD_TYPE=Release ^
|
||||
-DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" ^
|
||||
-DLLVM_TARGETS_TO_BUILD="X86" ^
|
||||
-DLLVM_ENABLE_PROJECTS="clang;lld" ^
|
||||
-DLLVM_ENABLE_RUNTIMES="" ^
|
||||
-DLLVM_INCLUDE_TESTS=OFF ^
|
||||
-DLLVM_INCLUDE_EXAMPLES=OFF ^
|
||||
-DLLVM_INCLUDE_UTILS=OFF ^
|
||||
-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF ^
|
||||
-DLLVM_BUILD_TOOLS=ON ^
|
||||
"%LLVM_SOURCE_DIR%\llvm"
|
||||
|
||||
if errorlevel 1 (
|
||||
echo ERROR: CMake configuration failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo Building...
|
||||
echo ================================================================
|
||||
|
||||
REM Build and install
|
||||
cmake --build . --config Release --target install --parallel %PARALLEL_JOBS%
|
||||
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Build failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo Verifying stage1 compiler...
|
||||
echo ================================================================
|
||||
|
||||
REM Verify the compiler works
|
||||
"%INSTALL_DIR%\bin\clang++.exe" --version > nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Built compiler doesn't work!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
"%INSTALL_DIR%\bin\clang++.exe" --version
|
||||
echo.
|
||||
echo Stage 1 completed successfully!
|
||||
echo Bootstrap compiler installed to: %INSTALL_DIR%
|
||||
echo.
|
||||
echo You can now run build-stage2.bat to build the complete toolchain.
|
||||
echo ================================================================
|
||||
150
Languages/cpp/llvm/llvm-build2.bat
Normal file
150
Languages/cpp/llvm/llvm-build2.bat
Normal file
@@ -0,0 +1,150 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM =================================================================
|
||||
REM Stage 2: Complete Toolchain (using stage1 compiler)
|
||||
REM =================================================================
|
||||
REM Builds Clang + LLD + libc++ + libc++abi + compiler-rt + LLDB
|
||||
REM =================================================================
|
||||
|
||||
echo ================================================================
|
||||
echo Stage 2: Building Complete Toolchain
|
||||
echo ================================================================
|
||||
|
||||
REM =============== CONFIGURATION ===============
|
||||
set LLVM_SOURCE_DIR=E:\llvm-project-llvmorg-22.1.5
|
||||
set STAGE1_DIR=E:\llvm-stage1
|
||||
set BUILD_DIR=E:\llvm-build-stage2
|
||||
set INSTALL_DIR=E:\llvm-final
|
||||
set PARALLEL_JOBS=8
|
||||
set CMAKE_GENERATOR=Ninja
|
||||
REM ==============================================
|
||||
|
||||
echo.
|
||||
echo Configuration:
|
||||
echo Source: %LLVM_SOURCE_DIR%
|
||||
echo Stage1: %STAGE1_DIR%
|
||||
echo Build: %BUILD_DIR%
|
||||
echo Install: %INSTALL_DIR%
|
||||
echo Generator: %CMAKE_GENERATOR%
|
||||
echo Jobs: %PARALLEL_JOBS%
|
||||
echo.
|
||||
|
||||
REM Check if source directory exists
|
||||
if not exist "%LLVM_SOURCE_DIR%\llvm\CMakeLists.txt" (
|
||||
echo ERROR: Source directory not found or invalid!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Check if stage1 compiler exists
|
||||
if not exist "%STAGE1_DIR%\bin\clang++.exe" (
|
||||
echo ERROR: Stage1 compiler not found!
|
||||
echo Please run build-stage1.bat first
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Clean previous build if exists
|
||||
if exist "%BUILD_DIR%" (
|
||||
echo Removing previous build directory...
|
||||
rmdir /s /q "%BUILD_DIR%"
|
||||
)
|
||||
|
||||
REM Create directories
|
||||
mkdir "%BUILD_DIR%"
|
||||
mkdir "%INSTALL_DIR%"
|
||||
|
||||
REM Navigate to build directory
|
||||
cd /d "%BUILD_DIR%"
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo Configuring with CMake...
|
||||
echo ================================================================
|
||||
|
||||
REM Configure with CMake
|
||||
cmake -G "%CMAKE_GENERATOR%" ^
|
||||
-DCMAKE_C_COMPILER="%STAGE1_DIR%\bin\clang.exe" ^
|
||||
-DCMAKE_CXX_COMPILER="%STAGE1_DIR%\bin\clang++.exe" ^
|
||||
-DCMAKE_BUILD_TYPE=Release ^
|
||||
-DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" ^
|
||||
-DLLVM_TARGETS_TO_BUILD="X86" ^
|
||||
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb" ^
|
||||
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" ^
|
||||
-DLLVM_INCLUDE_TESTS=OFF ^
|
||||
-DLLVM_INCLUDE_EXAMPLES=OFF ^
|
||||
-DLLVM_INCLUDE_UTILS=OFF ^
|
||||
-DCLANG_DEFAULT_CXX_STDLIB=libc++ ^
|
||||
-DCLANG_DEFAULT_LINKER=lld ^
|
||||
-DCLANG_DEFAULT_RTLIB=compiler-rt ^
|
||||
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-windows-msvc ^
|
||||
-DLLVM_USE_CRT_RELEASE=MT ^
|
||||
-DLIBCXX_HAS_WIN32_THREAD_API=ON ^
|
||||
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON ^
|
||||
-DLIBCXX_CXX_ABI=libcxxabi ^
|
||||
-DLIBCXXABI_USE_LLVM_UNWINDER=ON ^
|
||||
-DLLDB_ENABLE_PYTHON=OFF ^
|
||||
-DLLDB_INCLUDE_TESTS=OFF ^
|
||||
"%LLVM_SOURCE_DIR%\llvm"
|
||||
|
||||
if errorlevel 1 (
|
||||
echo ERROR: CMake configuration failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo Building complete toolchain...
|
||||
echo ================================================================
|
||||
echo This will take 1-3 hours depending on your system.
|
||||
echo.
|
||||
|
||||
REM Build and install
|
||||
cmake --build . --config Release --target install --parallel %PARALLEL_JOBS%
|
||||
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Build failed!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo Verifying the final toolchain...
|
||||
echo ================================================================
|
||||
|
||||
REM Test the compiler
|
||||
echo #include ^<iostream^> > test.cpp
|
||||
echo int main() { std::cout ^<^< "Hello from libc++!\\n"; } >> test.cpp
|
||||
|
||||
"%INSTALL_DIR%\bin\clang++.exe" -std=c++20 test.cpp -o test.exe
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Compilation test failed!
|
||||
goto cleanup
|
||||
)
|
||||
|
||||
REM Test the debugger
|
||||
if exist "%INSTALL_DIR%\bin\lldb.exe" (
|
||||
"%INSTALL_DIR%\bin\lldb.exe" --version
|
||||
) else (
|
||||
echo WARNING: LLDB not built or not found
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ================================================================
|
||||
echo SUCCESS! Complete toolchain installed to: %INSTALL_DIR%
|
||||
echo.
|
||||
echo Toolchain contents:
|
||||
echo - clang++.exe (C++ compiler with libc++ as default)
|
||||
echo - lld-link.exe (LLD linker)
|
||||
echo - lldb.exe (Debugger)
|
||||
echo - include/c++/v1 (C++ standard library headers)
|
||||
echo - lib/clang/... (Built-in headers and libraries)
|
||||
echo.
|
||||
echo To use it, add to PATH: %INSTALL_DIR%\bin
|
||||
echo Test compilation: clang++ -std=c++20 your_file.cpp
|
||||
echo ================================================================
|
||||
|
||||
:cleanup
|
||||
REM Clean up test files
|
||||
if exist test.cpp del test.cpp
|
||||
if exist test.exe del test.exe
|
||||
if exist test.pdb del test.pdb
|
||||
Reference in New Issue
Block a user