Skip to content
Open
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
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ semantic.cache
sems
sems_tests
sems-logfile-callextract
sems-stats
apps/monitoring/tools/target/
apps/monitoring/tools/vendor/
apps/monitoring/tools/.cargo/
apps/monitoring/tools/Cargo.lock
/core/plug-in/stats/sems-stats
/target/
/vendor/
/.cargo/
/Cargo.lock
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,42 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "")

enable_testing()

# Rust toolchain detection (used by tools/sems-stats and
# apps/monitoring/tools/*). A single workspace at the repo root means a
# single detection; SEMS_RUST_OK is plain (non-cache) so it propagates to
# every add_subdirectory() below.
set(SEMS_RUST_OK FALSE)
find_program(CARGO cargo)
if(CARGO)
execute_process(
COMMAND rustc --version
OUTPUT_VARIABLE RUSTC_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RUSTC_RESULT)
if(RUSTC_RESULT EQUAL 0)
string(REGEX MATCH "[0-9]+\\.[0-9]+" RUSTC_VERSION "${RUSTC_VERSION_OUTPUT}")
if(RUSTC_VERSION VERSION_GREATER_EQUAL "1.38")
set(SEMS_RUST_OK TRUE)
message(STATUS "Found cargo: ${CARGO}, rustc ${RUSTC_VERSION}")
else()
message(WARNING "rustc ${RUSTC_VERSION} found but >= 1.38 required; skipping Rust tools")
endif()
endif()
endif()

# Shared cargo build settings for any subdir that wants to invoke the
# root workspace. CARGO_PROFILE matches the subdir that `target/` lands
# in; CARGO_RELEASE_FLAG is the `--release` flag when in a non-Debug build.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CARGO_PROFILE "debug")
set(CARGO_RELEASE_FLAG "")
else()
set(CARGO_PROFILE "release")
set(CARGO_RELEASE_FLAG "--release")
endif()
set(SEMS_CARGO_WORKSPACE "${CMAKE_SOURCE_DIR}")
set(SEMS_CARGO_TARGET_DIR "${SEMS_CARGO_WORKSPACE}/target")

add_subdirectory(apps)
add_subdirectory(core)
add_subdirectory(tools)
Expand Down
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[workspace]
resolver = "2"
members = [
"apps/monitoring/tools/sems-monitoring-lib",
"apps/monitoring/tools/sems-list-calls",
"apps/monitoring/tools/sems-list-active-calls",
"apps/monitoring/tools/sems-list-finished-calls",
"apps/monitoring/tools/sems-get-callproperties",
"apps/monitoring/tools/sems-prometheus-exporter",
"tools/sems-stats",
]
43 changes: 11 additions & 32 deletions apps/monitoring/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,30 @@ install(
tools/sems_list_calls.py tools/sems_list_finished_calls.py
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)

# Rust-based monitoring tools (require rustc >= 1.38 for edition 2018)
find_program(CARGO cargo)
set(SEMS_RUST_OK FALSE)
if(CARGO)
execute_process(
COMMAND rustc --version
OUTPUT_VARIABLE RUSTC_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RUSTC_RESULT)
if(RUSTC_RESULT EQUAL 0)
string(REGEX MATCH "[0-9]+\\.[0-9]+" RUSTC_VERSION "${RUSTC_VERSION_OUTPUT}")
if(RUSTC_VERSION VERSION_GREATER_EQUAL "1.38")
set(SEMS_RUST_OK TRUE)
message(STATUS "Found cargo: ${CARGO}, rustc ${RUSTC_VERSION}")
else()
message(WARNING "rustc ${RUSTC_VERSION} found but >= 1.38 required; skipping Rust monitoring tools")
endif()
endif()
endif()

# Rust-based monitoring tools (require rustc >= 1.38 for edition 2018).
# Rust detection + shared cargo settings live in the root CMakeLists.txt so
# tools/ and apps/monitoring/tools/ can share one workspace and one target/.
if(SEMS_RUST_OK)
set(SEMS_MONITORING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CARGO_PROFILE "debug")
set(CARGO_RELEASE_FLAG "")
else()
set(CARGO_PROFILE "release")
set(CARGO_RELEASE_FLAG "--release")
endif()

set(SEMS_MONITORING_BINARIES
sems-list-calls
sems-list-active-calls
sems-list-finished-calls
sems-get-callproperties
sems-prometheus-exporter)

set(SEMS_MONITORING_CARGO_ARGS "")
foreach(bin ${SEMS_MONITORING_BINARIES})
list(APPEND SEMS_MONITORING_CARGO_ARGS "-p" "${bin}")
endforeach()

add_custom_target(sems-monitoring-tools ALL
COMMAND ${CARGO} build ${CARGO_RELEASE_FLAG}
--manifest-path ${SEMS_MONITORING_DIR}/Cargo.toml
--manifest-path ${SEMS_CARGO_WORKSPACE}/Cargo.toml
${SEMS_MONITORING_CARGO_ARGS}
COMMENT "Building sems monitoring tools (Rust)")

foreach(bin ${SEMS_MONITORING_BINARIES})
install(PROGRAMS ${SEMS_MONITORING_DIR}/target/${CARGO_PROFILE}/${bin}
install(PROGRAMS ${SEMS_CARGO_TARGET_DIR}/${CARGO_PROFILE}/${bin}
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)
endforeach()
else()
Expand Down
9 changes: 0 additions & 9 deletions apps/monitoring/tools/Cargo.toml

This file was deleted.

8 changes: 7 additions & 1 deletion core/plug-in/stats/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ set(sems_stats_SRCS query_stats.cxx)
add_executable(sems-stats ${sems_stats_SRCS})
target_link_libraries(sems-stats ${CMAKE_DL_LIBS} stdc++)

install(TARGETS sems-stats RUNTIME DESTINATION ${SEMS_EXEC_PREFIX}/sbin)
# When the Rust port (tools/sems-stats) is built it installs its own binary
# to the same path, so skip installing this C++ version to avoid the
# collision. The C++ target is still built so it remains a working fallback
# and a reference implementation. SEMS_RUST_OK is set in the root CMakeLists.
if(NOT SEMS_RUST_OK)
install(TARGETS sems-stats RUNTIME DESTINATION ${SEMS_EXEC_PREFIX}/sbin)
endif()

# library
set(stats_SRCS Statistics.cpp StatsUDPServer.cpp)
Expand Down
21 changes: 21 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,25 @@ install(
sems-rtp-mux-set-max-frame-age-ms sems-rtp-mux-set-mtu-threshold
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)

# sems-stats: Rust port of core/plug-in/stats/query_stats.cxx. Builds as
# part of the root Cargo workspace; the install is only wired when the
# Rust toolchain is available, which is also the signal for
# core/plug-in/stats/CMakeLists.txt to skip its C++ install.
if(SEMS_RUST_OK)
add_custom_target(sems-stats-rust ALL
COMMAND ${CARGO} build ${CARGO_RELEASE_FLAG}
--manifest-path ${SEMS_CARGO_WORKSPACE}/Cargo.toml
-p sems-stats
COMMENT "Building sems-stats (Rust)")

install(PROGRAMS ${SEMS_CARGO_TARGET_DIR}/${CARGO_PROFILE}/sems-stats
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)

add_test(
NAME sems-stats-cargo-tests
COMMAND ${CARGO} test ${CARGO_RELEASE_FLAG}
--manifest-path ${SEMS_CARGO_WORKSPACE}/Cargo.toml
-p sems-stats)
endif()

include(${CMAKE_SOURCE_DIR}/cmake/config.rules.txt)
14 changes: 14 additions & 0 deletions tools/sems-stats/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "sems-stats"
version = "0.1.0"
edition = "2018"
description = "UDP client for the SEMS stats plug-in (port of query_stats.cxx)"
license = "GPL-2.0-or-later"

[[bin]]
name = "sems-stats"
path = "src/main.rs"

[lib]
name = "sems_stats"
path = "src/lib.rs"
Loading
Loading