Skip to content

Commit

Permalink
Merge pull request #1 from jwinarske/cmake_update
Browse files Browse the repository at this point in the history
move to v1.30.1
  • Loading branch information
jwinarske authored Jul 13, 2020
2 parents 4f58aea + b264fbd commit 6ef46eb
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 380 deletions.
37 changes: 15 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
84 changes: 40 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")
64 changes: 21 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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`.
Expand All @@ -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`.
Expand Down
13 changes: 10 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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%
..

Expand Down
Loading

0 comments on commit 6ef46eb

Please sign in to comment.