feat: Windows build support, clippy zero-warnings, and dev tooling
New files: - prompts/win.md: Complete Windows execution guide covering build dependencies (libpq), compilation steps, runtime compatibility table (3rdparty.toml Windows URLs), shell command adaptations, GPU detection for LLM, directory structure, and troubleshooting - DEPENDENCIES.ps1: PowerShell script to auto-install PostgreSQL binaries and set PQ_LIB_DIR for Windows builds - restart.ps1: PowerShell restart script for Windows dev env Submodule updates: - botserver: Full Windows compatibility (21 files changed) including 3rdparty.toml Windows URLs, installer/cache/facade Windows process management, certificate generation, #[cfg(unix)] guards, and clippy zero-warnings refactors - bottest: #[cfg(unix)] guards for nix crate in postgres.rs, minio.rs, redis.rs service managers - botapp: Remove unused import (clippy auto-fix) Config: - .cargo/config.toml: Updated for Windows toolchain - Cargo.lock: Dependency updates
This commit is contained in:
parent
2fe4586be5
commit
8a6fec467c
8 changed files with 359 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
[build]
|
||||
rustc-wrapper = "sccache"
|
||||
# rustc-wrapper = "sccache"
|
||||
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "clang"
|
||||
|
|
|
|||
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -6671,12 +6671,10 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pq-sys"
|
||||
version = "0.7.5"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "574ddd6a267294433f140b02a726b0640c43cf7c6f717084684aaa3b285aba61"
|
||||
checksum = "f6cc05d7ea95200187117196eee9edd0644424911821aeb28a18ce60ea0b8793"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
|
|
|
|||
77
DEPENDENCIES.ps1
Normal file
77
DEPENDENCIES.ps1
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Installs runtime dependencies for General Bots on Windows.
|
||||
|
||||
.DESCRIPTION
|
||||
This script downloads and configures the system libraries required to build
|
||||
and run BotServer on Windows. It downloads PostgreSQL binaries (for libpq)
|
||||
and sets the PQ_LIB_DIR environment variable permanently.
|
||||
|
||||
.EXAMPLE
|
||||
PS> .\DEPENDENCIES.ps1
|
||||
#>
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# ─── COLORS ───
|
||||
function Write-Step { param($msg) Write-Host " * $msg" -ForegroundColor Green }
|
||||
function Write-Warn { param($msg) Write-Host " ! $msg" -ForegroundColor Yellow }
|
||||
function Write-Err { param($msg) Write-Host " x $msg" -ForegroundColor Red }
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " General Bots Runtime Dependencies" -ForegroundColor Green
|
||||
Write-Host " (Windows)" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# ─── PostgreSQL binaries (libpq.lib for Diesel ORM) ───
|
||||
$PgsqlDir = "C:\pgsql\pgsql"
|
||||
$PgsqlLib = "$PgsqlDir\lib\libpq.lib"
|
||||
$PgsqlZipUrl = "https://get.enterprisedb.com/postgresql/postgresql-17.4-1-windows-x64-binaries.zip"
|
||||
$PgsqlZip = "$env:TEMP\pgsql.zip"
|
||||
|
||||
if (Test-Path $PgsqlLib) {
|
||||
Write-Step "PostgreSQL binaries already present at $PgsqlDir"
|
||||
} else {
|
||||
Write-Host "`nDownloading PostgreSQL binaries..." -ForegroundColor Cyan
|
||||
Write-Host " URL: $PgsqlZipUrl"
|
||||
Write-Host " This may take a few minutes (~300MB)...`n"
|
||||
|
||||
Invoke-WebRequest -Uri $PgsqlZipUrl -OutFile $PgsqlZip -UseBasicParsing
|
||||
|
||||
Write-Host "Extracting to C:\pgsql ..."
|
||||
if (Test-Path "C:\pgsql") { Remove-Item "C:\pgsql" -Recurse -Force }
|
||||
Expand-Archive -Path $PgsqlZip -DestinationPath "C:\pgsql" -Force
|
||||
Remove-Item $PgsqlZip -Force -ErrorAction SilentlyContinue
|
||||
|
||||
if (Test-Path $PgsqlLib) {
|
||||
Write-Step "PostgreSQL binaries installed successfully."
|
||||
} else {
|
||||
Write-Err "Failed to find libpq.lib after extraction!"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Set PQ_LIB_DIR permanently for the current user
|
||||
$CurrentPqDir = [System.Environment]::GetEnvironmentVariable("PQ_LIB_DIR", "User")
|
||||
if ($CurrentPqDir -ne "$PgsqlDir\lib") {
|
||||
[System.Environment]::SetEnvironmentVariable("PQ_LIB_DIR", "$PgsqlDir\lib", "User")
|
||||
$env:PQ_LIB_DIR = "$PgsqlDir\lib"
|
||||
Write-Step "PQ_LIB_DIR set to '$PgsqlDir\lib' (User environment variable)"
|
||||
} else {
|
||||
Write-Step "PQ_LIB_DIR already configured."
|
||||
}
|
||||
|
||||
# ─── Summary ───
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " Dependencies installed!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "You can now build and run:" -ForegroundColor Cyan
|
||||
Write-Host " cargo build -p botserver"
|
||||
Write-Host " cargo build -p botui"
|
||||
Write-Host " .\restart.ps1"
|
||||
Write-Host ""
|
||||
Write-Host "NOTE: If this is the first time, restart your terminal" -ForegroundColor Yellow
|
||||
Write-Host " so PQ_LIB_DIR takes effect." -ForegroundColor Yellow
|
||||
2
botapp
2
botapp
|
|
@ -1 +1 @@
|
|||
Subproject commit 66ea6cffbc98b4c10449104806a80d368e3460d4
|
||||
Subproject commit ea625fa6b1e6617a71b7856337976b5d96600bee
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit ad4aca21ffec3de5db510317aa1e366a15c50499
|
||||
Subproject commit 3dfead5c044ccf2dbe036b709d5d0a36e3a39afa
|
||||
2
bottest
2
bottest
|
|
@ -1 +1 @@
|
|||
Subproject commit d03e13d2eb77ed0343509e0b55f50d17d511c612
|
||||
Subproject commit 8d2fabccabf8e989d2d45d6a8e349b43b45fd00c
|
||||
244
prompts/win.md
Normal file
244
prompts/win.md
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
# General Bots — Plano de Execução no Windows
|
||||
|
||||
## Pré-requisitos
|
||||
|
||||
- Windows 10/11 (x64)
|
||||
- Visual Studio Build Tools (com C++ workload) ou Visual Studio
|
||||
- Rust toolchain (`rustup` com `stable-x86_64-pc-windows-msvc`)
|
||||
- Git para Windows
|
||||
|
||||
---
|
||||
|
||||
## 1. Dependências de Build
|
||||
|
||||
### 1.1 PostgreSQL (libpq.lib para Diesel ORM)
|
||||
|
||||
O BotServer usa Diesel com backend Postgres. No Windows, o linker precisa de `libpq.lib`.
|
||||
|
||||
```powershell
|
||||
# Baixar binários do PostgreSQL (não precisa instalar o serviço)
|
||||
Invoke-WebRequest -Uri "https://get.enterprisedb.com/postgresql/postgresql-17.4-1-windows-x64-binaries.zip" -OutFile "$env:TEMP\pgsql.zip" -UseBasicParsing
|
||||
|
||||
# Extrair para C:\pgsql
|
||||
Expand-Archive -Path "$env:TEMP\pgsql.zip" -DestinationPath "C:\pgsql" -Force
|
||||
|
||||
# Configurar variável de ambiente permanente
|
||||
[System.Environment]::SetEnvironmentVariable("PQ_LIB_DIR", "C:\pgsql\pgsql\lib", "User")
|
||||
$env:PQ_LIB_DIR = "C:\pgsql\pgsql\lib"
|
||||
$env:PATH = "C:\pgsql\pgsql\bin;$env:PATH"
|
||||
```
|
||||
|
||||
Ou simplesmente execute:
|
||||
```powershell
|
||||
.\DEPENDENCIES.ps1
|
||||
```
|
||||
|
||||
### 1.2 sccache (opcional)
|
||||
|
||||
O `.cargo/config.toml` referencia `sccache`. Se não estiver instalado, comente a linha:
|
||||
```toml
|
||||
# [build]
|
||||
# rustc-wrapper = "sccache"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Compilação
|
||||
|
||||
```powershell
|
||||
# Garantir que PQ_LIB_DIR está configurado
|
||||
$env:PQ_LIB_DIR = "C:\pgsql\pgsql\lib"
|
||||
|
||||
# Build do botserver
|
||||
cargo build -p botserver
|
||||
|
||||
# Build do botui (interface desktop Tauri)
|
||||
cargo build -p botui
|
||||
```
|
||||
|
||||
### Correções de compilação aplicadas
|
||||
|
||||
| Arquivo | Problema | Correção |
|
||||
|---------|----------|----------|
|
||||
| `bootstrap.rs` | `use std::os::unix::fs::PermissionsExt` | Envolvido com `#[cfg(unix)]` |
|
||||
| `antivirus.rs` | `error!` macro não importada | Adicionado `use tracing::error` |
|
||||
| `installer.rs` | `check_root()` só existe no Unix | Adicionado `check_admin()` para Windows com `#[cfg(windows)]` |
|
||||
| `installer.rs` | `SUDOERS_CONTENT` não usado no Windows | Envolvido com `#[cfg(not(windows))]` |
|
||||
| `facade.rs` | `make_executable` param `path` não usado | Renomeado para `_path` no Windows |
|
||||
|
||||
---
|
||||
|
||||
## 3. Compatibilidade de Runtime (3rdparty.toml)
|
||||
|
||||
O `3rdparty.toml` agora tem entradas `_windows` para cada componente:
|
||||
|
||||
| Componente | Linux | Windows |
|
||||
|------------|-------|---------|
|
||||
| `drive` | `minio` (linux-amd64) | `minio.exe` (windows-amd64) |
|
||||
| `tables` | `postgresql-*-linux-gnu.tar.gz` | `postgresql-*-windows-x64-binaries.zip` |
|
||||
| `cache` | `valkey-*-jammy-x86_64.tar.gz` | `memurai-developer.msi` |
|
||||
| `llm` | `llama-*-ubuntu-x64.zip` | `llama-*-win-cpu-x64.zip` (ou CUDA/Vulkan) |
|
||||
| `email` | `stalwart-mail-*-linux.tar.gz` | `stalwart-mail-*-windows.zip` |
|
||||
| `proxy` | `caddy_*_linux_amd64.tar.gz` | `caddy_*_windows_amd64.zip` |
|
||||
| `directory` | `zitadel-linux-amd64.tar.gz` | `zitadel-windows-amd64.zip` |
|
||||
| `alm` | `forgejo-*-linux-amd64` | `forgejo-*-windows-amd64.exe` |
|
||||
| `alm_ci` | `forgejo-runner-*-linux-amd64` | `forgejo-runner-*-windows-amd64.exe` |
|
||||
| `dns` | `coredns_*_linux_amd64.tgz` | `coredns_*_windows_amd64.tgz` |
|
||||
| `meet` | `livekit_*_linux_amd64.tar.gz` | `livekit_*_windows_amd64.zip` |
|
||||
| `table_editor` | `nocodb-linux-x64` | `nocodb-win-x64.exe` |
|
||||
| `vector_db` | `qdrant-*-linux-gnu.tar.gz` | `qdrant-*-windows-msvc.zip` |
|
||||
| `timeseries_db` | `influxdb2-*-linux-amd64.tar.gz` | `influxdb2-*-windows-amd64.zip` |
|
||||
| `vault` | `vault_*_linux_amd64.zip` | `vault_*_windows_amd64.zip` |
|
||||
| `observability` | `vector-*-linux-gnu.tar.gz` | `vector-*-windows-msvc.zip` |
|
||||
|
||||
A seleção é automática via `get_component_url()` em `installer.rs` que busca `{name}_windows` primeiro.
|
||||
|
||||
---
|
||||
|
||||
## 4. Adaptações de Código para Windows
|
||||
|
||||
### 4.1 Execução de Comandos Shell
|
||||
|
||||
| Contexto | Linux | Windows |
|
||||
|----------|-------|---------|
|
||||
| `run_commands_with_password()` | `bash -c "{cmd}"` | `powershell -NoProfile -Command "{cmd}"` |
|
||||
| `start()` (spawnar processos) | `sh -c "{exec_cmd}"` | `powershell -NoProfile -Command "{exec_cmd}"` |
|
||||
| `safe_sh_command()` | `sh -c` | `powershell -NoProfile -Command` |
|
||||
|
||||
### 4.2 Gerenciamento de Processos
|
||||
|
||||
| Ação | Linux | Windows |
|
||||
|------|-------|---------|
|
||||
| Matar processos | `pkill -9 -f {name}` | `taskkill /F /IM {name}*` |
|
||||
| Verificar processo | `pgrep -f {name}` | `Get-Process \| Where-Object { $_.ProcessName -like '*{name}*' }` |
|
||||
|
||||
### 4.3 Health Checks (fallback quando curl não está disponível)
|
||||
|
||||
| Check | Linux | Windows |
|
||||
|-------|-------|---------|
|
||||
| Porta aberta | `nc -z -w 1 127.0.0.1 {port}` | `(Test-NetConnection -ComputerName 127.0.0.1 -Port {port}).TcpTestSucceeded` |
|
||||
|
||||
### 4.4 Extração de Arquivos
|
||||
|
||||
| Formato | Linux | Windows |
|
||||
|---------|-------|---------|
|
||||
| `.zip` | `unzip -o -q {file}` | `Expand-Archive -Path '{file}' -DestinationPath '{dest}' -Force` |
|
||||
| `.tar.gz` | `tar -xzf {file}` | `tar -xzf {file}` (Windows 10+ tem tar nativo) |
|
||||
|
||||
---
|
||||
|
||||
## 5. Execução
|
||||
|
||||
### 5.1 Modo CLI (gerenciar componentes)
|
||||
```powershell
|
||||
$env:PQ_LIB_DIR = "C:\pgsql\pgsql\lib"
|
||||
$env:PATH = "C:\pgsql\pgsql\bin;$env:PATH"
|
||||
|
||||
# Instalar um componente específico
|
||||
.\target\debug\botserver.exe install vault
|
||||
|
||||
# Listar componentes
|
||||
.\target\debug\botserver.exe list
|
||||
|
||||
# Iniciar componentes
|
||||
.\target\debug\botserver.exe start
|
||||
|
||||
# Ver status
|
||||
.\target\debug\botserver.exe status
|
||||
```
|
||||
|
||||
### 5.2 Modo Servidor (bootstrap completo + HTTP)
|
||||
```powershell
|
||||
$env:PQ_LIB_DIR = "C:\pgsql\pgsql\lib"
|
||||
$env:PATH = "C:\pgsql\pgsql\bin;$env:PATH"
|
||||
|
||||
# Executa bootstrap (baixa/instala todos os componentes) + inicia servidor HTTP
|
||||
.\target\debug\botserver.exe
|
||||
```
|
||||
|
||||
O bootstrap automático:
|
||||
1. Baixa e instala Vault, PostgreSQL, Valkey, MinIO, Zitadel, LLM, etc.
|
||||
2. Gera certificados TLS
|
||||
3. Inicializa o banco de dados
|
||||
4. Inicia o servidor HTTP na porta **5858**
|
||||
|
||||
Acesse: **http://localhost:5858**
|
||||
|
||||
### 5.3 Via restart.ps1
|
||||
```powershell
|
||||
.\restart.ps1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Detecção Automática de GPU (LLM)
|
||||
|
||||
O sistema detecta automaticamente:
|
||||
- **CUDA 13.x** → `llama-*-win-cuda-13.1-x64.zip`
|
||||
- **CUDA 12.x** → `llama-*-win-cuda-12.4-x64.zip`
|
||||
- **Vulkan SDK** → `llama-*-win-vulkan-x64.zip`
|
||||
- **CPU only** → `llama-*-win-cpu-x64.zip`
|
||||
- **ARM64** → `llama-*-win-cpu-arm64.zip`
|
||||
|
||||
---
|
||||
|
||||
## 7. Estrutura de Diretórios
|
||||
|
||||
```
|
||||
botserver-stack/
|
||||
├── bin/ # Binários dos componentes
|
||||
│ ├── vault/
|
||||
│ ├── tables/ # PostgreSQL
|
||||
│ ├── cache/ # Valkey/Memurai
|
||||
│ ├── drive/ # MinIO
|
||||
│ ├── directory/ # Zitadel
|
||||
│ ├── llm/ # llama.cpp
|
||||
│ └── ...
|
||||
├── conf/ # Configurações
|
||||
│ ├── vault/
|
||||
│ ├── system/certificates/
|
||||
│ └── ...
|
||||
├── data/ # Dados persistentes
|
||||
│ ├── vault/
|
||||
│ ├── tables/pgdata/
|
||||
│ └── ...
|
||||
└── logs/ # Logs de cada componente
|
||||
├── vault/
|
||||
├── tables/
|
||||
└── ...
|
||||
|
||||
botserver-installers/ # Cache de downloads (reutilizado)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. Troubleshooting
|
||||
|
||||
### Erro: `LNK1181: libpq.lib não encontrado`
|
||||
```powershell
|
||||
$env:PQ_LIB_DIR = "C:\pgsql\pgsql\lib"
|
||||
# Ou execute .\DEPENDENCIES.ps1
|
||||
```
|
||||
|
||||
### Erro: `sccache não encontrado`
|
||||
Comente no `.cargo/config.toml`:
|
||||
```toml
|
||||
# [build]
|
||||
# rustc-wrapper = "sccache"
|
||||
```
|
||||
|
||||
### Erro: `Path traversal detected`
|
||||
Limpe o cache e recompile:
|
||||
```powershell
|
||||
Remove-Item -Path ".\botserver-stack" -Recurse -Force
|
||||
Remove-Item -Path ".\botserver-installers" -Recurse -Force
|
||||
cargo clean -p botserver
|
||||
cargo build -p botserver
|
||||
```
|
||||
|
||||
### Componentes baixam versão Linux
|
||||
Recompile o botserver para que o `3rdparty.toml` embutido seja atualizado:
|
||||
```powershell
|
||||
cargo clean -p botserver
|
||||
cargo build -p botserver
|
||||
```
|
||||
32
restart.ps1
Normal file
32
restart.ps1
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
$ErrorActionPreference = "Continue"
|
||||
|
||||
Write-Host "Stopping..."
|
||||
Stop-Process -Name "botserver" -Force -ErrorAction SilentlyContinue
|
||||
Stop-Process -Name "botui" -Force -ErrorAction SilentlyContinue
|
||||
Stop-Process -Name "rustc" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "Cleaning..."
|
||||
Remove-Item -Path "botserver.log", "botui.log" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "Building..."
|
||||
cargo build -p botserver
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "Failed to build botserver"; exit 1 }
|
||||
|
||||
cargo build -p botui
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "Failed to build botui"; exit 1 }
|
||||
|
||||
Write-Host "Starting botserver..."
|
||||
$env:PORT = "8080"
|
||||
$env:RUST_LOG = "debug"
|
||||
$env:PATH += ";C:\pgsql\pgsql\bin;C:\pgsql\pgsql\lib"
|
||||
$botserverProcess = Start-Process -PassThru -NoNewWindow -FilePath ".\target\debug\botserver.exe" -ArgumentList "--noconsole" -RedirectStandardOutput "botserver.log" -RedirectStandardError "botserver.log"
|
||||
Write-Host " PID: $($botserverProcess.Id)"
|
||||
|
||||
Write-Host "Starting botui..."
|
||||
$env:BOTSERVER_URL = "http://localhost:8080"
|
||||
$env:PORT = "3000"
|
||||
$botuiProcess = Start-Process -PassThru -NoNewWindow -FilePath ".\target\debug\botui.exe" -RedirectStandardOutput "botui.log" -RedirectStandardError "botui.log"
|
||||
Write-Host " PID: $($botuiProcess.Id)"
|
||||
|
||||
Write-Host "Done. Logs are being written to botserver.log and botui.log"
|
||||
Write-Host "To view logs, you can use: Get-Content botserver.log -Wait"
|
||||
Loading…
Add table
Reference in a new issue