1
0

upload_libslirp.ps1 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # This script helps in building and uploading libslirp dll to google storage.
  2. # The prebuilts are downloaded primarily by test bots and developers.
  3. # Only googlers can upload the library to the cloud storage.
  4. param(
  5. [switch] $skip_msys_setup,
  6. [int] $version = $(throw "specify version to upload")
  7. )
  8. $BASE_PATH = $env:TEMP
  9. $MSYS_INSTALLER = $BASE_PATH + '\msys2.exe'
  10. $MSYS_PATH = $BASE_PATH + '\msys64'
  11. $LIBSLIRP_PATH = $BASE_PATH + '\libslirp'
  12. $LIBSLIRP_REPO_URL = 'https://gitlab.freedesktop.org/slirp/libslirp.git'
  13. $GS_BASE_URL = 'gs://chromeos-localmirror/distfiles/prebuilts/windows/x86_64/gnu/libslirp/'
  14. # The upstream libslirp library is compiled as dll with a lot of dependencies.
  15. # We compile the library as static binary by applying following patch.
  16. $LIBSLIRP_STATIC_COMPILE = @"
  17. diff --git a/meson.build b/meson.build
  18. index 7e7d818..9be3c20 100644
  19. --- a/meson.build
  20. +++ b/meson.build
  21. @@ -59,7 +59,8 @@ lt_version = '@0@.@1@.@2@'.format(lt_current - lt_age, lt_age, lt_revision)
  22. host_system = host_machine.system()
  23. -glib_dep = dependency('glib-2.0')
  24. +glib_dep = dependency('glib-2.0', static: true)
  25. +iconv_dep = dependency('iconv', static: true)
  26. add_project_arguments(cc.get_supported_arguments('-Wmissing-prototypes', '-Wstrict-prototypes',
  27. '-Wredundant-decls', '-Wundef', '-Wwrite-strings'),
  28. @@ -127,6 +128,7 @@ sources = [
  29. mapfile = 'src/libslirp.map'
  30. vflag = []
  31. +vflag += '-Wl,-Bstatic'
  32. vflag_test = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
  33. if cc.has_link_argument(vflag_test)
  34. vflag += vflag_test
  35. @@ -147,7 +149,7 @@ lib = library('slirp', sources,
  36. c_args : cargs,
  37. link_args : vflag,
  38. link_depends : mapfile,
  39. - dependencies : [glib_dep, platform_deps],
  40. + dependencies : [glib_dep, platform_deps, iconv_dep],
  41. install : install_devel or get_option('default_library') == 'shared',
  42. )
  43. "@
  44. Set-PSDebug -Trace 2
  45. try {
  46. if (-not $skip_msys_setup) {
  47. # Download the archive
  48. Start-BitsTransfer -Source 'https://github.com/msys2/msys2-installer/releases/download/nightly-x86_64/msys2-base-x86_64-latest.sfx.exe' -Destination $MSYS_INSTALLER
  49. $MSYS_DEST_ARG = '-o' + $BASE_PATH
  50. & $MSYS_INSTALLER -y $MSYS_DEST_ARG # Extract to C:\msys64
  51. $Env:PATH += $Env:PATH + ";" + $MSYS_PATH + "\usr\bin;" + $MSYS_PATH + "\mingw64\usr\bin;" + $MSYS_PATH + "\mingw64\bin"
  52. # Use bash from the installed msys.
  53. $bash_cmd = $MSYS_PATH + "\usr\bin\bash.exe"
  54. # Run for the first time
  55. & $bash_cmd -lc ' '
  56. # Update MSYS2
  57. & $bash_cmd -lc 'pacman --noconfirm -Syuu' # Core update (in case any core packages are outdated)
  58. & $bash_cmd -lc 'pacman --noconfirm -Syuu' # Normal update
  59. #Install dependencies
  60. & $bash_cmd -lc 'pacman --noconfirm -Syuu mingw-w64-x86_64-meson ninja git mingw-w64-x86_64-gcc mingw-w64-x86_64-glib2 mingw-w64-x86_64-pkg-config'
  61. }
  62. # Clone repo
  63. git clone $LIBSLIRP_REPO_URL $LIBSLIRP_PATH
  64. Push-Location
  65. Set-Location $LIBSLIRP_PATH
  66. Write-Output $LIBSLIRP_STATIC_COMPILE | git apply -
  67. meson release --buildtype release
  68. ninja -C release
  69. meson debug --buildtype debug
  70. ninja -C debug
  71. Copy-Item .\release\libslirp.dll.a .\release\libslirp.lib
  72. Copy-Item .\debug\libslirp.dll.a .\debug\libslirp.lib
  73. Write-Host Release binaries are located at: $LIBSLIRP_PATH\release\libslirp-0.dll and $LIBSLIRP_PATH\release\libslirp.lib
  74. Write-Host Debug binaries are located at: $LIBSLIRP_PATH\debug\libslirp-0.dll and $LIBSLIRP_PATH\debug\libslirp.lib
  75. Write-Host Uploading build binaries
  76. foreach ($build_type in 'release', 'debug') {
  77. foreach ($prebuilt in 'libslirp-0.dll', 'libslirp.lib') {
  78. gsutil cp -n -a public-read $LIBSLIRP_PATH\$build_type\$prebuilt $GS_BASE_URL/$build_type/$version/$prebuilt
  79. }
  80. }
  81. }
  82. finally {
  83. Set-PSDebug -Trace 0
  84. Write-Host Cleaning up
  85. Remove-Item $MSYS_INSTALLER # Delete the archive again
  86. Pop-Location
  87. }