Files
dstalk/build.bat
XiuChengWu 16475ca3fe Fix streaming and file IO edge cases
Repair streaming callback/error handling and make file/session handling safer so the core API behaves correctly under real usage.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 19:26:47 +08:00

107 lines
3.6 KiB
Batchfile

@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
set "ROOT=%~dp0"
set "TOOLS=%ROOT%tools\"
:: ============================================================
:: 1. 检查 tools\ 工具链
:: ============================================================
echo [dstalk] 检查工具链...
if not exist "%TOOLS%cmake\bin\cmake.exe" (
echo [ERROR] CMake 未找到,请先运行: tools\setup.bat
pause & exit /b 1
)
if not exist "%TOOLS%ninja\ninja.exe" (
echo [ERROR] Ninja 未找到,请先运行: tools\setup.bat
pause & exit /b 1
)
if not exist "%TOOLS%llvm\bin\clang.exe" (
echo [ERROR] LLVM/Clang 未找到,请先运行: tools\setup.bat
pause & exit /b 1
)
if not exist "%TOOLS%conan2\conan.exe" (
echo [ERROR] Conan2 未找到,请先运行: tools\setup.bat
pause & exit /b 1
)
:: ============================================================
:: 2. 加载 tools\ 环境
:: ============================================================
call "%TOOLS%env.bat"
:: ============================================================
:: 3. 检测并加载 MSVC 环境
:: ============================================================
set "VCVARS="
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 "%VCVARS%"=="" (
echo [ERROR] 未找到 Visual Studio Build Tools
echo 请安装: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
pause & exit /b 1
)
echo [dstalk] 加载 MSVC 环境...
call "%VCVARS%" x64 >nul 2>&1
:: ============================================================
:: 4. 强制使用 tools\ 内的编译器 (覆盖 MSVC 的 cl.exe)
:: ============================================================
set "CC=%TOOLS%llvm\bin\clang.exe"
set "CXX=%TOOLS%llvm\bin\clang++.exe"
cd /d "%ROOT%"
:: ============================================================
:: 5. Conan 安装依赖
:: ============================================================
if not exist "%ROOT%build\conan_toolchain.cmake" (
echo [dstalk] Conan 安装依赖...
call "%TOOLS%conan2\conan.exe" install deps/ -of build --build=missing
if !errorlevel! neq 0 (
echo [ERROR] Conan 安装失败
pause & exit /b 1
)
) else (
echo [dstalk] Conan 依赖已就绪
)
:: ============================================================
:: 6. 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" ^
-DCMAKE_TOOLCHAIN_FILE="%ROOT%build\conan_toolchain.cmake" ^
-DCMAKE_BUILD_TYPE=Release
if !errorlevel! neq 0 (
echo [ERROR] CMake 配置失败
pause & exit /b 1
)
"%TOOLS%cmake\bin\cmake.exe" --build "%ROOT%build"
if !errorlevel! neq 0 (
echo [ERROR] 编译失败
pause & exit /b 1
)
echo.
echo ============================================
echo 编译成功!
echo build\dstalk-core\dstalk.dll
echo build\dstalk-cli\dstalk-cli.exe
echo ============================================
pause