Files
rustdesk-custom/scripts/build-windows.ps1
T
gusadmin 08321338d9 Добавить flutter_rust_bridge codegen перед сборкой
RustDesk не коммитит src/bridge_generated.rs -> cargo build падал
E0583/E0277. Встроил шаг codegen (FRB 1.80.1 + cargo-expand 1.0.95,
RUSTC_BOOTSTRAP=1) в build-windows.ps1; пины в upstream.txt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 15:09:39 +03:00

137 lines
8.7 KiB
PowerShell
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.
<#
Локальная сборка преднастроенного RustDesk-клиента под Windows (GUSIK-PC).
Клон rustdesk@пин -> preconfigure (вшить сервер+ключ) -> vcpkg install -> python build.py --flutter -> dist/.
Тулчейн (ставится один раз, см. docs/CODEMAP.md):
Rust 1.75 (rustup), VS Build Tools 2022 (MSVC+CMake+libclang), Flutter 3.24.5, vcpkg@пин.
Пути тулчейна можно переопределить через env FLUTTER_HOME / VCPKG_ROOT.
Запуск: pwsh -File scripts\build-windows.ps1
Опции: -Clean снести клон и склонировать заново
-SkipBuild только клон+preconfigure (без компиляции)
#>
[CmdletBinding()]
param([switch]$Clean, [switch]$SkipBuild)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$src = Join-Path $root 'rustdesk'
$dist = Join-Path $root 'dist'
# --- пины ---
$pins = @{}
Get-Content (Join-Path $root 'upstream.txt') | Where-Object { $_ -match '^\s*[A-Z]' } | ForEach-Object {
$k,$v = $_ -split '=',2; $pins[$k.Trim()] = $v.Trim()
}
$TAG=$pins['RUSTDESK_TAG']; $REPO=$pins['RUSTDESK_REPO']; $TRIPLET=$pins['VCPKG_TRIPLET']
Write-Host "== RustDesk custom build == tag=$TAG triplet=$TRIPLET" -ForegroundColor Cyan
# --- пути тулчейна ---
$FlutterHome = if ($env:FLUTTER_HOME) { $env:FLUTTER_HOME } else { 'S:\dev\flutter' }
$VcpkgRoot = if ($env:VCPKG_ROOT) { $env:VCPKG_ROOT } else { 'S:\dev\vcpkg' }
$BashExe = 'C:\Program Files\Git\bin\bash.exe'
# --- config/server.env ---
$envFile = Join-Path $root 'config\server.env'
if (-not (Test-Path $envFile)) { throw "Нет $envFile — скопируй config\server.env.example и заполни RUSTDESK_SERVER/RUSTDESK_PUB_KEY." }
Get-Content $envFile | Where-Object { $_ -match '^\s*[A-Z].*=' } | ForEach-Object {
$k,$v = $_ -split '=',2; Set-Item -Path "Env:$($k.Trim())" -Value $v.Trim()
}
if (-not $env:RUSTDESK_SERVER -or -not $env:RUSTDESK_PUB_KEY) { throw "В config\server.env не заданы RUSTDESK_SERVER/RUSTDESK_PUB_KEY." }
# --- импорт VS dev-env (MSVC/CMake/Windows SDK в PATH) ---
$vsw = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsPath = & $vsw -latest -products * -property installationPath
if (-not $vsPath) { throw "VS Build Tools не найдены (vswhere)." }
$vcvars = Join-Path $vsPath 'VC\Auxiliary\Build\vcvars64.bat'
Write-Host "Импорт VS dev-env: $vcvars" -ForegroundColor DarkCyan
cmd /c "`"$vcvars`" >nul && set" | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') { Set-Item "Env:$($matches[1])" $matches[2] } }
# CIDR в NO_PROXY (напр. 192.168.5.0/24) ломает WinHTTP-загрузчик vcpkg (WinHttpSetOption 87).
# У машины есть прямой интернет -> убираем прокси-env для процесса сборки (системные настройки не трогаем).
foreach ($p in 'HTTP_PROXY','HTTPS_PROXY','NO_PROXY','ALL_PROXY','http_proxy','https_proxy','no_proxy') { Set-Item "Env:$p" $null -EA SilentlyContinue }
# --- env тулчейна на сессию ---
$env:VCPKG_ROOT = $VcpkgRoot
$env:VCPKGRS_TRIPLET = $TRIPLET # для vcpkg-rs крейтов (статик-триплет)
# libclang для bindgen: VS-бандл его НЕ содержит -> ставим LLVM отдельно (S:\dev\LLVM).
$clangCands = @('S:\dev\LLVM\bin','C:\Program Files\LLVM\bin', (Join-Path $vsPath 'VC\Tools\Llvm\x64\bin'))
$env:LIBCLANG_PATH = ($clangCands | Where-Object { Test-Path (Join-Path $_ 'libclang.dll') } | Select-Object -First 1)
$env:PATH = "$FlutterHome\bin;$VcpkgRoot;$env:PATH"
# --- preflight ---
function Check($n,$ok,$hint){ if($ok){Write-Host " [ok] $n" -ForegroundColor Green}else{Write-Host " [нет] $n$hint" -ForegroundColor Yellow}; return $ok }
Write-Host "Preflight:" -ForegroundColor Cyan
$all = $true
$all = (Check 'git' ([bool](Get-Command git -EA SilentlyContinue)) 'Git for Windows') -and $all
$all = (Check 'git-bash' (Test-Path $BashExe) "нет $BashExe") -and $all
$all = (Check 'python' ([bool](Get-Command python -EA SilentlyContinue)) 'Python 3') -and $all
$all = (Check "rust $($pins['RUST_VERSION'])" ([bool]((rustup toolchain list) -match $pins['RUST_VERSION'])) "rustup toolchain install $($pins['RUST_VERSION'])") -and $all
$all = (Check 'flutter' (Test-Path "$FlutterHome\bin\flutter.bat") "Flutter в $FlutterHome") -and $all
$all = (Check 'vcpkg' (Test-Path "$VcpkgRoot\vcpkg.exe") "vcpkg в $VcpkgRoot") -and $all
$all = (Check 'cl.exe' ([bool](Get-Command cl.exe -EA SilentlyContinue)) 'MSVC из vcvars') -and $all
$all = (Check 'libclang' ([bool]$env:LIBCLANG_PATH -and (Test-Path (Join-Path $env:LIBCLANG_PATH 'libclang.dll'))) 'нет libclang.dll — установи LLVM 15 в S:\dev\LLVM') -and $all
if (-not $all) { throw "Тулчейн неполный — см. docs\CODEMAP.md." }
# --- клон/сброс до пина ---
if ($Clean -and (Test-Path $src)) { Remove-Item -Recurse -Force $src }
if (-not (Test-Path $src)) {
Write-Host "Клонирую rustdesk@$TAG (+submodule)..." -ForegroundColor Cyan
git clone --branch $TAG --depth 1 --recurse-submodules --shallow-submodules $REPO $src
} else {
Write-Host "Сбрасываю патчи до чистого $TAG..." -ForegroundColor Cyan
git -C $src checkout -- .
git -C $src submodule foreach --recursive 'git checkout -- .'
}
Push-Location $src; rustup override set $pins['RUST_VERSION'] | Out-Null; Pop-Location
# --- preconfigure: вшить сервер+ключ ---
Write-Host "Preconfigure (сервер+ключ)..." -ForegroundColor Cyan
$srcBash = $src -replace '\\','/' # git-bash не любит backslash в [ -f ... ]
$preBash = ("$root/scripts/preconfigure.sh") -replace '\\','/'
& $BashExe $preBash $srcBash
if ($LASTEXITCODE) { throw "preconfigure.sh упал ($LASTEXITCODE)" }
if ($SkipBuild) { Write-Host "SkipBuild — стоп после preconfigure." -ForegroundColor Yellow; return }
# --- flutter_rust_bridge codegen ---
# RustDesk НЕ коммитит src/bridge_generated.rs — его генерит flutter_rust_bridge_codegen.
# Без него cargo build падает: E0583 (нет модуля bridge_generated) + E0277 (EventToUI: IntoIntoDart).
Write-Host "flutter_rust_bridge codegen..." -ForegroundColor Cyan
Push-Location $src
$env:RUSTC_BOOTSTRAP = '1' # cargo-expand требует nightly-фич; на stable — через RUSTC_BOOTSTRAP
# Инструменты собираем stable-тулчейном (1.75 может не собрать свежие tool-крейты); бинарь standalone.
if (-not (Get-Command cargo-expand -EA SilentlyContinue)) {
cargo +stable install cargo-expand --version $pins['CARGO_EXPAND_VERSION'] --locked
}
$frb = Join-Path $env:USERPROFILE '.cargo\bin\flutter_rust_bridge_codegen.exe'
if (-not (Test-Path $frb)) {
cargo +stable install flutter_rust_bridge_codegen --version $pins['FRB_VERSION'] --features uuid --locked
}
Push-Location flutter; flutter pub get; Pop-Location
& $frb --rust-input ./src/flutter_ffi.rs --dart-output ./flutter/lib/generated_bridge.dart --c-output ./flutter/macos/Runner/bridge_generated.h
if (-not (Test-Path 'src/bridge_generated.rs')) { Pop-Location; throw "codegen не создал src/bridge_generated.rs" }
Write-Host " bridge_generated.rs создан." -ForegroundColor Green
Pop-Location
# --- vcpkg install (манифест из vcpkg.json; первый раз долго: ffmpeg/aom) ---
Write-Host "vcpkg install ($TRIPLET) — первый раз ОЧЕНЬ долго (ffmpeg/aom из исходников)..." -ForegroundColor Cyan
Push-Location $src
& "$VcpkgRoot\vcpkg.exe" install --triplet $TRIPLET --x-install-root="$VcpkgRoot\installed"
if ($LASTEXITCODE) { Pop-Location; throw "vcpkg install упал ($LASTEXITCODE)" }
Pop-Location
# --- сборка ---
Write-Host "python build.py --flutter..." -ForegroundColor Cyan
Push-Location $src
python build.py --flutter
$rc = $LASTEXITCODE
Pop-Location
if ($rc) { throw "build.py упал ($rc)" }
# --- артефакт ---
New-Item -ItemType Directory -Force $dist | Out-Null
$out = Get-ChildItem -Path $src -Filter 'rustdesk-*-install.exe' -EA SilentlyContinue | Select-Object -First 1
if (-not $out) { $out = Get-ChildItem -Path $src -Recurse -Filter 'rustdesk*.exe' -EA SilentlyContinue |
Where-Object { $_.FullName -match 'Release' } | Select-Object -First 1 }
if ($out) { Copy-Item $out.FullName (Join-Path $dist $out.Name) -Force; Write-Host "ГОТОВО: $(Join-Path $dist $out.Name)" -ForegroundColor Green }
else { Write-Host "Сборка ок, но .exe не найден — глянь $src (rustdesk-*-install.exe) и $src\flutter\build." -ForegroundColor Yellow }