Git Product home page Git Product logo

grpc-vcpkg-boilerplate-example's Introduction

Boilerplate Hello World gRPC Example with Vcpkg Manager

0. Purpose

GRPC is a high performance open source rpc framework. By default gRPC must be installed natively. Over the years this method has slowly deprecated with other methods of installation. While they recommend other methods such as Bazel or vcpkg, their examples are not exactly plug and play. This repository is an attempt to try and provide a template that build and compiles with vcpkg manager as a starting point which you can build upon from.

1. Pre-Environment Setup

This project requires vcpkg a package manager to be installed. VCPKG is used to manage your packages dependencies for projects like Protobufs and gRPC. If you already have vcpkg manager installed then continue to 2. Compile, otherwise continuing reading.

1.1 Installing vcpkg

Run the following commands to clone and install vcpkg in the current directory.

sudo apt-get install -y unzip build-essential
git clone https://github.com/microsoft/vcpkg
cd vcpkg/
./bootstrap-vcpkg.sh -disableMetrics

1.2 Install packages

In the vcpkg folder, search and install for grpc and protobufs. You may find that installing grpc will also install protobuf by default.

./vcpkg search grpc
./vcpkg install grpc && ./vcpkg install protobuf

Once installed you can run ./vcpkg list to ensure all the packages have successfully installed.

1.3 Vcpkg user-wide install

Next we will expose the installed packages to our project. From vcpkg's documentation "the recommended and most productive way to use vcpkg is via user-wide integration, making the system available for all projects you build. The user-wide integration will prompt for administrator access the first time it is used on a given machine, but afterwards is no longer required and the integration is configured on a per-user basis." '(Source: Vcpkg Documentation)'.

./vcpkg integrate install

Running command will output the path which we need to supply to cmake each time we build with a project. Take note of the DCMAKE_TOOLCHAIN_FILE flag as we will use this later in 2. Compile.

aa@ubuntu:~/vcpkg$ ./vcpkg integrate install
Applied user-wide integration for this vcpkg root.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/home/aa/vcpkg/scripts/buildsystems/vcpkg.cmake"

1.4 Configure CMake

OPTIONAL: Skip this if you already have system cmake installed.

By default ubuntu / raspbian and other OS may come with an older version of CMake so you may need to upgrade. Vcpkg downloads Cmake for you but you will need to add it to your $PATH as shown below. If you do not have CMake installed you can download the appropriate binaries from Cmake's download page. If running this setup from an OS other than Linux, Windows or OSX then you will need to either download the binaries or compile from source with yoru appropriate OS (Read More).

Note: Replace XX to your version of CMake! The path below may change depending on the file binary you downloaded/compiled.

export PATH=$PATH:$HOME/vcpkg/downloads/tools/cmake-X.X.X-linux/cmake-X.X.X-Linux-x86_64/bin

2. Compile

Update $VCPKG_HOME defined in the CMakelist.txt (located at the root) to match the location you installed VCPKG to.

set (VCPKG_HOME "$ENV{HOME}/vcpkg")

Once set we can then build the project and pass the DCMAKE_TOOLCHAIN_FILE direction pointing to our VCPKG's cmake previously installed.

mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/aa/vcpkg/scripts/buildsystems/vcpkg.cmake
make

If you get an error when running cmake.. such as below you may need to target your appropriate OS with -DVCPKG_TARGET_TRIPLET.

  Could not find a package configuration file provided by "gRPC" with any of
  the following names:

    gRPCConfig.cmake
    grpc-config.cmake

Here are some targets for your OS:

windows: cmake -DVCPKG_TARGET_TRIPLET=x86-windows ..

linux: cmake -DVCPKG_TARGET_TRIPLET=x64-linux ..

raspberrypi: cmake -DVCPKG_TARGET_TRIPLET=arm-linux ..

3. Run

You can find our compiled binaries in build/src. Start up the server with ./greeter_server to begin listening for connections. Then open another terminal to and run ./greeter_client and/or ./greeter_client2. Similarly, you can run the asynchronous examples with ./greeter_async_server and ./greeter_async_client in seperate terminals.

grpc-vcpkg-boilerplate-example's People

Contributors

advra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

grpc-vcpkg-boilerplate-example's Issues

Issue building on Raspberry Pi

The example is confirmed to work with Ubuntu, Linux and Windows. Attempting to compile the project on an ARM processor like the raspberry pi results in the following error. This unfortunately doesnt look like an easy solution.

pi@raspaa:~/Desktop/grpc-vcpkg-boilerplate-example/build $ cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/pi/vcpkg/scripts/buildsystems/vcpkg.cmake
-- Found protoc program: /home/pi/vcpkg/installed/arm-linux/tools/protobuf/protoc
CMake Warning at protos/CMakeLists.txt:15 (message):
  The grpc_cpp_plugin plugin was not found, the gRPC classes are not being
  generated


-- Using protobuf 3.13.0.0
-- Using gRPC 1.32.0
-- IS ELSE
-- Configuring done
CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at /home/pi/vcpkg/scripts/buildsystems/vcpkg.cmake:399 (_add_executable):
  Target "greeter_server" links to target "gRPC::grpc++_reflection" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  src/CMakeLists.txt:156 (add_executable)


CMake Error at /home/pi/vcpkg/scripts/buildsystems/vcpkg.cmake:399 (_add_executable):
  Target "greeter_client" links to target "gRPC::grpc++_reflection" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  src/CMakeLists.txt:156 (add_executable)


CMake Error at /home/pi/vcpkg/scripts/buildsystems/vcpkg.cmake:399 (_add_executable):
  Target "greeter_async_client" links to target "gRPC::grpc++_reflection" but
  the target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  src/CMakeLists.txt:156 (add_executable)


CMake Error at /home/pi/vcpkg/scripts/buildsystems/vcpkg.cmake:399 (_add_executable):
  Target "greeter_async_client2" links to target "gRPC::grpc++_reflection"
  but the target was not found.  Perhaps a find_package() call is missing for
  an IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  src/CMakeLists.txt:156 (add_executable)


CMake Error at /home/pi/vcpkg/scripts/buildsystems/vcpkg.cmake:399 (_add_executable):
  Target "greeter_async_server" links to target "gRPC::grpc++_reflection" but
  the target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  src/CMakeLists.txt:156 (add_executable)


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


CMake Error at src/CMakeLists.txt:139 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:gRPC::grpc_cpp_plugin>

  No target "gRPC::grpc_cpp_plugin"


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Could not find compatible gRPC configuration.

$cmake .. -DCMAKE_TOOLCHAIN_FILE=C:'C:\Users\Public\Documents\vcpkg\scripts\buildsystems\vcpkg.cmake' 

-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18363.
CMake Error at C:/Users/Public/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake:329 (_find_package):
  Could not find a configuration file for package "gRPC" that is compatible
  with requested version "".

  The following configuration files were considered but not accepted:

    C:/Users/Public/Documents/vcpkg/installed/x64-windows/share/gRPC/gRPCConfig.cmake, version: 1.28.1 (64bit)
    C:/Users/Public/Documents/vcpkg/packages/grpc_x64-windows/share/gRPC/gRPCConfig.cmake, version: 1.28.1 (64bit)

Call Stack (most recent call first):
  CMakeLists.txt:10 (find_package)


-- Configuring incomplete, errors occurred!

I also tried installing the gRPC x86 and re-running the cmake. But the package is not even considered. (I thought the issue might have been due to conflicts between 64 and 32 bit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.