standalone-build.ps1 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. $ErrorActionPreference = "Stop"
  2. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  3. Set-Location $PSScriptRoot
  4. Write-Host "========================================" -ForegroundColor Cyan
  5. Write-Host "Building standalone exe (static linking)" -ForegroundColor Cyan
  6. Write-Host "========================================" -ForegroundColor Cyan
  7. Write-Host "`n[1/4] Setting OpenSSL static build environment..." -ForegroundColor Yellow
  8. . (Join-Path $PSScriptRoot "scripts\set-openssl-static-env.ps1")
  9. $env:DEFAULT_BACKEND_API_URL = "http://125.122.32.114:9000"
  10. Write-Host "API URL: $env:DEFAULT_BACKEND_API_URL" -ForegroundColor Cyan
  11. $env:RUSTFLAGS = "-C target-feature=+crt-static"
  12. $env:PROFILE = "release"
  13. Write-Host "`n[2/4] Building frontend..." -ForegroundColor Yellow
  14. npm run build
  15. if ($LASTEXITCODE -ne 0) {
  16. Write-Error "Frontend build failed!"
  17. exit 1
  18. }
  19. Write-Host "`n[3/4] Building Rust backend (static linking)..." -ForegroundColor Yellow
  20. Write-Host "This may take a few minutes, please wait..." -ForegroundColor Cyan
  21. cargo build --release --manifest-path src-tauri/Cargo.toml --bin your-app-name
  22. if ($LASTEXITCODE -ne 0) {
  23. Write-Error "Rust build failed!"
  24. exit 1
  25. }
  26. Write-Host "`n[4/4] Locating generated executable..." -ForegroundColor Yellow
  27. $exePaths = @(
  28. "src-tauri/target/release/your-app-name.exe"
  29. )
  30. $finalExe = $null
  31. foreach ($path in $exePaths) {
  32. if (Test-Path $path) {
  33. $finalExe = $path
  34. break
  35. }
  36. }
  37. if (-not $finalExe) {
  38. $exe = Get-ChildItem -Path "src-tauri/target/release" -Filter "*.exe" -File -Recurse |
  39. Where-Object { $_.Name -notmatch 'setup|uninstaller|bundle|deps|build' } |
  40. Sort-Object LastWriteTime -Descending |
  41. Select-Object -First 1
  42. if ($exe) {
  43. $finalExe = $exe.FullName
  44. }
  45. }
  46. if (-not $finalExe) {
  47. Write-Error "Cannot find generated executable!"
  48. exit 1
  49. }
  50. $outputName = "steamSH_standalone.exe"
  51. $outputPath = Join-Path $PSScriptRoot $outputName
  52. Copy-Item -Path $finalExe -Destination $outputPath -Force
  53. $fileSize = (Get-Item $outputPath).Length / 1MB
  54. Write-Host "`n========================================" -ForegroundColor Green
  55. Write-Host "Build completed!" -ForegroundColor Green
  56. Write-Host "========================================" -ForegroundColor Green
  57. Write-Host "Output file: $outputPath" -ForegroundColor Cyan
  58. Write-Host "File size: $([math]::Round($fileSize, 2)) MB" -ForegroundColor Cyan
  59. Write-Host "`nThis is a standalone executable that can run without installing any dependencies." -ForegroundColor Yellow
  60. if (Test-Path $outputPath) {
  61. Write-Host "`nFile verification: OK" -ForegroundColor Green
  62. }