forked from IvanMurzak/Unity-MCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-all.ps1
More file actions
159 lines (131 loc) · 4.85 KB
/
build-all.ps1
File metadata and controls
159 lines (131 loc) · 4.85 KB
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
#!/usr/bin/env pwsh
# Universal PowerShell script to build self-contained executables for all platforms
# Works on Windows, macOS, and Linux with PowerShell Core
param(
[string]$Configuration = "Release",
[string]$ProjectFile = "com.IvanMurzak.Unity.MCP.Server.csproj",
[string[]]$Platforms = @()
)
Write-Host "Building self-contained executables..." -ForegroundColor Green
# Root output directory (relative to this script location)
$PublishRoot = Join-Path $PSScriptRoot "publish"
if (Test-Path $PublishRoot) {
Write-Host "Cleaning existing publish folder..." -ForegroundColor Cyan
try {
Remove-Item $PublishRoot -Recurse -Force -ErrorAction Stop
}
catch {
Write-Host "Failed to clean publish folder: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
}
New-Item -ItemType Directory -Path $PublishRoot | Out-Null
$allRuntimes = @(
"win-x64",
"win-x86",
"win-arm64",
"linux-x64",
"linux-arm64",
"osx-x64",
"osx-arm64"
)
$runtimes = if ($Platforms.Count -gt 0) {
$allRuntimes | Where-Object { $_ -in $Platforms }
} else {
$allRuntimes
}
if ($runtimes.Count -eq 0 -and $Platforms.Count -gt 0) {
Write-Host "No valid runtimes found matching: $($Platforms -join ', ')" -ForegroundColor Red
Write-Host "Available runtimes: $($allRuntimes -join ', ')" -ForegroundColor Cyan
exit 1
}
Write-Host "Target runtimes: $($runtimes -join ', ')" -ForegroundColor Cyan
$success = 0
$failed = 0
foreach ($runtime in $runtimes) {
Write-Host "Building for $runtime..." -ForegroundColor Yellow
$outputPath = Join-Path $PublishRoot $runtime
if (-not (Test-Path $outputPath)) { New-Item -ItemType Directory -Path $outputPath | Out-Null }
$publishArgs = @(
"publish",
$ProjectFile,
"-c", $Configuration,
"-r", $runtime,
"--self-contained", "true",
"-p:PublishSingleFile=true",
"-o", $outputPath
)
Write-Host "Executing: dotnet $($publishArgs -join ' ')" -ForegroundColor DarkGray
try {
dotnet @publishArgs
$exitCode = $LASTEXITCODE
}
catch {
Write-Host "Error executing dotnet publish: $($_.Exception.Message)" -ForegroundColor Red
$exitCode = 1
}
if ($exitCode -eq 0) {
Write-Host "Successfully built $runtime" -ForegroundColor Green
$success++
}
else {
Write-Host "Failed to build $runtime (exit code: $exitCode)" -ForegroundColor Red
$failed++
}
}
Write-Host "`nBuild Summary:" -ForegroundColor Cyan
Write-Host "Success: $success" -ForegroundColor Green
Write-Host "Failed: $failed" -ForegroundColor Red
if ($failed -gt 0) {
Write-Host "`nSome builds failed. Check the output above." -ForegroundColor Yellow
exit 1
}
Write-Host "`nAll builds completed successfully!" -ForegroundColor Green
Write-Host "Executables are located in: $PublishRoot" -ForegroundColor Yellow
Write-Host "Per-platform folders: ./publish/{runtime}/" -ForegroundColor Yellow
Write-Host "`nCreating zip archives for each runtime..." -ForegroundColor Cyan
$zipSuccess = 0
$zipFailed = 0
foreach ($runtime in $runtimes) {
$runtimePath = Join-Path $PublishRoot $runtime
if (Test-Path $runtimePath) {
Write-Host "Creating zip for $runtime..." -ForegroundColor Yellow
$zipName = "unity-mcp-server-$runtime.zip"
$zipPath = Join-Path $PublishRoot $zipName
try {
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($runtimePath, $zipPath)
Write-Host "Successfully created $zipName" -ForegroundColor Green
$zipSuccess++
}
catch {
Write-Host "Failed to create $zipName : $($_.Exception.Message)" -ForegroundColor Red
$zipFailed++
}
}
else {
Write-Host "Skipping $runtime - directory not found" -ForegroundColor Yellow
$zipFailed++
}
}
Write-Host "`nZip Creation Summary:" -ForegroundColor Cyan
Write-Host "Success: $zipSuccess" -ForegroundColor Green
Write-Host "Failed: $zipFailed" -ForegroundColor Red
if ($zipFailed -eq 0) {
Write-Host "`nAll zip archives created successfully!" -ForegroundColor Green
Write-Host "Zip files are located in: $PublishRoot" -ForegroundColor Yellow
Write-Host "Created files:" -ForegroundColor Cyan
$zipFiles = Get-ChildItem -Path $PublishRoot -Filter "*.zip" -ErrorAction SilentlyContinue
if ($zipFiles) {
foreach ($zipFile in $zipFiles) {
$sizeKB = [math]::Round($zipFile.Length / 1KB, 2)
Write-Host " $($zipFile.Name) ($sizeKB KB)" -ForegroundColor White
}
}
} else {
Write-Host "`n$zipFailed zip archive(s) failed to create. See errors above." -ForegroundColor Red
exit 1
}