Skip to content

Commit 57560da

Browse files
committed
Merge branch 'main' of github.com:viamrobotics/viam-cpp-sdk into 20250514-RSDK-13982-construct-model-table
2 parents dbe6b9b + e071c81 commit 57560da

6 files changed

Lines changed: 65 additions & 10 deletions

File tree

.github/workflows/update-templates.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ on:
1212
branch:
1313
required: true
1414
type: string
15+
rdk_branch:
16+
description: 'Branch of viamrobotics/rdk to check out for the generator'
17+
required: false
18+
type: string
19+
default: main
1520

1621
jobs:
1722
update_templates:
@@ -67,6 +72,7 @@ jobs:
6772
uses: actions/checkout@v6
6873
with:
6974
repository: viamrobotics/rdk
75+
ref: ${{ inputs.rdk_branch || 'main' }}
7076
path: rdk
7177

7278
- name: Build and install generator

CMakeLists.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ project(viam-cpp-sdk
4747
LANGUAGES CXX
4848
)
4949

50+
# Detect if we're building as a standalone module
51+
# vs being included via FetchContent by a downstream consumer
52+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
53+
set(VIAMCPPSDK_STANDALONE_BUILD ON)
54+
message(STATUS "viam-cpp-sdk: Standalone build mode")
55+
else()
56+
set(VIAMCPPSDK_STANDALONE_BUILD OFF)
57+
message(STATUS "viam-cpp-sdk: FetchContent mode (included by parent project)")
58+
endif()
59+
5060

5161
# Configure cmake-level options:
5262

@@ -113,7 +123,7 @@ option(VIAMCPPSDK_USE_LOCAL_PROTOS "Generate protos against sibling `api` direct
113123
# This causes the SDK's internal code to compile with `-Wall` and
114124
# `-Werror` flags.
115125
#
116-
option(VIAMCPPSDK_USE_WALL_WERROR "Build with -Wall and -Werror flags" ON)
126+
option(VIAMCPPSDK_USE_WALL_WERROR "Build with -Wall and -Werror flags" ${VIAMCPPSDK_STANDALONE_BUILD})
117127

118128

119129
# - `VIAMCPPSDK_SANITIZED_BUILD`
@@ -141,11 +151,15 @@ option(VIAMCPPSDK_CLANG_TIDY "Run the clang-tidy linter" OFF)
141151
#
142152
option(VIAMCPPSDK_OPENTELEMETRY_TRACING "Compile OpenTelemetry tracing into all gRPC calls" OFF)
143153

144-
# The following options are only defined if this project is not being included as a subproject
145-
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
146-
option(VIAMCPPSDK_BUILD_EXAMPLES "Build the example executables" ON)
147-
option(VIAMCPPSDK_BUILD_TESTS "Build the example executables" ON)
148-
endif()
154+
# - `VIAMCPPSDK_BUILD_EXAMPLES `
155+
#
156+
# Defaults to ON for standalone builds, OFF for FetchContent consumers.
157+
option(VIAMCPPSDK_BUILD_EXAMPLES "Build the example executables" ${VIAMCPPSDK_STANDALONE_BUILD})
158+
159+
# - `VIAMCPPSDK_BUILD_TESTS `
160+
#
161+
# Defaults to ON for standalone builds, OFF for FetchContent consumers.
162+
option(VIAMCPPSDK_BUILD_TESTS "Build the example executables" ${VIAMCPPSDK_STANDALONE_BUILD})
149163

150164

151165
# Enforce known toolchains and toolchain minima unless asked not to.

res/module_generator/_templates/components/generic.cpp.in

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace {{ .ModuleSnake }} {
77

88

99
{{ .ModelPascal }}::{{ .ModelPascal }}(const viam::sdk::Dependencies& deps, const viam::sdk::ResourceConfig& cfg)
10-
: Generic(cfg.name()) {
10+
: GenericComponent(cfg.name()) {
1111
throw std::runtime_error("constructor not implemented");
1212
}
1313

@@ -16,5 +16,20 @@ std::vector<std::string> {{ .ModelPascal }}::validate(const viam::sdk::ResourceC
1616
throw std::runtime_error("\"validate\" not implemented");
1717
}
1818

19+
viam::sdk::ProtoStruct {{ .ModelPascal }}::do_command(const viam::sdk::ProtoStruct & command)
20+
{
21+
throw std::logic_error("\"do_command\" not implemented");
22+
}
23+
24+
viam::sdk::ProtoStruct {{ .ModelPascal }}::get_status()
25+
{
26+
throw std::logic_error("\"get_status\" not implemented");
27+
}
28+
29+
std::vector<viam::sdk::GeometryConfig> {{ .ModelPascal }}::get_geometries(const viam::sdk::ProtoStruct & extra)
30+
{
31+
throw std::logic_error("\"get_geometries\" not implemented");
32+
}
33+
1934
} // namespace {{ .ModuleSnake }}
2035

res/module_generator/_templates/components/generic.hpp.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
namespace {{ .ModuleSnake }} {
1010

1111

12-
class {{ .ModelPascal }} : public viam::sdk::Generic {
12+
class {{ .ModelPascal }} : public viam::sdk::GenericComponent {
1313
public:
1414
{{ .ModelPascal }}(const viam::sdk::Dependencies& deps, const viam::sdk::ResourceConfig& cfg);
1515

1616
static std::vector<std::string> validate(const viam::sdk::ResourceConfig& cfg);
1717

18+
viam::sdk::ProtoStruct do_command(const viam::sdk::ProtoStruct & command) override;
19+
20+
viam::sdk::ProtoStruct get_status() override;
21+
22+
std::vector<viam::sdk::GeometryConfig> get_geometries(const viam::sdk::ProtoStruct & extra) override;
23+
1824
};
1925

2026
} // namespace {{ .ModuleSnake }}

res/module_generator/_templates/services/generic.cpp.in

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace {{ .ModuleSnake }} {
77

88

99
{{ .ModelPascal }}::{{ .ModelPascal }}(const viam::sdk::Dependencies& deps, const viam::sdk::ResourceConfig& cfg)
10-
: Generic(cfg.name()) {
10+
: GenericService(cfg.name()) {
1111
throw std::runtime_error("constructor not implemented");
1212
}
1313

@@ -16,5 +16,15 @@ std::vector<std::string> {{ .ModelPascal }}::validate(const viam::sdk::ResourceC
1616
throw std::runtime_error("\"validate\" not implemented");
1717
}
1818

19+
viam::sdk::ProtoStruct {{ .ModelPascal }}::do_command(const viam::sdk::ProtoStruct & command)
20+
{
21+
throw std::logic_error("\"do_command\" not implemented");
22+
}
23+
24+
viam::sdk::ProtoStruct {{ .ModelPascal }}::get_status()
25+
{
26+
throw std::logic_error("\"get_status\" not implemented");
27+
}
28+
1929
} // namespace {{ .ModuleSnake }}
2030

res/module_generator/_templates/services/generic.hpp.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
namespace {{ .ModuleSnake }} {
1010

1111

12-
class {{ .ModelPascal }} : public viam::sdk::Generic {
12+
class {{ .ModelPascal }} : public viam::sdk::GenericService {
1313
public:
1414
{{ .ModelPascal }}(const viam::sdk::Dependencies& deps, const viam::sdk::ResourceConfig& cfg);
1515

1616
static std::vector<std::string> validate(const viam::sdk::ResourceConfig& cfg);
1717

18+
viam::sdk::ProtoStruct do_command(const viam::sdk::ProtoStruct & command) override;
19+
20+
viam::sdk::ProtoStruct get_status() override;
21+
1822
};
1923

2024
} // namespace {{ .ModuleSnake }}

0 commit comments

Comments
 (0)