xref: /aosp_15_r20/external/grpc-grpc/test/distrib/cpp/run_distrib_test_cmake.bat (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1@rem Copyright 2016 gRPC authors.
2@rem
3@rem Licensed under the Apache License, Version 2.0 (the "License");
4@rem you may not use this file except in compliance with the License.
5@rem You may obtain a copy of the License at
6@rem
7@rem     http://www.apache.org/licenses/LICENSE-2.0
8@rem
9@rem Unless required by applicable law or agreed to in writing, software
10@rem distributed under the License is distributed on an "AS IS" BASIS,
11@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12@rem See the License for the specific language governing permissions and
13@rem limitations under the License.
14
15@rem enter this directory
16cd /d %~dp0\..\..\..
17
18@rem TODO(jtattermusch): Kokoro has pre-installed protoc.exe in C:\Program Files\ProtoC and that directory
19@rem is on PATH. To avoid picking up the older version protoc.exe, we change the path to something non-existent.
20set PATH=%PATH:ProtoC=DontPickupProtoC%
21
22@rem Install into ./testinstall, but use absolute path and foward slashes
23set INSTALL_DIR=%cd:\=/%/testinstall
24
25@rem Download OpenSSL-Win32 originally installed from https://slproweb.com/products/Win32OpenSSL.html
26powershell -Command "(New-Object Net.WebClient).DownloadFile('https://storage.googleapis.com/grpc-testing.appspot.com/OpenSSL-Win32-1_1_0g.zip', 'OpenSSL-Win32.zip')"
27powershell -Command "Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('OpenSSL-Win32.zip', '.');"
28
29@rem set absolute path to OpenSSL with forward slashes
30set OPENSSL_DIR=%cd:\=/%/OpenSSL-Win32
31
32@rem TODO(jtattermusch): add support for GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS env variable
33
34set VS_GENERATOR="Visual Studio 16 2019"
35@rem TODO(jtattermusch): switch to x64 build (will require pulling a x64 build of openssl)
36set VS_ARCHITECTURE="Win32"
37
38@rem Install absl
39mkdir third_party\abseil-cpp\cmake\build
40pushd third_party\abseil-cpp\cmake\build
41cmake -G %VS_GENERATOR% -A %VS_ARCHITECTURE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ..\..
42cmake --build . --config Release --target install || goto :error
43popd
44
45@rem Install c-ares
46mkdir third_party\cares\cares\cmake\build
47pushd third_party\cares\cares\cmake\build
48cmake -G %VS_GENERATOR% -A %VS_ARCHITECTURE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ..\..
49cmake --build . --config Release --target install || goto :error
50popd
51
52@rem Install protobuf
53mkdir third_party\protobuf\cmake\build
54pushd third_party\protobuf\cmake\build
55cmake -G %VS_GENERATOR% -A %VS_ARCHITECTURE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -Dprotobuf_ABSL_PROVIDER=package -DZLIB_ROOT=%INSTALL_DIR% -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF ..\..
56cmake --build . --config Release --target install || goto :error
57popd
58
59@rem Install re2
60mkdir third_party\re2\cmake\build
61pushd third_party\re2\cmake\build
62cmake -G %VS_GENERATOR% -A %VS_ARCHITECTURE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ..\..
63cmake --build . --config Release --target install || goto :error
64popd
65
66@rem Install zlib
67mkdir third_party\zlib\cmake\build
68pushd third_party\zlib\cmake\build
69cmake -G %VS_GENERATOR% -A %VS_ARCHITECTURE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ..\..
70cmake --build . --config Release --target install || goto :error
71popd
72
73@rem Just before installing gRPC, wipe out contents of all the submodules to simulate
74@rem a standalone build from an archive
75@rem NOTE(lidiz) We used to use "git submodule deinit", but it leaves an empty
76@rem folder for deinit-ed submodules, blocking the CMake download. For users
77@rem downloaded gRPC code as an archive, they won't have submodule residual
78@rem folders, like the following command trying to imitate.
79git submodule foreach bash -c "cd $toplevel; rm -rf $name"
80
81@rem Install gRPC
82@rem NOTE(jtattermusch): The -DProtobuf_USE_STATIC_LIBS=ON is necessary on cmake3.16+
83@rem since by default "find_package(Protobuf ...)" uses the cmake's builtin
84@rem FindProtobuf.cmake module, which now requires the info whether protobuf
85@rem is to be linked statically.
86@rem See https://github.com/Kitware/CMake/commit/3bbd85d5fffe66181cf16c81b23b2ba50f5387ba
87@rem See https://gitlab.kitware.com/cmake/cmake/-/merge_requests/3555#note_660390
88mkdir cmake\build
89pushd cmake\build
90cmake ^
91  -G %VS_GENERATOR% ^
92  -A %VS_ARCHITECTURE% ^
93  -DCMAKE_BUILD_TYPE=Release ^
94  -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ^
95  -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% ^
96  -DZLIB_ROOT=%INSTALL_DIR% ^
97  -DgRPC_INSTALL=ON ^
98  -DgRPC_BUILD_TESTS=OFF ^
99  -DgRPC_BUILD_MSVC_MP_COUNT=-1 ^
100  -DgRPC_ABSL_PROVIDER=package ^
101  -DgRPC_CARES_PROVIDER=package ^
102  -DgRPC_PROTOBUF_PROVIDER=package ^
103  -DProtobuf_USE_STATIC_LIBS=ON ^
104  -DgRPC_RE2_PROVIDER=package ^
105  -DgRPC_SSL_PROVIDER=package ^
106  -DgRPC_ZLIB_PROVIDER=package ^
107  ../.. || goto :error
108cmake --build . --config Release --target install || goto :error
109popd
110
111@rem Build helloworld example using cmake
112mkdir examples\cpp\helloworld\cmake\build
113pushd examples\cpp\helloworld\cmake\build
114cmake -G %VS_GENERATOR% -A %VS_ARCHITECTURE% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DZLIB_ROOT=%INSTALL_DIR% ../.. || goto :error
115cmake --build . --config Release || goto :error
116popd
117
118goto :EOF
119
120:error
121echo Failed!
122exit /b %errorlevel%
123