From b264fbd7e413192590a8e0adc43873f9ea4f123d Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Thu, 9 Jul 2020 15:19:12 +0000 Subject: [PATCH] move to v1.30.1 --- .travis.yml | 37 ++++++------- CMakeLists.txt | 84 ++++++++++++++--------------- README.md | 64 ++++++++--------------- appveyor.yml | 13 +++-- cmake/build_dependencies.cmake | 93 ++++++++++++++++---------------- cmake/build_googleapis.cmake | 96 ---------------------------------- cmake/googleapis.cmake | 72 +++++++++++++++++++++++++ src/json_util.cc | 53 ------------------- src/json_util.h | 23 -------- src/json_util_test.cc | 45 ---------------- src/run_assistant_audio.cc | 1 - src/run_assistant_file.cc | 1 - src/run_assistant_text.cc | 1 - 13 files changed, 203 insertions(+), 380 deletions(-) delete mode 100644 cmake/build_googleapis.cmake create mode 100644 cmake/googleapis.cmake delete mode 100644 src/json_util.cc delete mode 100644 src/json_util.h delete mode 100644 src/json_util_test.cc diff --git a/.travis.yml b/.travis.yml index 4a69d37..5ed9732 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,17 +9,9 @@ compiler: - clang env: - - BUILD_TYPE=Debug CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - BUILD_TYPE=Debug CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - BUILD_TYPE=Debug CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - - BUILD_TYPE=Release CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - BUILD_TYPE=Release CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - BUILD_TYPE=Release CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - - BUILD_TYPE=MinSizeRel CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - BUILD_TYPE=MinSizeRel CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" - - BUILD_TYPE=MinSizeRel CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE" + - BUILD_TYPE=Debug + - BUILD_TYPE=Release + - BUILD_TYPE=MinSizeRel addons: apt: @@ -30,26 +22,27 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir ${DEPS_DIR} && cd ${DEPS_DIR} && pwd; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_retry wget --no-check-certificate https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.tar.gz; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "96d67e21f0983ebf0fffc5b106ec338c *cmake-3.11.0-Linux-x86_64.tar.gz" > cmake_md5.txt; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_retry wget --no-check-certificate https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.tar.gz; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "06bb006122e8e094f942bc9b2d999c92 *cmake-3.17.3-Linux-x86_64.tar.gz" > cmake_md5.txt; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then md5sum -c cmake_md5.txt; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xvf cmake-3.11.0-Linux-x86_64.tar.gz > /dev/null; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mv cmake-3.11.0-Linux-x86_64 cmake-install; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xvf cmake-3.17.3-Linux-x86_64.tar.gz > /dev/null; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mv cmake-3.17.3-Linux-x86_64 cmake-install; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then PATH=${DEPS_DIR}/cmake-install:${DEPS_DIR}/cmake-install/bin:$PATH; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_retry wget --no-check-certificate https://dl.google.com/go/go1.11.1.linux-amd64.tar.gz; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "a6103c8157246dd1ac70528878994f31 *go1.11.1.linux-amd64.tar.gz" > go_md5.txt; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_retry wget --no-check-certificate https://golang.org/dl/go1.14.4.linux-amd64.tar.gz; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "0ea61d0d7e05bbe454b8b19569ad86c8 *go1.14.4.linux-amd64.tar.gz" > go_md5.txt; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then md5sum -c go_md5.txt; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf go1.11.1.linux-amd64.tar.gz > /dev/null; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf go1.14.4.linux-amd64.tar.gz > /dev/null; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export GOROOT=${DEPS_DIR}/go; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then PATH=${DEPS_DIR}/go/bin:$PATH; fi - before_script: - cd ${TRAVIS_BUILD_DIR} - mkdir build && cd build - - cmake -DCMAKE_VERBOSE_MAKEFILE=FALSE -DCMAKE_BUILD_TYPE=${BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/build/dist ${CMAKE_ARGS} - .. + - cmake .. + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} + -DCMAKE_VERBOSE_MAKEFILE=TRUE + -DCMAKE_STAGING_PREFIX=${TRAVIS_BUILD_DIR}/dist/usr/local + script: - cmake --build . --config ${BUILD_TYPE} --target install diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bca9b9..84c9b45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.10.2) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE) @@ -10,7 +10,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") if(NOT BUILD_NUMBER) set(BUILD_NUMBER 0) endif() -set(ASSISTANT_SDK_CPP_VERSION 0.1.${BUILD_NUMBER}) +set(ASSISTANT_SDK_CPP_VERSION 0.0.1.${BUILD_NUMBER}) set(PACKAGE_NAME assistant-sdk-cpp) project(${PACKAGE_NAME} VERSION "${ASSISTANT_SDK_CPP_VERSION}" LANGUAGES CXX C) @@ -25,45 +25,42 @@ include(build_dependencies) set(CMAKE_CXX_STANDARD_REQUIRED 11) set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) include(FindThreads) +include(googleapis) -set(GOOGLEAPIS_API_CCS - ${GOOGLEAPIS_GENS_PATH}/google/api/http.grpc.pb.cc - ${GOOGLEAPIS_GENS_PATH}/google/api/http.pb.cc - ${GOOGLEAPIS_GENS_PATH}/google/api/annotations.grpc.pb.cc - ${GOOGLEAPIS_GENS_PATH}/google/api/annotations.pb.cc -) -set(GOOGLEAPIS_TYPE_CCS - ${GOOGLEAPIS_GENS_PATH}/google/type/latlng.pb.cc - ${GOOGLEAPIS_GENS_PATH}/google/type/latlng.grpc.pb.cc -) -set(GOOGLEAPIS_RPC_CCS -) -set(GOOGLEAPIS_ASSISTANT_PATH google/assistant/embedded/v1alpha2) -set(GOOGLEAPIS_ASSISTANT_CCS - ${GOOGLEAPIS_GENS_PATH}/${GOOGLEAPIS_ASSISTANT_PATH}/embedded_assistant.pb.cc - ${GOOGLEAPIS_GENS_PATH}/${GOOGLEAPIS_ASSISTANT_PATH}/embedded_assistant.grpc.pb.cc +protobuf_generate_grpc_cpp( + ${PROTO_BASE_PATH}/google/api/http.proto + ${PROTO_BASE_PATH}/google/api/annotations.proto + ${PROTO_BASE_PATH}/google/type/latlng.proto + ${PROTO_BASE_PATH}/google/assistant/embedded/v1alpha2/embedded_assistant.proto ) set(GOOGLEAPIS_CCS - ${GOOGLEAPIS_ASSISTANT_CCS} ${GOOGLEAPIS_API_CCS} - ${GOOGLEAPIS_RPC_CCS} ${GOOGLEAPIS_TYPE_CCS} + ${_gRPC_PROTO_GENS_DIR}/google/api/http.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/api/http.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/api/annotations.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/api/annotations.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/type/latlng.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/type/latlng.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/assistant/embedded/v1alpha2/embedded_assistant.pb.cc + ${_gRPC_PROTO_GENS_DIR}/google/assistant/embedded/v1alpha2/embedded_assistant.grpc.pb.cc ) set_source_files_properties(${GOOGLEAPIS_CCS} PROPERTIES GENERATED TRUE) +include_directories(${_gRPC_PROTO_GENS_DIR}) -set(CORE_SRCS src/base64_encode.cc src/json_util.cc) +set(CORE_SRCS src/base64_encode.cc) set(AUDIO_INPUT_FILE_SRCS src/audio_input_file.cc) set(ASSISTANT_AUDIO_SRCS src/run_assistant_audio.cc src/audio_pa.cc) set(ASSISTANT_FILE_SRCS src/run_assistant_file.cc) set(ASSISTANT_TEXT_SRCS src/run_assistant_text.cc) - -include_directories(src) - - -set(EXE_DEPS googleapis_ccs portaudio_ext) +include_directories( + src + ${CMAKE_CURRENT_BINARY_DIR}/grpc_ext-prefix/src/grpc_ext/third_party/abseil-cpp +) if(WIN32 AND MSVC) add_definitions(-D_WIN32_WINNT=0x600) @@ -77,34 +74,33 @@ else() set(_ALLTARGETS_LIBRARIES ${CMAKE_DL_LIBS} rt m ${CMAKE_THREAD_LIBS_INIT}) endif() - set(LDFLAGS - grpc++ grpc gpr grpc_cronet address_sorting - upb absl_base absl_strings absl_throw_delegate - ${_PROTOBUF_LIBRARIES} ${_CARES_LIBRARIES} + grpc++ grpc address_sorting upb cares gpr + ${_ABSL_LIBRARIES} ${_PROTOBUF_LIBRARIES} ${_ZLIB_LIBRARIES} ${_SSL_LIBRARIES} ${_ALLTARGETS_LIBRARIES} ) +add_executable(run_assistant_text ${GOOGLEAPIS_CCS} ${CORE_SRCS} ${ASSISTANT_TEXT_SRCS}) +target_link_libraries(run_assistant_text ${LDFLAGS}) +add_dependencies(run_assistant_text portaudio_ext) -add_library(googleapis_ccs STATIC ${GOOGLEAPIS_CCS}) -add_dependencies(googleapis_ccs googleapis) - -add_executable(run_assistant_text ${CORE_SRCS} ${ASSISTANT_TEXT_SRCS}) -target_link_libraries(run_assistant_text googleapis_ccs ${LDFLAGS}) -add_dependencies(run_assistant_text ${EXE_DEPS}) +add_executable(run_assistant_file ${GOOGLEAPIS_CCS} ${CORE_SRCS} ${AUDIO_INPUT_FILE_SRCS} ${ASSISTANT_FILE_SRCS}) +target_link_libraries(run_assistant_file ${LDFLAGS}) +add_dependencies(run_assistant_file portaudio_ext) -add_executable(run_assistant_file ${CORE_SRCS} ${AUDIO_INPUT_FILE_SRCS} ${ASSISTANT_FILE_SRCS}) -target_link_libraries(run_assistant_file googleapis_ccs ${LDFLAGS}) -add_dependencies(run_assistant_file ${EXE_DEPS}) - -add_executable(run_assistant_audio ${CORE_SRCS} ${AUDIO_SRCS} ${ASSISTANT_AUDIO_SRCS}) -target_link_libraries(run_assistant_audio googleapis_ccs ${LDFLAGS} ${_PORTAUDIO_LIB}) -add_dependencies(run_assistant_audio ${EXE_DEPS}) +add_executable(run_assistant_audio ${GOOGLEAPIS_CCS} ${CORE_SRCS} ${AUDIO_SRCS} ${ASSISTANT_AUDIO_SRCS}) +target_link_libraries(run_assistant_audio ${LDFLAGS} ${_PORTAUDIO_LIB}) +add_dependencies(run_assistant_audio portaudio_ext) +if(APPLE) + target_link_libraries(run_assistant_text "-framework CoreFoundation") + target_link_libraries(run_assistant_file "-framework CoreFoundation") + target_link_libraries(run_assistant_audio "-framework CoreFoundation") +endif() install (TARGETS run_assistant_audio run_assistant_text run_assistant_file - RUNTIME DESTINATION bin + RUNTIME DESTINATION bin ) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake") diff --git a/README.md b/README.md index 942ae1a..b451f12 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Google Assistant SDK for devices - C++ +### Linux / OSX build status +[![Build Status](https://travis-ci.com/jwinarske/assistant-sdk-cpp.svg?branch=cmake)](https://travis-ci.com/jwinarske/assistant-sdk-cpp) + +### Windows build status +[![Build status](https://ci.appveyor.com/api/projects/status/op7vmksh3p0jkln4/branch/cmake?svg=true)](https://ci.appveyor.com/project/jwinarske/assistant-sdk-cpp/branch/cmake) + ## Requirements This project is officially supported on Ubuntu 14.04. Other Linux distributions may be able to run @@ -29,7 +35,6 @@ sudo rm -rf /usr/local/bin/grpc_* /usr/local/bin/protoc \ ``` git clone https://github.com/googlesamples/assistant-sdk-cpp.git cd assistant-sdk-cpp -export PROJECT_PATH=$(pwd) ``` 2. Install dependencies @@ -39,78 +44,51 @@ sudo apt-get install libasound2-dev # For ALSA sound output sudo apt-get install libcurl4-openssl-dev # CURL development library ``` -3. Build Protocol Buffer, gRPC, and Google APIs -``` -git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc -GRPC_PATH=${PROJECT_PATH}/grpc -cd ${GRPC_PATH} - -git submodule update --init - -cd third_party/protobuf -./autogen.sh && ./configure && make -sudo make install -sudo ldconfig - -export LDFLAGS="$LDFLAGS -lm" -cd ${GRPC_PATH} -make clean -make -sudo make install -sudo ldconfig - -cd ${PROJECT_PATH} -git clone https://github.com/googleapis/googleapis.git -cd googleapis/ -make LANGUAGE=cpp -``` - -4. Make sure you setup environment variable `$GOOGLEAPIS_GENS_PATH` -``` -export GOOGLEAPIS_GENS_PATH=${PROJECT_PATH}/googleapis/gens -``` - -5. Build this project +3. Build this project ``` -cd ${PROJECT_PATH} -make run_assistant +mkdir build && cd build +cmake .. -DCMAKE_STAGING_PREFIX=`pwd`/dist/usr/local +make install -j ``` -6. Get credentials file. It must be an end-user's credentials. +4. Get credentials file. It must be an end-user's credentials. * Go to the [Actions Console](https://console.actions.google.com/) and register your device model, following [these instructions](https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device) * Move it in this folder and rename it to `client_secret.json` * run `get_credentials.sh` in this folder. It will create the file `credentials.json`. -7. Start one of the `run_assistant` samples: +5. Start one of the `run_assistant` samples: ```bash -./run_assistant_file --input ./resources/weather_in_mountain_view.raw --output ./response.wav --credentials ./credentials.json +export LD_LIBRARY_PATH=`pwd`/dist/usr/local/lib +./dist/usr/local/bin/run_assistant_file --input ../resources/weather_in_mountain_view.raw --output ./response.wav --credentials ../credentials.json aplay ./response.wav --rate=16000 --format=S16_LE ``` On a Linux workstation, you can alternatively use ALSA for audio input: ```bash -./run_assistant_audio --credentials ./credentials.json +export LD_LIBRARY_PATH=`pwd`/dist/usr/local/lib +./dist/usr/local/bin/run_assistant_audio --credentials ../credentials.json ``` You can use a text-based query instead of audio. This allows you to continually enter text queries to the Assistant. ```bash -./run_assistant_text --credentials ./credentials.json +export LD_LIBRARY_PATH=`pwd`/dist/usr/local/lib +./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json ``` This takes input from `cin`, so you can send data to the program when it starts. ```bash -echo "what time is it" | ./run_assistant_text --credentials ./credentials.json +echo "what time is it" | ./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json ``` To change the locale, include a `locale` parameter: ```bash -echo "Bonjour" | ./run_assistant_text --credentials ./credentials.json --locale "fr-FR" +echo "Bonjour" | ./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json --locale "fr-FR" ``` Default Assistant gRPC API endpoint is `embeddedassistant.googleapis.com`. If you want to test with a custom Assistant gRPC API endpoint, you can pass `--api_endpoint CUSTOM_API_ENDPOINT`. @@ -120,7 +98,7 @@ Default Assistant gRPC API endpoint is `embeddedassistant.googleapis.com`. If yo To get a visual output from the Assistant, provide a command to be run alongside every step of the conversation. It will execute that command along along with a provided argument of a temporary HTML file. ```bash -echo "what time is it" | ./run_assistant_text --credentials ./credentials.json --html_out google-chrome +echo "what time is it" | ./dist/usr/local/bin/run_assistant_text --credentials ../credentials.json --html_out google-chrome ``` After you enter text, it will run `google-chrome /tmp/google-assistant-cpp-screen-out.html`. diff --git a/appveyor.yml b/appveyor.yml index fc8ed2e..ecc8ccb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -68,11 +68,16 @@ init: - echo BUILD_NUMBER=%APPVEYOR_BUILD_NUMBER% stack: - - go 1.11 + - go 1.14.4 install: + - echo Downloading Yasm... + - mkdir windows_build_tools + - powershell -Command "(New-Object Net.WebClient).DownloadFile('https://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe', 'windows_build_tools\yasm.exe')" + - set PATH=%cd%\windows_build_tools;%PATH% - cmake --version - go version + - yasm --version build: parallel: true @@ -85,9 +90,11 @@ build_script: - mkdir build - cd build - - cmake %CMAKE_TOOLCHAIN_ARGS% -G"%GENERATOR%" -DCMAKE_VERBOSE_MAKEFILE=TRUE + - cmake %CMAKE_TOOLCHAIN_ARGS% -G"%GENERATOR%" + -DCMAKE_VERBOSE_MAKEFILE=TRUE -DCMAKE_BUILD_TYPE=%CONFIGURATION% - "-DCMAKE_INSTALL_PREFIX=%DIST_DIR%\%APPVEYOR_BUILD_WORKER_IMAGE%" + -DCMAKE_ASM_NASM_COMPILER="yasm.exe" + -DCMAKE_STAGING_PREFIX="%DIST_DIR%\%APPVEYOR_BUILD_WORKER_IMAGE%\${CMAKE_INSTALL_PREFIX}" -DBUILD_NUMBER=%APPVEYOR_BUILD_NUMBER% %CMAKE_ARGS% .. diff --git a/cmake/build_dependencies.cmake b/cmake/build_dependencies.cmake index 788f17f..0ed48e6 100644 --- a/cmake/build_dependencies.cmake +++ b/cmake/build_dependencies.cmake @@ -2,7 +2,7 @@ include (ExternalProject) include(CheckFunctionExists) if(NOT GRPC_VERSION) - set(GRPC_VERSION v1.27.2) + set(GRPC_VERSION v1.30.1) endif() if(ANDROID) @@ -11,15 +11,23 @@ if(ANDROID) -DRUN_HAVE_POSIX_REGEX=0 -DRUN_HAVE_STEADY_CLOCK=0 -DCMAKE_EXE_LINKER_FLAGS=-llog - -DgRPC_BUILD_CODEGEN=OFF - -DgRPC_BUILD_CSHARP_EXT=OFF ) endif() + +set(GRPC_SRC_PATH ${CMAKE_CURRENT_BINARY_DIR}/grpc_ext-prefix/src/grpc_ext) + +if(NOT MSVC) + set(gRPC_ZLIB_PROVIDER package) +else() + set(gRPC_ZLIB_PROVIDER module) +endif() + ExternalProject_Add(grpc_ext GIT_REPOSITORY "https://github.com/grpc/grpc" GIT_TAG ${GRPC_VERSION} GIT_SHALLOW 1 + PATCH_COMMAND "" UPDATE_COMMAND "" BUILD_IN_SOURCE 0 CMAKE_ARGS @@ -28,22 +36,43 @@ ExternalProject_Add(grpc_ext -DANDROID_STL=${ANDROID_STL} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_STAGING_PREFIX=${CMAKE_STAGING_PREFIX} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE} + -DCMAKE_ASM_NASM_COMPILER=${CMAKE_ASM_NASM_COMPILER} + -DgRPC_INSTALL=ON + -DgRPC_BUILD_CODEGEN=ON + -DgRPC_BUILD_CSHARP_EXT=ON + -DgRPC_ZLIB_PROVIDER=${gRPC_ZLIB_PROVIDER} ${GRPC_ANDROID_ARGS} ) set(_GRPC_SRC_PATH ${CMAKE_BINARY_DIR}/grpc_ext-prefix/src/grpc_ext) set(_GRPC_LIBRARIES_DIR ${_GRPC_SRC_PATH}-build) +set(_ABSL_LIBRARIES + absl_bad_optional_access + absl_str_format_internal + absl_time + absl_time_zone + absl_civil_time + absl_strings + absl_strings_internal + absl_throw_delegate + absl_int128 + absl_base + absl_spinlock_wait + absl_raw_logging_internal + absl_log_severity + absl_dynamic_annotations +) + set(_SSL_LIBRARIES_DIRS ${_GRPC_SRC_PATH}-build/third_party/boringssl/crypto ${_GRPC_SRC_PATH}-build/third_party/boringssl/ssl - ${_GRPC_SRC_PATH}-build/third_party/boringssl/decrepit ) -set(_SSL_LIBRARIES ssl decrepit crypto) - +set(_SSL_LIBRARIES ssl crypto) if(NOT MSVC) set(_ZLIB_LIBRARIES z) @@ -55,8 +84,6 @@ else() endif() endif() -set(_CARES_LIBRARIES cares) - if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(PROTOBUF_LIB protobufd) else() @@ -68,42 +95,6 @@ endif() set(_PROTOBUF_LIBRARIES ${PROTOBUF_LIB}) -set(GOOGLEAPIS_GENS_PATH ${CMAKE_INSTALL_PREFIX}/gens) - -if(CMAKE_CROSSCOMPILING) - if(NOT PROTOBUF_ROOT_FOLDER) - set(PROTOBUF_ROOT_FOLDER /usr/local/bin) - endif() - if(NOT GRPC_PLUGINPATH) - set(GRPC_PLUGINPATH /usr/local/bin) - endif() -else() - set(PROTOBUF_ROOT_FOLDER ${_GRPC_SRC_PATH}-build) - set(GRPC_PLUGINPATH ${_GRPC_SRC_PATH}-build) -endif() - -ExternalProject_Add(googleapis - GIT_REPOSITORY https://github.com/googleapis/googleapis.git - GIT_TAG master - GIT_SHALLOW 1 - PATCH_COMMAND - cmake -E copy - ${CMAKE_SOURCE_DIR}/cmake/build_googleapis.cmake - ${CMAKE_BINARY_DIR}/googleapis-prefix/src/googleapis/CMakeLists.txt - UPDATE_COMMAND "" - BUILD_IN_SOURCE 0 - CMAKE_ARGS - -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} - -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} - -DProtobuf_DEBUG=OFF - -DProtobuf_SRC_ROOT_FOLDER=${PROTOBUF_ROOT_FOLDER} - -DGRPCPLUGIN_PATH=${GRPC_PLUGINPATH} - -DOUTPUT=${GOOGLEAPIS_GENS_PATH} - INSTALL_COMMAND "" -) -add_dependencies(googleapis grpc_ext) - - if(MSVC) if(${TARGET_ARCH} STREQUAL "x86_64") set(_PORTAUDIO_LIB portaudio_x64) @@ -124,6 +115,7 @@ if(NOT ANDROID) CMAKE_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_STAGING_PREFIX=${CMAKE_STAGING_PREFIX} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE} @@ -145,6 +137,7 @@ else() -DANDROID_STL=${ANDROID_STL} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_STAGING_PREFIX=${CMAKE_STAGING_PREFIX} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE} @@ -171,6 +164,7 @@ if(NOT HAVE_GETOPT_C) -DANDROID_STL=${ANDROID_STL} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_STAGING_PREFIX=${CMAKE_STAGING_PREFIX} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE} @@ -184,14 +178,17 @@ endif() include_directories( - ${CMAKE_INSTALL_PREFIX}/include + ${CMAKE_STAGING_PREFIX}/include ${_GRPC_SRC_PATH} - ${GOOGLEAPIS_GENS_PATH} ) link_directories( - ${CMAKE_INSTALL_PREFIX}/lib - ${CMAKE_INSTALL_PREFIX}/lib/static + ${CMAKE_STAGING_PREFIX}/lib + ${CMAKE_STAGING_PREFIX}/lib/static ${_GRPC_LIBRARIES_DIR} ${_SSL_LIBRARIES_DIRS} ) + +set(Protobuf_PROTOC_EXECUTABLE ${CMAKE_STAGING_PREFIX}/bin/protoc) + +set(PROTO_BASE_PATH ${CMAKE_CURRENT_BINARY_DIR}/grpc_ext-prefix/src/grpc_ext/third_party/googleapis) diff --git a/cmake/build_googleapis.cmake b/cmake/build_googleapis.cmake deleted file mode 100644 index f0844f4..0000000 --- a/cmake/build_googleapis.cmake +++ /dev/null @@ -1,96 +0,0 @@ -cmake_minimum_required(VERSION 3.11) - -set(Protobuf_USE_STATIC_LIBS OFF) - -if(NOT Protobuf_SRC_ROOT_FOLDER) - set(Protobuf_SRC_ROOT_FOLDER ${CMAKE_INSTALL_PREFIX}) -endif() - -set(Protobuf_IMPORT_DIRS - ${CMAKE_SOURCE_DIR} - ${CMAKE_BINARY_DIR} - ${CMAKE_INSTALL_PREFIX}/include -) - -if(NOT WIN32) - set(BIN_SUFFIX "") - set(PATH_SEPERATOR ":") -else() - set(PATH_SEPERATOR ";") - set(BIN_SUFFIX ".exe") -endif() - -find_package(Protobuf REQUIRED) - -include_directories(${CMAKE_BINARY_DIR}) - -if(NOT Protobuf_FOUND) - message(FATAL_ERROR "Set Protobuf_SRC_ROOT_FOLDER to the desired sysroot...") -endif() -message(STATUS "Protobuf_VERSION=${Protobuf_VERSION}") - -# Choose the output directory -if(NOT OUTPUT) - set(OUTPUT ./gens) -endif() -file(MAKE_DIRECTORY ${OUTPUT}) - - -# Choose the target language. -if(NOT LANGUAGE) - set(LANGUAGE cpp) -endif() -if(${LANGUAGE} STREQUAL "go") - MESSAGE(FATAL_ERROR "Go source files are not generated from this repository. See: https://github.com/google/go-genproto") -endif() - - -# Choose grpc plugin -if(NOT GRPCPLUGIN_PATH) - set(GRPCPLUGIN_PATH /usr/local/bin/grpc_${LANGUAGE}_plugin) -endif() -set(GRPCPLUGIN "${GRPCPLUGIN_PATH}/grpc_${LANGUAGE}_plugin${BIN_SUFFIX}") - -# Choose the proto include directory. -#include_directories(${Protobuf_INCLUDE_DIRS}) - -get_filename_component(protoc_path ${Protobuf_PROTOC_EXECUTABLE} DIRECTORY) -file(TO_NATIVE_PATH ${protoc_path} protoc_path) - -set(ENV{PATH} "${protoc_path}${PATH_SEPERATOR}$ENV{PATH}") - -# Compile the entire repository -# -file(TO_NATIVE_PATH ${OUTPUT} NATIVE_OUTPUT) -file(TO_NATIVE_PATH ${GRPCPLUGIN} NATIVE_GRPCPLUGIN) -file(TO_NATIVE_PATH ${Protobuf_INCLUDE_DIRS} NATIVE_Protobuf_INCLUDE_DIRS) -MESSAGE(STATUS "Protobuf_INCLUDE_DIRS=${NATIVE_Protobuf_INCLUDE_DIRS}") -MESSAGE(STATUS "OUTPUT=${NATIVE_OUTPUT}") -MESSAGE(STATUS "LANGUAGE=${LANGUAGE}") -MESSAGE(STATUS "GRPCPLUGIN=${NATIVE_GRPCPLUGIN}") -message(STATUS "WORKING_DIRECTORY=${CMAKE_SOURCE_DIR}") - -file(MAKE_DIRECTORY ${OUTPUT}) - -file(GLOB_RECURSE src_list ${CMAKE_SOURCE_DIR} google/*.proto) - -foreach(src ${src_list}) - string (REGEX REPLACE "^${CMAKE_SOURCE_DIR}/" "" rel_src ${src}) - file(TO_NATIVE_PATH ${rel_src} NATIVE_rel_src) - - if(Protobuf_DEBUG) - MESSAGE(STATUS "protoc${BIN_SUFFIX} --proto_path=.${PATH_SEPERATOR}${NATIVE_Protobuf_INCLUDE_DIRS} --${LANGUAGE}_out=${NATIVE_OUTPUT} --grpc_out=${NATIVE_OUTPUT} --plugin=protoc-gen-grpc=${NATIVE_GRPCPLUGIN} ${NATIVE_rel_src}") - else() - MESSAGE(STATUS ${NATIVE_rel_src}) - endif() - - execute_process( - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND "protoc${BIN_SUFFIX}" - "--proto_path=.${PATH_SEPERATOR}${NATIVE_Protobuf_INCLUDE_DIRS}" - "--${LANGUAGE}_out=${NATIVE_OUTPUT}" - "--grpc_out=${NATIVE_OUTPUT}" - "--plugin=protoc-gen-grpc=${NATIVE_GRPCPLUGIN}" - ${NATIVE_rel_src} - ) -endforeach(src) diff --git a/cmake/googleapis.cmake b/cmake/googleapis.cmake new file mode 100644 index 0000000..16f50bb --- /dev/null +++ b/cmake/googleapis.cmake @@ -0,0 +1,72 @@ +# Set grpc plugin +if(NOT _gRPC_CPP_PLUGIN) + set(_gRPC_CPP_PLUGIN ${CMAKE_STAGING_PREFIX}/bin/grpc_cpp_plugin) +endif() + +if(NOT _gRPC_PROTO_GENS_DIR) + set(_gRPC_PROTO_GENS_DIR ${CMAKE_CURRENT_BINARY_DIR}/gens) +endif() + +if(NOT _gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR) + set(_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR ${CMAKE_STAGING_PREFIX}/include) +endif() + +# Normalize all paths +file(TO_NATIVE_PATH ${_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR} NATIVE_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR) +file(TO_NATIVE_PATH ${_gRPC_CPP_PLUGIN} NATIVE_gRPC_CPP_PLUGIN) +file(TO_NATIVE_PATH ${_gRPC_PROTO_GENS_DIR} NATIVE_gRPC_PROTO_GENS_DIR) +file(TO_NATIVE_PATH ${PROTO_BASE_PATH} NATIVE_PROTO_BASE_PATH) + +# Create directory for generated .proto files +file(MAKE_DIRECTORY ${NATIVE_gRPC_PROTO_GENS_DIR}) + +# protobuf_generate_grpc_cpp +# -------------------------- +# +# Add custom commands to process ``.proto`` files to C++ using protoc and +# GRPC plugin:: +# +# protobuf_generate_grpc_cpp [...] +# +# ``ARGN`` +# ``.proto`` files +# +function(protobuf_generate_grpc_cpp) + if(NOT ARGN) + message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files") + return() + endif() + + set(_protobuf_include_path -I . -I ${NATIVE_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR}) + + foreach(FIL ${ARGN}) + + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(FIL_WE ${FIL} NAME_WE) + file(RELATIVE_PATH REL_FIL ${PROTO_BASE_PATH} ${ABS_FIL}) + get_filename_component(REL_DIR ${REL_FIL} DIRECTORY) + + set(RELFIL_WE ${_gRPC_PROTO_GENS_DIR}/${REL_DIR}/${FIL_WE}) + + # Normalize paths + file(TO_NATIVE_PATH ${RELFIL_WE} NATIVE_RELFIL_WE) + file(TO_NATIVE_PATH ${REL_FIL} NATIVE_REL_FIL) + + add_custom_command( + OUTPUT ${NATIVE_RELFIL_WE}.grpc.pb.cc + ${NATIVE_RELFIL_WE}.grpc.pb.h + ${NATIVE_RELFIL_WE}_mock.grpc.pb.h + ${NATIVE_RELFIL_WE}.pb.cc + ${NATIVE_RELFIL_WE}.pb.h + COMMAND ${Protobuf_PROTOC_EXECUTABLE} + ARGS --grpc_out=generate_mock_code=true:${NATIVE_gRPC_PROTO_GENS_DIR} + --plugin=protoc-gen-grpc=${NATIVE_gRPC_CPP_PLUGIN} + --cpp_out=${NATIVE_gRPC_PROTO_GENS_DIR} + ${_protobuf_include_path} + ${NATIVE_REL_FIL} + DEPENDS ${ABS_FIL} grpc_ext + WORKING_DIRECTORY ${PROTO_BASE_PATH} + COMMENT "Running gRPC C++ protocol buffer compiler on ${FIL}" + VERBATIM) + endforeach() +endfunction() diff --git a/src/json_util.cc b/src/json_util.cc deleted file mode 100644 index 1911c92..0000000 --- a/src/json_util.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "json_util.h" -#include "scope_exit.h" - -extern "C" { -#include -} - -#include -#include - -grpc_json* GetJsonValueOrNullFromDict(grpc_json* dict_node, const char* key) { - if (dict_node->type != GRPC_JSON_OBJECT) { - return nullptr; - } - - grpc_json* child = dict_node->child; - while (child != nullptr) { - if (child->key != nullptr && strcmp(child->key, key) == 0) { - return child; - } - child = child->next; - } - return nullptr; -} - -grpc_json* GetJsonValueOrNullFromArray(grpc_json* array_node, int index) { - if (array_node->type != GRPC_JSON_ARRAY) { - return nullptr; - } - - grpc_json* child = array_node->child; - while (child != nullptr && index != 0) { - child = child->next; - index--; - } - return child; -} diff --git a/src/json_util.h b/src/json_util.h deleted file mode 100644 index 3b6ba78..0000000 --- a/src/json_util.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSON_UTIL_H -#define JSON_UTIL_H - -#include -#include - -#endif diff --git a/src/json_util_test.cc b/src/json_util_test.cc deleted file mode 100644 index f50f0bf..0000000 --- a/src/json_util_test.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2017 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "json_util.h" - -#include - -bool check_result(const std::string& input_json, - std::unique_ptr intended_result) { - std::unique_ptr result = GetCustomResponseOrNull(input_json); - return (intended_result == nullptr && result == nullptr) || - (intended_result != nullptr && result != nullptr && - *intended_result == *result); -} - -int main() { - std::string invalid_json = ""; - std::unique_ptr intended_result(nullptr); - if (!check_result(invalid_json, std::move(intended_result))) { - std::cerr << "Test failed for invalid JSON" << std::endl; - return 1; - } - - std::string incomplete_json = "{}"; - intended_result.reset(nullptr); - if (!check_result(incomplete_json, std::move(intended_result))) { - std::cerr << "Test failed for incomplete JSON" << std::endl; - return 1; - } - - std::cerr << "Test passed" << std::endl; -} diff --git a/src/run_assistant_audio.cc b/src/run_assistant_audio.cc index 47b74bf..b33b88f 100644 --- a/src/run_assistant_audio.cc +++ b/src/run_assistant_audio.cc @@ -35,7 +35,6 @@ limitations under the License. #include "audio_input.h" #include "audio_input_file.h" #include "base64_encode.h" -#include "json_util.h" namespace assistant = google::assistant::embedded::v1alpha2; diff --git a/src/run_assistant_file.cc b/src/run_assistant_file.cc index 8f51437..c827910 100644 --- a/src/run_assistant_file.cc +++ b/src/run_assistant_file.cc @@ -33,7 +33,6 @@ limitations under the License. #include "audio_input.h" #include "audio_input_file.h" #include "base64_encode.h" -#include "json_util.h" namespace assistant = google::assistant::embedded::v1alpha2; diff --git a/src/run_assistant_text.cc b/src/run_assistant_text.cc index 27496d9..5918f04 100644 --- a/src/run_assistant_text.cc +++ b/src/run_assistant_text.cc @@ -33,7 +33,6 @@ limitations under the License. #include "audio_input.h" #include "audio_input_file.h" #include "base64_encode.h" -#include "json_util.h" namespace assistant = google::assistant::embedded::v1alpha2;