Build-CrossPlatform.ps1 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. param(
  2. [ValidateSet('desktop', 'android', 'ios-simulator', 'test')][string]$Target = 'desktop',
  3. [ValidateSet('', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64', 'android-arm64', 'android-x64', 'iossimulator-arm64', 'iossimulator-x64')][string]$Runtime = '',
  4. [string]$DotnetPath = 'dotnet',
  5. [string]$PythonPath = 'python',
  6. [string]$AndroidSdkDirectory = '',
  7. [string]$JavaSdkDirectory = '',
  8. [switch]$Network
  9. )
  10. $ErrorActionPreference = 'Stop'
  11. $repo = Split-Path -Parent $PSScriptRoot
  12. $cross = Join-Path $repo 'CrossPlatform'
  13. $output = Join-Path $repo 'artifacts/cross-platform'
  14. function Invoke-Dotnet([string[]]$Arguments) {
  15. & $DotnetPath @Arguments
  16. if ($LASTEXITCODE -ne 0) { throw "Cross-platform $Target failed (exit $LASTEXITCODE)." }
  17. }
  18. Push-Location $cross
  19. try {
  20. switch ($Target) {
  21. 'test' {
  22. $arguments = @('run', '--project', 'PCL.Communist.Tests', '-c', 'Release', '--', "--screenshots=$output/qa")
  23. if ($Network) { $arguments += '--network' }
  24. Invoke-Dotnet $arguments
  25. }
  26. 'desktop' {
  27. if ($Runtime -notmatch '^(win|linux|osx)-(x64|arm64)$') { throw 'Specify a desktop -Runtime, for example osx-arm64.' }
  28. $publish = Join-Path $output $Runtime
  29. Invoke-Dotnet @('publish', 'PCL.Communist.Desktop', '-c', 'Release', '-r', $Runtime, '--self-contained', 'true', '-p:PublishTrimmed=false', '-o', $publish)
  30. & $PythonPath (Join-Path $PSScriptRoot 'package_cross_platform.py') --runtime $Runtime --input $publish --output (Join-Path $output 'packages')
  31. if ($LASTEXITCODE -ne 0) { throw 'Desktop packaging failed.' }
  32. }
  33. 'android' {
  34. if (-not $Runtime) { $Runtime = 'android-arm64' }
  35. if ($Runtime -notmatch '^android-(arm64|x64)$') { throw 'Android requires android-arm64 or android-x64.' }
  36. $arguments = @('publish', 'PCL.Communist.Android', '-c', 'Release', '-r', $Runtime, '-p:AndroidKeyStore=false', '-p:RunAOTCompilation=false', '-o', (Join-Path $output $Runtime))
  37. if ($AndroidSdkDirectory) { $arguments += "-p:AndroidSdkDirectory=$AndroidSdkDirectory" }
  38. if ($JavaSdkDirectory) { $arguments += "-p:JavaSdkDirectory=$JavaSdkDirectory" }
  39. Invoke-Dotnet $arguments
  40. Write-Output 'Preview APK uses the local debug signing key. Production signing is configured separately.'
  41. }
  42. 'ios-simulator' {
  43. if (-not [Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([Runtime.InteropServices.OSPlatform]::OSX)) {
  44. throw 'An iOS simulator build requires macOS, Xcode and the .NET iOS workload.'
  45. }
  46. if (-not $Runtime) {
  47. $Runtime = if ([Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq [Runtime.InteropServices.Architecture]::Arm64) { 'iossimulator-arm64' } else { 'iossimulator-x64' }
  48. }
  49. if ($Runtime -notmatch '^iossimulator-(arm64|x64)$') { throw 'Use an iOS simulator runtime.' }
  50. Invoke-Dotnet @('build', 'PCL.Communist.iOS', '-c', 'Debug', '-r', $Runtime, '-p:EnableCodeSigning=false', '-o', (Join-Path $output $Runtime))
  51. }
  52. }
  53. } finally { Pop-Location }