Stabilize Conan build and remove stale TLS code
Simplifies the active Windows build path around Boost.Beast/OpenSSL, fixes VS2017/clang-cl compatibility, and removes unused BearSSL/WinHTTP remnants so the project builds and tests cleanly. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
106
build.bat
106
build.bat
@@ -3,47 +3,71 @@ chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "ROOT=%~dp0"
|
||||
set "TOOLS=%ROOT%tools\"
|
||||
if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%"
|
||||
set "TOOLS=%ROOT%\tools\"
|
||||
set "CMAKE_EXE=%TOOLS%cmake\bin\cmake.exe"
|
||||
set "NINJA_EXE=%TOOLS%ninja\ninja.exe"
|
||||
set "CLANG_EXE=%TOOLS%llvm\bin\clang-cl.exe"
|
||||
set "CLANGXX_EXE=%TOOLS%llvm\bin\clang-cl.exe"
|
||||
set "CONAN_EXE=%TOOLS%.venv\Scripts\conan.exe"
|
||||
|
||||
:: ============================================================
|
||||
:: 1. 检查 tools\ 工具链
|
||||
:: 1. 检查工具链,优先使用 tools\,缺失时回退到 PATH
|
||||
:: ============================================================
|
||||
echo [dstalk] 检查工具链...
|
||||
|
||||
if not exist "%TOOLS%cmake\bin\cmake.exe" (
|
||||
echo [ERROR] CMake 未找到,请先运行: tools\setup.bat
|
||||
if not exist "%CMAKE_EXE%" set "CMAKE_EXE=cmake"
|
||||
if not exist "%NINJA_EXE%" set "NINJA_EXE=ninja"
|
||||
if not exist "%CLANG_EXE%" (
|
||||
set "CLANG_EXE=clang-cl.exe"
|
||||
set "CLANGXX_EXE=clang-cl.exe"
|
||||
)
|
||||
if not exist "%CONAN_EXE%" set "CONAN_EXE=conan"
|
||||
|
||||
"%CMAKE_EXE%" --version >nul 2>&1 || (
|
||||
echo [ERROR] CMake 未找到,请先运行 tools\setup.bat 或加入 PATH
|
||||
pause & exit /b 1
|
||||
)
|
||||
if not exist "%TOOLS%ninja\ninja.exe" (
|
||||
echo [ERROR] Ninja 未找到,请先运行: tools\setup.bat
|
||||
"%NINJA_EXE%" --version >nul 2>&1 || (
|
||||
echo [ERROR] Ninja 未找到,请先运行 tools\setup.bat 或加入 PATH
|
||||
pause & exit /b 1
|
||||
)
|
||||
if not exist "%TOOLS%llvm\bin\clang.exe" (
|
||||
echo [ERROR] LLVM/Clang 未找到,请先运行: tools\setup.bat
|
||||
"%CLANG_EXE%" --version >nul 2>&1 || (
|
||||
echo [ERROR] LLVM/Clang 未找到,请先运行 tools\setup.bat 或加入 PATH
|
||||
pause & exit /b 1
|
||||
)
|
||||
if not exist "%TOOLS%.venv\Scripts\conan.exe" (
|
||||
echo [ERROR] Conan2 未找到,请先运行: tools\setup.bat
|
||||
for /f "tokens=1,2,3" %%a in ('"%CLANG_EXE%" --version 2^>nul') do (
|
||||
if "%%a %%b"=="clang version" set "CLANG_VERSION=%%c"
|
||||
)
|
||||
for /f "tokens=1 delims=." %%v in ("!CLANG_VERSION!") do set "CLANG_MAJOR=%%v"
|
||||
if "!CLANG_MAJOR!"=="" (
|
||||
echo [ERROR] 无法检测 Clang 版本
|
||||
pause & exit /b 1
|
||||
)
|
||||
"%CONAN_EXE%" --version >nul 2>&1 || (
|
||||
echo [ERROR] Conan2 未找到,请先运行 tools\setup.bat 或加入 PATH
|
||||
echo 需要已安装 Python 3.10+
|
||||
pause & exit /b 1
|
||||
)
|
||||
|
||||
:: ============================================================
|
||||
:: 2. 加载 tools\ 环境
|
||||
:: ============================================================
|
||||
call "%TOOLS%env.bat"
|
||||
if exist "%TOOLS%env.bat" call "%TOOLS%env.bat"
|
||||
|
||||
:: ============================================================
|
||||
:: 3. 检测并加载 MSVC 环境
|
||||
:: 2. 检测并加载 MSVC 环境
|
||||
:: ============================================================
|
||||
set "VCVARS="
|
||||
set "VS_YEAR="
|
||||
for %%v in (2022 2019 2017) do (
|
||||
for %%e in (Professional Community Enterprise BuildTools) do (
|
||||
if exist "C:\Program Files (x86)\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat" (
|
||||
set "VCVARS=C:\Program Files (x86)\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat"
|
||||
)
|
||||
if exist "C:\Program Files\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat" (
|
||||
set "VCVARS=C:\Program Files\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat"
|
||||
if not defined VCVARS (
|
||||
for %%e in (Professional Community Enterprise BuildTools) do (
|
||||
if not defined VCVARS if exist "C:\Program Files (x86)\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat" (
|
||||
set "VCVARS=C:\Program Files (x86)\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat"
|
||||
set "VS_YEAR=%%v"
|
||||
)
|
||||
if not defined VCVARS if exist "C:\Program Files\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat" (
|
||||
set "VCVARS=C:\Program Files\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat"
|
||||
set "VS_YEAR=%%v"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -55,43 +79,59 @@ if "%VCVARS%"=="" (
|
||||
)
|
||||
echo [dstalk] 加载 MSVC 环境...
|
||||
call "%VCVARS%" x64 >nul 2>&1
|
||||
set "MSVC_RUNTIME_VERSION=v143"
|
||||
set "MSVC_CONAN_VERSION=193"
|
||||
set "CONAN_CPPSTD=20"
|
||||
if "!VS_YEAR!"=="2019" (
|
||||
set "MSVC_RUNTIME_VERSION=v142"
|
||||
set "MSVC_CONAN_VERSION=192"
|
||||
)
|
||||
if "!VS_YEAR!"=="2017" (
|
||||
set "MSVC_RUNTIME_VERSION=v141"
|
||||
set "MSVC_CONAN_VERSION=191"
|
||||
set "CONAN_CPPSTD=17"
|
||||
)
|
||||
|
||||
echo [dstalk] MSVC runtime: !MSVC_RUNTIME_VERSION!
|
||||
|
||||
:: ============================================================
|
||||
:: 4. 强制使用 tools\ 内的编译器 (覆盖 MSVC 的 cl.exe)
|
||||
:: 3. 使用 Clang 编译器
|
||||
:: ============================================================
|
||||
set "CC=%TOOLS%llvm\bin\clang.exe"
|
||||
set "CXX=%TOOLS%llvm\bin\clang++.exe"
|
||||
set "CC=%CLANG_EXE%"
|
||||
set "CXX=%CLANGXX_EXE%"
|
||||
|
||||
cd /d "%ROOT%"
|
||||
|
||||
:: ============================================================
|
||||
:: 5. Conan 安装依赖
|
||||
:: 4. Conan 安装依赖
|
||||
:: ============================================================
|
||||
echo [dstalk] Conan 安装/刷新依赖...
|
||||
call "%TOOLS%.venv\Scripts\conan.exe" install deps/ -of build --build=missing -s compiler.cppstd=20 -c tools.cmake.cmaketoolchain:generator=Ninja
|
||||
call "%CONAN_EXE%" install deps/ -of build --build=missing -s compiler=msvc -s compiler.version=!MSVC_CONAN_VERSION! -s compiler.cppstd=!CONAN_CPPSTD! -s compiler.runtime=dynamic -s compiler.runtime_type=Release -c tools.cmake.cmaketoolchain:generator=Ninja
|
||||
if !errorlevel! neq 0 (
|
||||
echo [ERROR] Conan 安装失败
|
||||
pause & exit /b 1
|
||||
)
|
||||
|
||||
set "CONAN_GENERATORS=%ROOT%build\build\Release\generators"
|
||||
set "CONAN_GENERATORS=%ROOT%\build\build\Release\generators"
|
||||
|
||||
:: ============================================================
|
||||
:: 6. CMake 配置 + Ninja 编译
|
||||
:: 5. CMake 配置 + Ninja 编译
|
||||
:: ============================================================
|
||||
echo [dstalk] CMake 配置 + 编译...
|
||||
"%TOOLS%cmake\bin\cmake.exe" -S "%ROOT%" -B "%ROOT%build" -G Ninja ^
|
||||
-DCMAKE_C_COMPILER="%TOOLS%llvm\bin\clang.exe" ^
|
||||
-DCMAKE_CXX_COMPILER="%TOOLS%llvm\bin\clang++.exe" ^
|
||||
"%CMAKE_EXE%" -S "%ROOT%" -B "%ROOT%\build" -G Ninja ^
|
||||
-DCMAKE_MAKE_PROGRAM="%NINJA_EXE%" ^
|
||||
-DCMAKE_C_COMPILER="%CLANG_EXE%" ^
|
||||
-DCMAKE_CXX_COMPILER="%CLANGXX_EXE%" ^
|
||||
-DCMAKE_TOOLCHAIN_FILE="%CONAN_GENERATORS%\conan_toolchain.cmake" ^
|
||||
-DCMAKE_PREFIX_PATH="%CONAN_GENERATORS%" ^
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_BUILD_TYPE=Release ^
|
||||
-DDSTALK_BUILD_GUI=OFF
|
||||
if !errorlevel! neq 0 (
|
||||
echo [ERROR] CMake 配置失败
|
||||
pause & exit /b 1
|
||||
)
|
||||
|
||||
"%TOOLS%cmake\bin\cmake.exe" --build "%ROOT%build"
|
||||
"%CMAKE_EXE%" --build "%ROOT%\build"
|
||||
if !errorlevel! neq 0 (
|
||||
echo [ERROR] 编译失败
|
||||
pause & exit /b 1
|
||||
|
||||
Reference in New Issue
Block a user