set-openssl-static-env.ps1 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # OpenSSL static linking environment setup script
  2. # For Tauri build with static OpenSSL linking
  3. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  4. $ErrorActionPreference = "Continue"
  5. # OpenSSL installation path (OpenSSL-Win64 FULL version)
  6. $OpenSSLDir = "C:\Program Files\OpenSSL-Win64"
  7. $OpenSSLLibDir = "C:\Program Files\OpenSSL-Win64\lib\VC\x64\MT"
  8. $OpenSSLIncludeDir = "C:\Program Files\OpenSSL-Win64\include"
  9. # Check if OpenSSL is installed
  10. if (-not (Test-Path $OpenSSLDir)) {
  11. Write-Host "[WARN] OpenSSL-Win64 not found at default location: $OpenSSLDir" -ForegroundColor Yellow
  12. Write-Host "[WARN] Trying other locations..." -ForegroundColor Yellow
  13. # Try other possible paths
  14. $possiblePaths = @(
  15. "C:\Program Files\OpenSSL-Win64",
  16. "C:\Program Files (x86)\OpenSSL-Win64",
  17. "C:\OpenSSL-Win64"
  18. )
  19. foreach ($path in $possiblePaths) {
  20. if (Test-Path $path) {
  21. $OpenSSLDir = $path
  22. $OpenSSLLibDir = "$path\lib\VC\x64\MT"
  23. $OpenSSLIncludeDir = "$path\include"
  24. Write-Host "[OK] Found OpenSSL: $path" -ForegroundColor Green
  25. break
  26. }
  27. }
  28. }
  29. # Set environment variables (static linking OpenSSL)
  30. $env:OPENSSL_DIR = $OpenSSLDir
  31. $env:OPENSSL_LIB_DIR = $OpenSSLLibDir
  32. $env:OPENSSL_INCLUDE_DIR = $OpenSSLIncludeDir
  33. $env:OPENSSL_STATIC = "1"
  34. # Set C runtime static linking (generate truly standalone exe)
  35. $env:RUSTFLAGS = "-C target-feature=+crt-static"
  36. Write-Host "========================================" -ForegroundColor Cyan
  37. Write-Host "OpenSSL static linking environment configured" -ForegroundColor Cyan
  38. Write-Host "========================================" -ForegroundColor Cyan
  39. Write-Host "OPENSSL_DIR: $env:OPENSSL_DIR"
  40. Write-Host "OPENSSL_LIB_DIR: $env:OPENSSL_LIB_DIR"
  41. Write-Host "OPENSSL_INCLUDE_DIR: $env:OPENSSL_INCLUDE_DIR"
  42. Write-Host "OPENSSL_STATIC: $env:OPENSSL_STATIC"
  43. Write-Host "RUSTFLAGS: $env:RUSTFLAGS"
  44. Write-Host ""
  45. # Check if static libraries exist
  46. $libcryptoPath = Join-Path $OpenSSLLibDir "libcrypto_static.lib"
  47. $libsslPath = Join-Path $OpenSSLLibDir "libssl_static.lib"
  48. if ((Test-Path $libcryptoPath) -and (Test-Path $libsslPath)) {
  49. Write-Host "[OK] OpenSSL static libraries found" -ForegroundColor Green
  50. Write-Host " - $libcryptoPath"
  51. Write-Host " - $libsslPath"
  52. } else {
  53. Write-Host "[WARN] OpenSSL static libraries not found" -ForegroundColor Yellow
  54. Write-Host " Expected: $libcryptoPath"
  55. Write-Host " Expected: $libsslPath"
  56. Write-Host "[INFO] Will use vendored OpenSSL (takes longer to compile)" -ForegroundColor Yellow
  57. # Clear manual path settings, let openssl crate use vendored
  58. $env:OPENSSL_DIR = $null
  59. $env:OPENSSL_LIB_DIR = $null
  60. $env:OPENSSL_INCLUDE_DIR = $null
  61. }
  62. Write-Host ""