Development Tips and Tricks - ni/grpc-device GitHub Wiki
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.
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
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.
- Visual Studio Code
- C/C++ Extension
[Recommended]: Edit Workspace settings, not User settings.
-
Edit the C/C++ extension settings as follows
- Navigate to the C/C++ extension settings
- Append "format" in the search bar
- Set "Clang_format_fallback Style" to "Google"
- Set "Clang_format_style" to "file"
-
Edit the Text editor Formatting settings as follows
- Navigate to the Text Editor -> Formatting
- Check Editor: Format On Save
- Set "Format on Save Mode" to "file"
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:
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:
- Build grpc-device at least once with cmake.
- Ctrl+Shift+P to bring up the command palette.
- Select Interpreter
- Select the interpreter .\build\venv\Scripts\python.exe
- Note that this setting is saved per-workspace in an internal vscode database.
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:
- 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.
-
Navigate to Extensions -> Python
-
Change Formatting: Provider to black
Black cannot format "modifications-only" so ensure that Format on Save is set to "file":
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:
- Setup virtual environment above
-
Ctrl+,
to open settings. -
Select
Workspace
settings. -
Navigate to Extensions -> Python.
-
Select the checkbox for
Flake8 enabled
-
Add the following entries to
Flake8 Args
:--config
build/venv/Lib/site-packages/ni_python_styleguide/config.ini
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:
- Setup virtual environment above
-
Ctrl+
, to open settings. -
Select
Workspace
settings. -
Navigate to Extensions -> Python.
-
Select the
Mypy Enabled
checkbox.
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
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.
In the CMake Tools extension, set the Generator setting to "Ninja" (with no quotes). You will probably have to clean and rebuild after that.