-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_custom.ps1
177 lines (146 loc) · 5.35 KB
/
build_custom.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
Clear-Host
# Set environment variables
$env:LIBCLANG_PATH = "C:\Program Files\LLVM\bin"
$download = 'C:\download'
$buildir = 'C:\buildrustdesk'
$rustdeskPath = Join-Path $buildir "rustdesk"
$releasePath = Join-Path $rustdeskPath "flutter\build\windows\x64\runner\Release"
# Increase memory limits
$env:DART_VM_OPTIONS = "--old_gen_heap_size=4096 --max_old_space_size=4096"
$env:NODE_OPTIONS = "--max_old_space_size=4096"
# Clean up temporary files
Write-Host "Cleaning up temporary files..."
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
[System.GC]::Collect()
# Create necessary directories
Write-Host "Creating necessary directories..."
@($download, $buildir) | ForEach-Object {
if (-not (Test-Path $_)) {
try {
New-Item -ItemType Directory -Force -Path $_
Write-Host "Created directory: $_"
} catch {
Write-Warning "Failed to create directory: $_"
Write-Warning $_.Exception.Message
exit 1
}
}
}
# Clone RustDesk if not exists
if (-not (Test-Path $rustdeskPath)) {
Write-Host "Cloning RustDesk repository..."
git clone https://github.com/rustdesk/rustdesk.git $rustdeskPath
}
# Change to rustdesk directory
Set-Location $rustdeskPath
# Install and configure Rust toolchain
Write-Host "Installing and configuring Rust toolchain..."
rustup toolchain install 1.75 --target x86_64-pc-windows-msvc --component rustfmt --profile minimal --no-self-update
rustup default 1.75
# Display Rust version information
Write-Host "Rust version information:"
rustc +1.75 --version --verbose
rustup show
# Check vcpkg dependencies
$vcpkgPath = "C:\libs\vcpkg\vcpkg.exe"
$installRoot = "C:\libs\vcpkg\installed"
if (!(Test-Path $vcpkgPath)) {
Write-Host "Error: vcpkg executable not found at $vcpkgPath"
exit 1
}
# List of packages to check
$packagesToCheck = @(
"openssl",
"libvpx",
"libyuv",
"opus"
# Add other specific packages RustDesk might need
)
$needsInstall = $false
foreach ($package in $packagesToCheck) {
$packagePath = Join-Path $installRoot "x64-windows-static\include\$package"
if (!(Test-Path $packagePath)) {
Write-Host "Package $package is missing. Needs installation."
$needsInstall = $true
break
}
}
if ($needsInstall) {
Write-Host "Installing vcpkg dependencies..."
& $vcpkgPath install --triplet x64-windows-static --x-install-root="$installRoot"
if ($LASTEXITCODE -ne 0) {
Write-Host "vcpkg installation failed. Checking log files..."
Get-ChildItem -Path "C:\libs\vcpkg" -Recurse -Filter "*.log" | ForEach-Object {
Write-Host "Log file: $($_.FullName)"
Write-Host "======"
Get-Content $_.FullName
Write-Host "======"
Write-Host ""
}
exit 1
}
} else {
Write-Host "All required vcpkg packages are already installed."
}
# Clean and prepare Flutter environment
Write-Host "Preparing Flutter environment..."
Set-Location (Join-Path $rustdeskPath "flutter")
flutter clean
Remove-Item -Path ".dart_tool" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "build" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "lib/generated_bridge*" -Force -ErrorAction SilentlyContinue
flutter pub cache clean
# Install flutter_rust_bridge_codegen
Write-Host "Installing flutter_rust_bridge_codegen..."
cargo install flutter_rust_bridge_codegen --version 1.80.1 --features "uuid" --force --locked
Push-Location "C:\buildrustdesk\rustdesk\flutter"
flutter pub get
Pop-Location
# Generate bridge code
Write-Host "Generating bridge code..."
flutter_rust_bridge_codegen --rust-input ..\src\flutter_ffi.rs --dart-output .\lib\generated_bridge.dart
# Extract and copy WindowInjection.dll
Write-Host "Extracting WindowInjection.dll..."
$windowsDllZipPath = "f:\rustdesk_builder_windows\WindowInjection.zip"
$windowsDllPath = Join-Path $download "WindowInjection.dll"
try {
# Ensure the download directory exists
if (-not (Test-Path $download)) {
New-Item -ItemType Directory -Force -Path $download
}
# Extract the DLL
Write-Host "Extracting from: $windowsDllZipPath"
Write-Host "Extracting to: $download"
Expand-Archive -Path $windowsDllZipPath -DestinationPath $download -Force
# Create release directory structure
New-Item -ItemType Directory -Force -Path $releasePath
# Copy WindowInjection.dll
Write-Host "Copying WindowInjection.dll to: $releasePath"
Copy-Item -Path $windowsDllPath -Destination $releasePath -Force
} catch {
Write-Warning "Failed to extract or copy WindowInjection.dll"
Write-Warning $_.Exception.Message
exit 1
}
# Run build script
Write-Host "Running build script..."
$env:RUST_BACKTRACE = "full"
$env:RUST_LOG = "debug"
Set-Location $rustdeskPath
python build.py --portable --flutter
# Copy debug DLLs
Write-Host "Copying debug DLLs..."
$debugDlls = @(
"vcruntime140.dll",
"vcruntime140_1.dll",
"msvcp140.dll"
)
foreach ($dll in $debugDlls) {
$sourcePath = "C:\Windows\System32\$dll"
if (Test-Path $sourcePath) {
Copy-Item -Path $sourcePath -Destination "$releasePath" -Force
Write-Host "Copied $dll"
}
}
Write-Host "Build process completed! The executable should be in: $releasePath"
Write-Host "Try running the executable with: Start-Process '$releasePath\rustdesk.exe' -NoNewWindow -Wait"