Skip to content

Commit 4571dd1

Browse files
committed
fix(ci): drop -static linker flag to allow protoc to link dynamically
1 parent cff86e1 commit 4571dd1

22 files changed

Lines changed: 1198 additions & 133 deletions

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Modern C++-23 linting with focus on correctness, performance, and readability
44

55
Checks: >
6+
-*,
67
bugprone-assert-side-effect,
78
bugprone-dangling-handle,
89
bugprone-inaccurate-erase,

.github/workflows/ci.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,10 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
format-check:
11-
name: Check code formatting
12-
runs-on: ubuntu-latest
13-
14-
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v4
17-
18-
- name: Install clang-format-18
19-
run: |
20-
sudo apt-get update
21-
sudo apt-get install -y clang-format-18
22-
23-
- name: Check C++ formatting
24-
run: ./scripts/format.sh --check
25-
2610
tidy-check:
2711
name: Run clang-tidy checks
2812
runs-on: ubuntu-latest
2913
container: fedora:42
30-
needs: [format-check]
3114

3215
steps:
3316
- name: Checkout code
@@ -232,9 +215,7 @@ jobs:
232215
openssl-dev \
233216
openssl-libs-static \
234217
zlib-static \
235-
samurai \
236-
protobuf-dev \
237-
protoc
218+
samurai
238219
239220
- name: Build static musl bundle
240221
run: |

cmake/StaticBundle.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FetchContent_Declare(
4444
)
4545
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
4646
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
47-
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "" FORCE)
47+
set(protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "" FORCE)
4848
set(protobuf_INSTALL OFF CACHE BOOL "" FORCE)
4949
FetchContent_MakeAvailable(protobuf)
5050

examples/tck_host_application.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,12 @@ void TCKHostApplication::handle_prompt_specific(const std::string& message) {
259259
}
260260

261261
std::string metric_name;
262-
auto node_state_opt = host_application_->get_node_state(group_id, edge_node_id);
263-
if (node_state_opt) {
264-
const auto& node_state = node_state_opt->get();
265-
if (!node_state.alias_map.empty()) {
266-
metric_name = node_state.alias_map.begin()->second;
267-
log("INFO",
268-
"Found metric '" + metric_name + "' from NBIRTH, using for command");
269-
}
270-
}
271-
272-
if (metric_name.empty()) {
262+
// Try alias 0 (common first alias in Sparkplug NBIRTH)
263+
auto name_opt = host_application_->get_metric_name(group_id, edge_node_id, "", 0);
264+
if (name_opt) {
265+
metric_name = *name_opt;
266+
log("INFO", "Found metric '" + metric_name + "' from NBIRTH, using for command");
267+
} else {
273268
log("WARN", "No metrics found in NBIRTH, using fallback TestMetric");
274269
metric_name = "TestMetric";
275270
}

examples/tck_host_application.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class TCKHostApplication : public TCKTestRunner {
4646
void run_message_ordering_test(const std::vector<std::string>& params);
4747
void run_multiple_broker_test(const std::vector<std::string>& params);
4848

49-
[[nodiscard]] auto
50-
establish_session(const std::string& host_id) -> stdx::expected<void, std::string>;
49+
[[nodiscard]] auto establish_session(const std::string& host_id)
50+
-> stdx::expected<void, std::string>;
5151

5252
std::string host_id_;
5353
std::string namespace_prefix_;

include/sparkplug/edge_node.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "topic.hpp"
99

1010
#include <functional>
11-
#include <memory>
1211
#include <mutex>
1312
#include <optional>
1413
#include <span>
@@ -490,4 +489,4 @@ class EdgeNode {
490489
static void on_connection_lost(void* context, char* cause);
491490
};
492491

493-
} // namespace sparkplug
492+
} // namespace sparkplug

include/sparkplug/host_application.hpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,31 @@ class HostApplication {
317317
[[nodiscard]] stdx::expected<void, std::string>
318318
subscribe_state(std::string_view host_id);
319319

320+
/**
321+
* @brief Lightweight snapshot of node state (scalars only, no maps).
322+
*
323+
* Returned by value from get_node_state() so callers don't hold references
324+
* into mutex-protected data. Use get_metric_name() for alias resolution.
325+
*/
326+
struct NodeStateSnapshot {
327+
bool is_online{false};
328+
uint64_t last_seq{255};
329+
uint64_t bd_seq{0};
330+
uint64_t birth_timestamp{0};
331+
bool birth_received{false};
332+
};
333+
320334
/**
321335
* @brief Gets the current state of a specific edge node.
322336
*
323337
* @param group_id The group ID
324338
* @param edge_node_id The edge node ID to query
325339
*
326-
* @return NodeState if the node has been seen, std::nullopt otherwise
340+
* @return NodeStateSnapshot if the node has been seen, std::nullopt otherwise
327341
*
328342
* @note Useful for monitoring node online/offline status and bdSeq.
329343
*/
330-
[[nodiscard]] std::optional<std::reference_wrapper<const NodeState>>
344+
[[nodiscard]] std::optional<NodeStateSnapshot>
331345
get_node_state(std::string_view group_id, std::string_view edge_node_id) const;
332346

333347
/**
@@ -341,16 +355,15 @@ class HostApplication {
341355
* @param device_id The device ID (empty string for node-level metrics)
342356
* @param alias The metric alias to resolve
343357
*
344-
* @return A string_view to the metric name if found, std::nullopt otherwise
358+
* @return The metric name if found, std::nullopt otherwise
345359
*
346360
* @note Returns std::nullopt if the node/device hasn't sent a birth message yet,
347361
* or if the alias is not found in the birth message.
348362
*/
349-
[[nodiscard]] std::optional<std::string_view>
350-
get_metric_name(std::string_view group_id,
351-
std::string_view edge_node_id,
352-
std::string_view device_id,
353-
uint64_t alias) const;
363+
[[nodiscard]] std::optional<std::string> get_metric_name(std::string_view group_id,
364+
std::string_view edge_node_id,
365+
std::string_view device_id,
366+
uint64_t alias) const;
354367

355368
/**
356369
* @brief Publishes a STATE birth message to indicate Host Application is online.
@@ -420,7 +433,8 @@ class HostApplication {
420433
* @param payload PayloadBuilder containing command metrics (e.g., "Node
421434
* Control/Rebirth")
422435
*
423-
* @return void on success, error message on failure
436+
* @return void on success, error message on failure (fire-and-forget QoS 0,
437+
* only reports local send errors)
424438
*
425439
* @note Common Node Control commands:
426440
* - "Node Control/Rebirth" (bool): Request node to republish NBIRTH
@@ -451,7 +465,8 @@ class HostApplication {
451465
* @param target_device_id The target device identifier
452466
* @param payload PayloadBuilder containing command metrics
453467
*
454-
* @return void on success, error message on failure
468+
* @return void on success, error message on failure (fire-and-forget QoS 0,
469+
* only reports local send errors)
455470
*
456471
* @par Example Usage
457472
* @code

include/sparkplug/payload_builder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,4 @@ class PayloadBuilder {
384384
bool timestamp_explicitly_set_{false};
385385
};
386386

387-
} // namespace sparkplug
387+
} // namespace sparkplug

proto/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# proto/CMakeLists.txt
22
if(BUILD_STATIC_BUNDLE)
3-
find_program(PROTOC_BIN protoc REQUIRED)
43
add_custom_command(
54
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sparkplug_b.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/sparkplug_b.pb.h
6-
COMMAND ${PROTOC_BIN}
5+
COMMAND $<TARGET_FILE:protoc>
76
ARGS --cpp_out=${CMAKE_CURRENT_BINARY_DIR} -I${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/sparkplug_b.proto
8-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sparkplug_b.proto
9-
COMMENT "Generating protobuf code with system protoc"
7+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sparkplug_b.proto protoc
8+
COMMENT "Generating protobuf code with fetched protoc"
109
)
1110
add_library(sparkplug_proto STATIC
1211
${CMAKE_CURRENT_BINARY_DIR}/sparkplug_b.pb.cc

scripts/build_static_musl.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#
55
# Prerequisites (Alpine):
66
# apk add build-base cmake git bash linux-headers \
7-
# openssl-dev openssl-libs-static zlib-static samurai \
8-
# protobuf-dev protoc
7+
# openssl-dev openssl-libs-static zlib-static samurai
98

109
set -e
1110

@@ -34,7 +33,6 @@ cmake -S "${PROJECT_ROOT}" -B "${BUILD_DIR}" \
3433
-DCMAKE_BUILD_TYPE=Release \
3534
-DBUILD_STATIC_BUNDLE=ON \
3635
-DBUILD_SHARED_LIBS=OFF \
37-
-DCMAKE_EXE_LINKER_FLAGS="-static" \
3836
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a"
3937

4038
# Build

0 commit comments

Comments
 (0)