Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copilot Instructions for grpc-device Repository

## Building the Project

This repository requires specific environment setup before building. **Always** follow these guidelines when running build commands.

### Prerequisites

1. **Visual Studio Build Tools**: Ensure Visual Studio Build Tools are installed with C++ development components
2. **CMake**: Make sure CMake is available in the system PATH

### Critical: Preferred Build Method

**Always use the copilot-build.ps1 script for all builds:**

```powershell
# Default Debug build
.\utils\copilot-build.ps1

# Release build
.\utils\copilot-build.ps1 --config Release

# RelWithDebInfo build
.\utils\copilot-build.ps1 --config RelWithDebInfo

# Other cmake arguments
.\utils\copilot-build.ps1 --target clean --config Debug
.\utils\copilot-build.ps1 --parallel 4 --config Release
```

This script automatically handles the Visual Studio environment setup and is much more Copilot-friendly since it avoids complex command chaining that often requires manual approval.
Any parameters you pass into this script will be passed along into the cmake command. However, you should prefer to do simple full builds instead of targeted builds. Ninja is good
at doing incremental builds quickly.

### Testing

To run tests after building:

```powershell
# Run unit tests
.\build\Debug\UnitTestsRunner.exe

# Run system tests
.\build\Debug\SystemTestsRunner.exe
```

Or use the build script to build first, then run tests:

```powershell
.\utils\copilot-build.ps1 --config Debug
.\build\Debug\UnitTestsRunner.exe
.\build\Debug\SystemTestsRunner.exe
```

### Clean Build

**WARNING: Never perform a clean build without asking the user first.** Full builds take a very long time and are almost never needed. Most issues can be resolved with a regular incremental build.

If a clean build is specifically requested:

```powershell
# Using the build script (preferred)
.\utils\copilot-build.ps1 --target clean --config Debug

# Or manually
cmd.exe /c "call `"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat`" && cd /d `"%cd%\build`" && cmake --build . --target clean && cmake --build . --config Debug"
```

## Repository Structure Notes

- Source code is in the `source/` directory
- Examples are in the `examples/` directory
- Generated code is in the `generated/` directory
- Build artifacts go in the `build/` directory
- The project uses gRPC and Protocol Buffers for communication

## Python Components

This repository also contains Python components. When working with Python:

1. Use the virtual environment created by the build system
2. Install dependencies from `python_build_requirements.txt`
3. Python examples are located in the `examples/` directory
4 changes: 4 additions & 0 deletions .github/workflows/create_client_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Initialize ni-apis submodule
run: |
git submodule update --init third_party/ni-apis

- name: Setup python3
uses: actions/setup-python@v5
with:
Expand Down
24 changes: 19 additions & 5 deletions .github/workflows/sync_github_issues_to_azdo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ name: Sync issue to Azure DevOps work item

on:
issues:
# Omit "labeled" and "unlabeled" to work around https://github.com/danhellem/github-actions-issue-to-work-item/issues/70
types:
[opened, edited, deleted, closed, reopened, labeled, unlabeled, assigned]
[opened, edited, deleted, closed, reopened, assigned]
issue_comment:
types: [created, edited, deleted]

jobs:
alert:
if: ${{ !github.event.issue.pull_request && github.event.issue.title != 'Dependency Dashboard' }}
runs-on: ubuntu-latest
steps:
- uses: danhellem/github-actions-issue-to-work-item@master
- name: Choose work item type
id: choose_work_item_type
run: |
if [ "${{ contains(github.event.issue.labels.*.name, 'enhancement') || contains(github.event.issue.labels.*.name, 'user story') }}" == "true" ]; then
echo "work_item_type=User Story" >> $GITHUB_OUTPUT
elif [ "${{ contains(github.event.issue.labels.*.name, 'tech debt') }}" == "true" ]; then
echo "work_item_type=Technical Debt" >> $GITHUB_OUTPUT
else
echo "work_item_type=Bug" >> $GITHUB_OUTPUT
fi
- uses: danhellem/github-actions-issue-to-work-item@45eb3b46e684f2acd2954f02ef70350c835ee4bb # v2.4
env:
ado_token: "${{ secrets.AZDO_Work_Item_Token }}"
ado_token: "${{ secrets.AZDO_WORK_ITEM_TOKEN }}"
github_token: "${{ secrets.GH_REPO_TOKEN }}"
ado_organization: "ni"
ado_project: "DevCentral"
ado_area_path: "DevCentral\\Product RnD\\Platform HW and SW\\Core SW and Drivers\\Platform HW and Drivers\\Drivers\\Customer Facing"
ado_wit: "Bug"
ado_wit: "${{ steps.choose_work_item_type.outputs.work_item_type }}"
ado_new_state: "New"
ado_active_state: "Active"
ado_close_state: "Closed"
ado_bypassrules: true
log_level: 100
log_level: 100
69 changes: 67 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c17") # Needed for boringssl
endif()

# GCC-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-var-tracking-assignments")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-var-tracking-assignments")
endif()

#----------------------------------------------------------------------
# Use C++17 (needed for shared_mutex support on Linux)
#----------------------------------------------------------------------
Expand Down Expand Up @@ -289,6 +295,8 @@ get_filename_component(deviceid_restricted_proto "source/protobuf_restricted/dev
get_filename_component(debugsessionproperties_restricted_proto "source/protobuf_restricted/debugsessionproperties_restricted.proto" ABSOLUTE)
get_filename_component(calibrationoperations_restricted_proto "source/protobuf_restricted/calibrationoperations_restricted.proto" ABSOLUTE)
get_filename_component(data_moniker_proto "imports/protobuf/data_moniker.proto" ABSOLUTE)
get_filename_component(precision_timestamp_proto "third_party/ni-apis/ni/protobuf/types/precision_timestamp.proto" ABSOLUTE)
get_filename_component(waveform_proto "third_party/ni-apis/ni/protobuf/types/waveform.proto" ABSOLUTE)
get_filename_component(session_proto_path "${session_proto}" PATH)

#----------------------------------------------------------------------
Expand All @@ -303,8 +311,9 @@ function(GenerateGrpcSources)
set(proto_file "${GENERATE_ARGS_PROTO}")
if(USE_SUBMODULE_LIBS)
set(protobuf_includes_arg
-I ${CMAKE_SOURCE_DIR}/third_party/grpc/third_party/protobuf/src/
-I ${CMAKE_SOURCE_DIR}/third_party/ni-apis/ni/grpcdevice/v1/) # for session.proto
-I ${CMAKE_SOURCE_DIR}/third_party/grpc/third_party/protobuf/src/
-I ${CMAKE_SOURCE_DIR}/third_party/ni-apis/ni/grpcdevice/v1/ # for session.proto
-I ${CMAKE_SOURCE_DIR}/third_party/ni-apis/)
endif()
get_filename_component(proto_name "${proto_file}" NAME)
get_filename_component(proto_path "${proto_file}" PATH)
Expand Down Expand Up @@ -346,6 +355,34 @@ function(GenerateGrpcSources)
endif()
endfunction()

#----------------------------------------------------------------------
# Generate sources from ni-apis proto files
# Usage: GenerateNiApisProtoSources(PROTO_PATH <relative_path> OUTPUT_SRCS <var> OUTPUT_HDRS <var> [DEPENDS <dependency>...])
#----------------------------------------------------------------------
function(GenerateNiApisProtoSources)
set(oneValueArgs PROTO_PATH OUTPUT_SRCS OUTPUT_HDRS)
set(multiValueArgs DEPENDS)
cmake_parse_arguments(GEN_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(proto_srcs "${proto_srcs_dir}/${GEN_ARGS_PROTO_PATH}.pb.cc")
set(proto_hdrs "${proto_srcs_dir}/${GEN_ARGS_PROTO_PATH}.pb.h")

add_custom_command(
OUTPUT "${proto_srcs}" "${proto_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --cpp_out ${proto_srcs_dir}
-I ${CMAKE_SOURCE_DIR}/third_party/ni-apis/
-I ${CMAKE_SOURCE_DIR}/third_party/grpc/third_party/protobuf/src/
${GEN_ARGS_PROTO_PATH}.proto
DEPENDS "${CMAKE_SOURCE_DIR}/third_party/ni-apis/${GEN_ARGS_PROTO_PATH}.proto" ${GEN_ARGS_DEPENDS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third_party/ni-apis/
VERBATIM
)

set(${GEN_ARGS_OUTPUT_SRCS} "${proto_srcs}" PARENT_SCOPE)
set(${GEN_ARGS_OUTPUT_HDRS} "${proto_hdrs}" PARENT_SCOPE)
endfunction()

set(session_proto_srcs "${proto_srcs_dir}/session.pb.cc")
set(session_proto_hdrs "${proto_srcs_dir}/session.pb.h")
set(session_grpc_srcs "${proto_srcs_dir}/session.grpc.pb.cc")
Expand All @@ -372,6 +409,10 @@ set(data_moniker_proto_srcs "${proto_srcs_dir}/data_moniker.pb.cc")
set(data_moniker_proto_hdrs "${proto_srcs_dir}/data_moniker.pb.h")
set(data_moniker_grpc_srcs "${proto_srcs_dir}/data_moniker.grpc.pb.cc")
set(data_moniker_grpc_hdrs "${proto_srcs_dir}/data_moniker.grpc.pb.h")
set(precision_timestamp_proto_srcs "${proto_srcs_dir}/ni/protobuf/types/precision_timestamp.pb.cc")
set(precision_timestamp_proto_hdrs "${proto_srcs_dir}/ni/protobuf/types/precision_timestamp.pb.h")
set(waveform_proto_srcs "${proto_srcs_dir}/ni/protobuf/types/waveform.pb.cc")
set(waveform_proto_hdrs "${proto_srcs_dir}/ni/protobuf/types/waveform.pb.h")

GenerateGrpcSources(
PROTO
Expand Down Expand Up @@ -441,6 +482,19 @@ GenerateGrpcSources(
"${data_moniker_grpc_hdrs}"
)

GenerateNiApisProtoSources(
PROTO_PATH "ni/protobuf/types/precision_timestamp"
OUTPUT_SRCS precision_timestamp_proto_srcs
OUTPUT_HDRS precision_timestamp_proto_hdrs
)

GenerateNiApisProtoSources(
PROTO_PATH "ni/protobuf/types/waveform"
OUTPUT_SRCS waveform_proto_srcs
OUTPUT_HDRS waveform_proto_hdrs
DEPENDS "${precision_timestamp_proto_hdrs}"
)

set(nidriver_service_library_hdrs
${nidriver_service_library_hdrs}
"${session_proto_hdrs}"
Expand All @@ -454,6 +508,8 @@ set(nidriver_service_library_hdrs
"${debugsessionproperties_restricted_grpc_hdrs}"
"${calibrationoperations_restricted_proto_hdrs}"
"${calibrationoperations_restricted_grpc_hdrs}"
"${precision_timestamp_proto_hdrs}"
"${waveform_proto_hdrs}"
)

foreach(api ${nidrivers})
Expand Down Expand Up @@ -514,6 +570,8 @@ add_executable(ni_grpc_device_server
${calibrationoperations_restricted_grpc_srcs}
${data_moniker_proto_srcs}
${data_moniker_grpc_srcs}
${precision_timestamp_proto_srcs}
${waveform_proto_srcs}
${nidriver_service_srcs})

# Enable warnings only on source that we own, not generated code or dependencies
Expand Down Expand Up @@ -655,6 +713,8 @@ add_executable(IntegrationTestsRunner
${calibrationoperations_restricted_grpc_srcs}
${data_moniker_proto_srcs}
${data_moniker_grpc_srcs}
${precision_timestamp_proto_srcs}
${waveform_proto_srcs}
${nidriver_service_srcs}
"${proto_srcs_dir}/nifake.pb.cc"
"${proto_srcs_dir}/nifake.grpc.pb.cc"
Expand Down Expand Up @@ -711,6 +771,7 @@ add_executable(UnitTestsRunner
"source/tests/unit/ni_fake_non_ivi_service_tests.cpp"
"source/tests/unit/ni_fake_service_tests.cpp"
"source/tests/unit/nimxlc_terminal_adaptor_converters_tests.cpp"
"source/tests/unit/precision_timestamp_converter_tests.cpp"
"source/tests/unit/shared_library_tests.cpp"
"source/tests/unit/syscfg_library_tests.cpp"
"source/tests/unit/syscfg_resource_accessor_tests.cpp"
Expand Down Expand Up @@ -742,6 +803,8 @@ add_executable(UnitTestsRunner
${calibrationoperations_restricted_grpc_srcs}
${data_moniker_proto_srcs}
${data_moniker_grpc_srcs}
${precision_timestamp_proto_srcs}
${waveform_proto_srcs}
"${proto_srcs_dir}/nifake.pb.cc"
"${proto_srcs_dir}/nifake.grpc.pb.cc"
"${proto_srcs_dir}/nifake_extension.pb.cc"
Expand Down Expand Up @@ -879,6 +942,8 @@ set(system_test_runner_sources
${calibrationoperations_restricted_grpc_srcs}
${data_moniker_proto_srcs}
${data_moniker_grpc_srcs}
${precision_timestamp_proto_srcs}
${waveform_proto_srcs}
${nidriver_service_srcs}
${nidriver_client_srcs}
)
Expand Down
16 changes: 15 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Build a release build for use in a production environment:
> cmake --build . --config Release
```

### Build with Ninja

Build faster by using Ninja:

```
> "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
> mkdir build
> cd build
> cmake .. -G "Ninja Multi-Config"
> cmake --build .
```

## Building on Linux

### Prerequisites
Expand All @@ -77,7 +89,9 @@ For Debian/Ubuntu, install git, cmake (3.18.0 or newer), and mako:
> sudo apt-get update
> sudo apt-get install git
> sudo apt-get install cmake
> python -m pip install mako
> sudo apt-get install g++
> sudo apt-get install python3-venv # for ensurepip
> sudo apt-get install ninja-build # optional
```

For NI Linux RT, install packagegroup-core-buildessential, git, git-perltools, cmake (3.18.0 or newer), python3-utils, and mako:
Expand Down
Loading
Loading