Files
dstalk/tools/setup.bat
2026-05-26 09:28:42 +08:00

165 lines
5.7 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
set "TOOLS=%~dp0"
echo ============================================
echo dstalk 工具链 — 便携安装
echo 目标: %TOOLS%
echo ============================================
echo.
:: ============================================================
:: 0. 检测 Visual Studio Build Tools (MSVC 头文件/库)
:: 这是 Windows C++ 编译的硬依赖, 需单独安装
:: ============================================================
echo [0/5] 检测 MSVC (Visual Studio Build Tools) ...
set "VS_FOUND="
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 "VS_FOUND=%%v %%e"
if exist "C:\Program Files\Microsoft Visual Studio\%%v\%%e\VC\Auxiliary\Build\vcvarsall.bat" set "VS_FOUND=%%v %%e"
)
)
if defined VS_FOUND (
echo [OK] 已安装: !VS_FOUND!
) else (
echo [WARN] 未找到 Visual Studio Build Tools
echo 这是 C++ 编译必需的 (提供 vcruntime.h / msvcrt.lib 等)
echo.
echo 请下载安装: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
echo 安装时勾选 "使用 C++ 的桌面开发" 工作负载
echo.
echo 安装完成后重新运行 setup.bat
pause
exit /b 1
)
:: ============================================================
:: 1. CMake (便携 zip, ~50MB)
:: ============================================================
echo [1/5] CMake ...
if exist "%TOOLS%cmake\bin\cmake.exe" (
echo [OK] 已存在
) else (
mkdir "%TOOLS%cmake" 2>nul
set "URL=https://github.com/Kitware/CMake/releases/download/v3.31.6/cmake-3.31.6-windows-x86_64.zip"
echo 下载中...
curl -L -o "%TOOLS%cmake\cmake.zip" "!URL!" 2>nul
if !errorlevel! neq 0 (
set "URL=https://github.com/Kitware/CMake/releases/download/v3.30.3/cmake-3.30.3-windows-x86_64.zip"
curl -L -o "%TOOLS%cmake\cmake.zip" "!URL!" 2>nul
)
if !errorlevel! neq 0 (
echo [FAIL] 请手动下载: https://cmake.org/download/
echo 选择 cmake-*-windows-x86_64.zip 解压到 %TOOLS%cmake\
) else (
powershell -Command "Expand-Archive -Force '%TOOLS%cmake\cmake.zip' '%TOOLS%cmake\tmp\'"
for /d %%d in ("%TOOLS%cmake\tmp\cmake-*") do xcopy /E /Y "%%d\*" "%TOOLS%cmake\" >nul
rmdir /s /q "%TOOLS%cmake\tmp" 2>nul
del "%TOOLS%cmake\cmake.zip" 2>nul
echo [OK] CMake
)
)
:: ============================================================
:: 2. Ninja (单文件 ~300KB)
:: ============================================================
echo [2/5] Ninja ...
if exist "%TOOLS%ninja\ninja.exe" (
echo [OK] 已存在
) else (
mkdir "%TOOLS%ninja" 2>nul
curl -L -o "%TOOLS%ninja\ninja.zip" "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-win64.zip" 2>nul
if !errorlevel! neq 0 (
curl -L -o "%TOOLS%ninja\ninja.zip" "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win64.zip" 2>nul
)
if !errorlevel! neq 0 (
echo [FAIL] 请手动下载: https://github.com/ninja-build/ninja/releases
) else (
powershell -Command "Expand-Archive -Force '%TOOLS%ninja\ninja.zip' '%TOOLS%ninja\'"
del "%TOOLS%ninja\ninja.zip" 2>nul
echo [OK] Ninja
)
)
:: ============================================================
:: 3. LLVM/Clang (便携, ~1.2GB)
:: ============================================================
echo [3/5] LLVM/Clang ...
if exist "%TOOLS%llvm\bin\clang.exe" (
echo [OK] 已存在
) else (
mkdir "%TOOLS%llvm" 2>nul
echo 下载中 (~1.2GB, 耐心等待)...
curl -L -o "%TOOLS%llvm\llvm.exe" "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.7/LLVM-19.1.7-win64.exe" 2>nul
if !errorlevel! neq 0 (
echo [FAIL] 请手动下载: https://github.com/llvm/llvm-project/releases
echo 选择 LLVM-*-win64.exe, 运行后复制安装目录到 %TOOLS%llvm\
) else (
"%TOOLS%llvm\llvm.exe" /S /D="%TOOLS%llvm"
del "%TOOLS%llvm\llvm.exe" 2>nul
echo [OK] LLVM
)
)
:: ============================================================
:: 4. Python venv + Conan2
:: ============================================================
echo [4/5] Python venv + Conan2 ...
set "PYTHON="
for %%p in (python python3) do (
if not defined PYTHON (
where %%p >nul 2>nul
if !errorlevel! equ 0 set "PYTHON=%%p"
)
)
if not defined PYTHON (
echo [FAIL] 未找到 Python 3.10+
echo 请先安装 Python并确保 python.exe 在 PATH 中
pause
exit /b 1
)
if not exist "%TOOLS%.venv\Scripts\python.exe" (
call %PYTHON% -m venv "%TOOLS%.venv"
if !errorlevel! neq 0 (
echo [FAIL] 创建 Python venv 失败
pause
exit /b 1
)
)
call "%TOOLS%.venv\Scripts\python.exe" -m pip install --upgrade pip
if !errorlevel! neq 0 (
echo [FAIL] pip 更新失败
pause
exit /b 1
)
call "%TOOLS%.venv\Scripts\python.exe" -m pip install "conan>=2,<3"
if !errorlevel! neq 0 (
echo [FAIL] Conan2 安装失败
pause
exit /b 1
)
echo [OK] Conan2
:: ============================================================
:: 5. 配置 Conan profile
:: ============================================================
echo [5/5] 配置 Conan ...
call "%TOOLS%.venv\Scripts\conan.exe" profile detect --force 2>nul
if errorlevel 1 (
echo [WARN] Conan profile 配置失败 (可能首次运行需手动配置)
)
echo.
echo ============================================
echo 完成! 所有工具已就绪
echo ============================================
echo.
echo 下一步: 回到项目根目录运行 build.bat
pause