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