diff --git a/README.md b/README.md index cdec1de99..99e1bcec4 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,100 @@ -### Building Dive host tool in Windows +### Checkout the code + +``` +git clone --recursive https://github.com/google/dive.git +``` + +If the code has been checked out without `--recursive` or you're pulling from the main branch later, please run following command to make sure the submodules are retrieved properly. +``` +git submodule update --init --recursive +``` + +### Prerequisite + + - The QT framework, can be installed from [QT online installer](https://download.qt.io/archive/online_installers/4.6/). We are currently using QT 5.11.2 + - gRPC [dependencies](https://github.com/grpc/grpc/blob/master/BUILDING.md#pre-requisites) + - Android NDK (currently we are using 25.2.9519653). Set the `ANDROID_NDK_HOME` environment variable. + ``` + export ANDROID_NDK_HOME=~/andriod_sdk/ndk/25.2.9519653 + ``` + +### Building Dive host tool on Linux +``` +# Assumes QTDIR is set to gcc_64 directory (eg. ~/Qt/5.11.2/gcc_64) +export CMAKE_PREFIX_PATH=$QTDIR +export PATH=$QTDIR:$PATH +cd +git submodule update --init --recursive +mkdir build +cd build +cmake -GNinja .. +ninja +``` + +You can specify the build type for debug/release as well +with `-DCMAKE_BUILD_TYPE=Debug` or `-DCMAKE_BUILD_TYPE=Release` when running cmake. + +### Building Dive host tool on Windows +To build with prebuilt gRPC libraries: ``` REM Assumes QTDIR is set to msvc directory (eg. C:\Qt\5.11.2\msvc2017_64) set CMAKE_PREFIX_PATH=%QTDIR% set PATH=%QTDIR%\bin;%PATH% cd -git submodule update --init +git submodule update --init --recursive mkdir build cd build cmake -G "Visual Studio 17 2022" .. ``` -Open `dive.sln` and build in Debug or Release + +Open `dive.sln` and build in Debug or Release Or run: +``` cmake --build . --config Debug cmake --build . --config Release +``` +#### Build without prebuilt libraries + +Or you can build without using the prebuilt libraries with `-DBUILD_GRPC=ON` -### Building Dive host tool in Linux (DEBUG) ``` -REM Assumes QTDIR is set to gcc_64 directory (eg. ~/Qt/5.11.2/gcc_64) -export CMAKE_PREFIX_PATH=$QTDIR -export PATH=$QTDIR:$PATH -cd -git submodule update --init --recursive -mkdir build +cmake -G "Visual Studio 17 2022" -DBUILD_GRPC=ON .. +``` + +Or you can build with Ninja, which is much faster: +Open Developer Command Prompt for VS 2022(or 2019) and run: +``` cd build -cmake -DCMAKE_BUILD_TYPE=Debug .. -make -j$(nproc) +cmake -G "Ninja" -DBUILD_GRPC=ON .. +ninja ``` +Note this requires build dependencies for gRPC, which requires to install prerequisite listed at [gRPC website](https://github.com/grpc/grpc/blob/master/BUILDING.md#windows). It's mostly about install the [NASM](https://www.nasm.us/). If you don't have `choco` installed, you can download the binary from [NASM website](https://www.nasm.us/) and add its path to the `PATH` environment variable. + +#### Update prebuilt libraries +Currently, the gRPC binaries are prebuilt under the folder `prebuild``. In case there's build error with the prebuilt libraries, you can run regenerate the libraries with following steps: + - Open Developer Command Prompt for VS 2022(or 2019) + - Run `scripts/build_grpc.bat` + + ### Building Android Libraries - Download the Android NDK (e.g. 25.2.9519653) - Set the environment variable `ANDROID_NDK_HOME` (e.g. export ANDROID_NDK_HOME=~/andriod_sdk/ndk/25.2.9519653) Run the script +On Linux, run: ``` ./scripts/build_android.sh ``` +And on Windows, Open Developer Command Prompt for VS 2022(or 2019) and run + +``` +scripts\build_android.bat +``` + + -It will build both debug and release version of the libraries. +It will build both debug and release version of the libraries under `build_android` folder. diff --git a/grpc.cmake b/grpc.cmake index 0aecd7646..c6d0eb8e9 100644 --- a/grpc.cmake +++ b/grpc.cmake @@ -68,7 +68,7 @@ if(GRPC_AS_SUBMODULE) set(_REFLECTION grpc++_reflection) if(CMAKE_CROSSCOMPILING) if(CMAKE_HOST_WIN32) - set(_PROTOBUF_PROTOC "${CMAKE_SOURCE_DIR}/bin/protoc.exe") + set(_PROTOBUF_PROTOC "${CMAKE_SOURCE_DIR}/prebuild/grpc/bin/protoc.exe") else() find_program(_PROTOBUF_PROTOC protoc PATHS ${CMAKE_SOURCE_DIR}/bin) endif() @@ -81,7 +81,7 @@ if(GRPC_AS_SUBMODULE) set(_GRPC_GRPCPP grpc++) if(CMAKE_CROSSCOMPILING) if(CMAKE_HOST_WIN32) - set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_SOURCE_DIR}/bin/grpc_cpp_plugin.exe") + set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_SOURCE_DIR}/prebuild/grpc/bin/grpc_cpp_plugin.exe") else() find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin PATHS ${CMAKE_SOURCE_DIR}/bin) endif() diff --git a/scripts/build_android.bat b/scripts/build_android.bat index 21e0a78a0..2a2fb3484 100644 --- a/scripts/build_android.bat +++ b/scripts/build_android.bat @@ -12,11 +12,12 @@ :: See the License for the specific language governing permissions and :: limitations under the License. -@REM @echo off +@echo off set PROJECT_ROOT=%~dp0\.. set BUILD_TYPE=Debug Release set SRC_DIR=%PROJECT_ROOT% +set startTime=%time% (for %%b in (%BUILD_TYPE%) do ( setlocal enabledelayedexpansion @@ -24,11 +25,10 @@ set SRC_DIR=%PROJECT_ROOT% set build=%%b set BUILD_DIR=%PROJECT_ROOT%\\build_android\\!build! echo "BUILD_DIR: " !BUILD_DIR! - mkdir !BUILD_DIR! + md !BUILD_DIR! pushd !BUILD_DIR! cmake -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%/build/cmake/android.toolchain.cmake ^ - -G "Unix Makefiles"^ - -DCMAKE_MAKE_PROGRAM="make" ^ + -G "Ninja"^ -DCMAKE_BUILD_TYPE=!build! ^ -DCMAKE_SYSTEM_NAME=Android ^ -DANDROID_ABI=arm64-v8a ^ @@ -43,4 +43,7 @@ set SRC_DIR=%PROJECT_ROOT% cmake --build . --config=!build! -j %NUMBER_OF_PROCESSORS% popd -)) \ No newline at end of file +)) + +echo Start Time: %startTime% +echo Finish Time: %time% \ No newline at end of file