Development Tips and Tricks - ni/grpc-device GitHub Wiki

Introduction

A good portion of the Bock squad has been using Visual Studio Code for development on the grpc-device repo.

Main advantages being

  • Lightweight
  • Available on both Windows and Linux
  • Suite of extensions that suited our needs The rest of this Wiki page assumes the use of Visual Studio Code for IDE.

Useful Extensions

The following are Visual Studio Code extensions that have proved useful for development on the grpc-device repo.

  • C/C++
  • C++ TestMate
  • Code Spell Checker
  • CMake Tools
  • Mako
  • Python
  • vscode-proto3

Clang-format On Save

Instead of having to remember to manually run clang-format to get your C++ updates in the proper form it's handy to set up clang-format to run when you save the C++ file you've been working on.

Pre-requisites

  • Visual Studio Code
  • C/C++ Extension

Setup

[Recommended]: Edit Workspace settings, not User settings.

EditWorkspaceSettings

  1. Edit the C/C++ extension settings as follows

    1. Navigate to the C/C++ extension settings
    2. Append "format" in the search bar
    3. Set "Clang_format_fallback Style" to "Google"
    4. Set "Clang_format_style" to "file"

    C++ExtensionSettings

  2. Edit the Text editor Formatting settings as follows

    1. Navigate to the Text Editor -> Formatting
    2. Check Editor: Format On Save
    3. Set "Format on Save Mode" to "file"

    FormatOnSaveSettings

Example

After configuring the settings mentioned above, when you save a C++ file it should apply the settings specified in the repo's root .clang-format file to the file under edit as follows:

ExampleFormatOnSave

Setup Python Virtual Environment

For the best IDE experience, you need the following tools installed in the python virtual environment used by vscode:

  • black
  • mypy
  • ni-python-styleguide

All of these can be installed via pip install , but they are also included in the virtual environment created cmake build. To use this virtual environment:

  1. Build grpc-device at least once with cmake.
  2. Ctrl+Shift+P to bring up the command palette.
  3. Select Interpreter
  4. Select the interpreter .\build\venv\Scripts\python.exe
  5. Note that this setting is saved per-workspace in an internal vscode database.

SetupPythonVirtualEnvironment

Black Format on Save

Black formatting is enforced for python code and examples as part of the grpc-device github workflow build.

This can be run from the command line:

pip install black
black source/codegen examples

For IDE configuration:

Pre-requisites

  • Setup virtual environment above

Note that black is included in the venv created by our build, so you can use that or pip install for a global installation.

Setup

  1. Navigate to Extensions -> Python

  2. Change Formatting: Provider to black

    ChangeFormatToBlack

Black cannot format "modifications-only" so ensure that Format on Save is set to "file":

FormatOnSaveSetToFile

ni-python-style guide compatible flake8

ni-python-styleguide formatting is enforced for python code and examples as part of the grpc-device github workflow build.

This can be run from the command line:

pip install ni-python-styleguide
ni-python-styleguide lint source/codegen/*.py examples

For IDE configuration:

Pre-requisites

  • Setup virtual environment above

Setup

  1. Ctrl+, to open settings.

  2. Select Workspace settings.

  3. Navigate to Extensions -> Python.

  4. Select the checkbox for Flake8 enabled

  5. Add the following entries to Flake8 Args:

    • --config
    • build/venv/Lib/site-packages/ni_python_styleguide/config.ini

    Flake8Args

Mypy

Mypy is a useful tool for type-checking in python. It is run on examples as part of the validate_examples.py script. It can be used to catch type errors in development and encourage the use of helpful type hints.

It can be run from the command line:

pip install mypy
mypy <directory> --check-untyped-defs

For IDE configuration:

Pre-requisites

  • Setup virtual environment above

Setup

  1. Ctrl+, to open settings.

  2. Select Workspace settings.

  3. Navigate to Extensions -> Python.

  4. Select the Mypy Enabled checkbox.

    EnableMypy

Ninja

grpc-device builds a lot faster with Ninja and it's easy to use with CMake.

Install Ninja with your package manager (chocolatey on Windows). On windows nasm is also required:

choco install ninja
choco install nasm

Command line

Depending on your terminal config, you may need to run vcvarsall.bat to setup CMAKE_C_COMPILER and CMAKE_CXX_COMPILER:

call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x64

Just add -GNinja to your configure call. (Clean first)

cmake .. -GNinja

See gRPC docs for more details.

VSCode extension

In the CMake Tools extension, set the Generator setting to "Ninja" (with no quotes). You will probably have to clean and rebuild after that.

⚠️ **GitHub.com Fallback** ⚠️