From 8b7fda61122e028d8afed260c2223e2b3be596b9 Mon Sep 17 00:00:00 2001 From: 0xShug0 <231717474+0xShug0@users.noreply.github.com> Date: Sat, 5 Sep 2026 18:43:43 -0400 Subject: [PATCH] Add CLI and server version output --- CMakeLists.txt | 42 ++++++++++++++++++++++++ app/cli/main.cpp | 14 ++++++-- app/common/build_info.cpp | 53 +++++++++++++++++++++++++++++++ app/common/build_info.h | 10 ++++++ app/common/build_info_config.h.in | 11 +++++++ app/server/main.cpp | 7 ++++ 6 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 app/common/build_info.cpp create mode 100644 app/common/build_info.h create mode 100644 app/common/build_info_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 534b13a3a..6c32bfc5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.20) project(AudioCpp LANGUAGES C CXX) +set(AUDIOCPP_VERSION "dev" CACHE STRING "audio.cpp version string") + set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) @@ -116,6 +118,43 @@ set(AUDIOCPP_GGML_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/ggml" CACHE PATH "ggml source tree to build with AudioCPP") +set(AUDIOCPP_GIT_SHA "unknown") +set(AUDIOCPP_GIT_DATE "unknown") +find_package(Git QUIET) +if (GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE AUDIOCPP_GIT_SHA + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + execute_process( + COMMAND ${GIT_EXECUTABLE} show -s --format=%cs HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE AUDIOCPP_GIT_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) +endif() + +set(AUDIOCPP_BUILD_BACKENDS "cpu") +if (ENGINE_ENABLE_CUDA) + string(APPEND AUDIOCPP_BUILD_BACKENDS ",cuda") +endif() +if (ENGINE_ENABLE_HIP) + string(APPEND AUDIOCPP_BUILD_BACKENDS ",hip") +endif() +if (ENGINE_ENABLE_VULKAN) + string(APPEND AUDIOCPP_BUILD_BACKENDS ",vulkan") +endif() +if (ENGINE_ENABLE_METAL) + string(APPEND AUDIOCPP_BUILD_BACKENDS ",metal") +endif() +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/app/common/build_info_config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/generated/build_info_config.h" + @ONLY +) + # HIP compiles ggml's CUDA backend sources as HIP code, so the two options drive the # same ggml backend and cannot coexist: enabling both starts CUDA backend setup and # HIP backend setup in the same configure, which fails in confusing ways downstream. @@ -1873,6 +1912,7 @@ if (ENGINE_ENABLE_CUDA AND NOT ENGINE_ENABLE_HIP) endif() add_executable(audiocpp_cli + app/common/build_info.cpp app/cli/main.cpp app/cli/args.cpp app/cli/batch.cpp @@ -1886,6 +1926,7 @@ add_executable(audiocpp_cli ) target_link_libraries(audiocpp_cli PRIVATE engine_runtime ggml) +target_include_directories(audiocpp_cli PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated") # MinGW selects the wmain() entry point only when linked with -municode; # without it the CLI fails to link (undefined reference / ld error 5). # MSVC detects wmain natively, so this is MinGW-only. Link option only: @@ -1942,6 +1983,7 @@ configure_file( ) add_executable(audiocpp_server + app/common/build_info.cpp app/server/main.cpp app/server/base64.cpp app/server/config.cpp diff --git a/app/cli/main.cpp b/app/cli/main.cpp index ad59f4555..dd5ca47dd 100644 --- a/app/cli/main.cpp +++ b/app/cli/main.cpp @@ -2,6 +2,7 @@ #include "batch.h" #include "partial_render.h" #include "request.h" +#include "../common/build_info.h" #include "../streaming/pcm_source.h" #include "../streaming/streaming.h" #include "../workflow/execution.h" @@ -51,6 +52,7 @@ void print_task_list_help() { std::cout << "audiocpp_cli --task --family --model --backend [options]\n" << " Global:\n" + << " --version Print build version, commit, compiler, platform, and enabled backends\n" << " --task vad|asr|diar|sep|gen|tts|clon|vc|s2s|align|vdes|spk|svc|midi\n" << " --family \n" << " --model \n" @@ -637,6 +639,10 @@ int audiocpp_cli_main(int argc, char ** argv) { log_file, }); const bool metrics_requested = has_arg(argc, argv, "--metrics"); + if (has_arg(argc, argv, "--version")) { + minitts::app::print_build_info(std::cout); + return 0; + } const auto registry_config = find_arg(argc, argv, "--registry-config"); auto registry = engine::runtime::make_default_registry( @@ -769,6 +775,10 @@ int audiocpp_cli_main(int argc, char ** argv) { return 0; } if (!model_arg) { + if (argc == 1) { + minitts::app::print_build_info_summary(std::cerr); + std::cerr << "Run audiocpp_cli --help for usage.\n"; + } throw std::runtime_error("missing required --model argument"); } @@ -990,7 +1000,7 @@ int wmain(int argc, wchar_t ** wargv) { } argv.push_back(nullptr); const int status = audiocpp_cli_main(argc, argv.data()); - if (status == 0) { + if (status == 0 && !minitts::cli::has_arg(argc, argv.data(), "--version")) { minitts::cli::warn_ignored_args(argc, argv.data()); } return status; @@ -1002,7 +1012,7 @@ int wmain(int argc, wchar_t ** wargv) { #else int main(int argc, char ** argv) { const int status = audiocpp_cli_main(argc, argv); - if (status == 0) { + if (status == 0 && !minitts::cli::has_arg(argc, argv, "--version")) { minitts::cli::warn_ignored_args(argc, argv); } return status; diff --git a/app/common/build_info.cpp b/app/common/build_info.cpp new file mode 100644 index 000000000..8f0619bf8 --- /dev/null +++ b/app/common/build_info.cpp @@ -0,0 +1,53 @@ +#include "build_info.h" + +#include "build_info_config.h" + +#include +#include + +namespace minitts::app { +namespace { + +std::string build_type() { + std::string value = AUDIOCPP_BUILD_TYPE_STRING; + if (value.empty()) { + value = "unknown"; + } + return value; +} + +std::string compiler_name() { + const std::string id = AUDIOCPP_COMPILER_ID_STRING; + const std::string version = AUDIOCPP_COMPILER_VERSION_STRING; + if (id == "GNU") { + return "gcc " + version; + } + if (id == "Clang") { + return "clang " + version; + } + if (id == "AppleClang") { + return "apple-clang " + version; + } + if (id == "MSVC") { + return "msvc " + version; + } + return id.empty() ? "unknown" : id + " " + version; +} + +} // namespace + +void print_build_info(std::ostream & out) { + out << "audio.cpp " << AUDIOCPP_VERSION_STRING << "\n" + << "git: " << AUDIOCPP_GIT_SHA_STRING << " " << AUDIOCPP_GIT_DATE_STRING << "\n" + << "build: " << build_type() << ", " << compiler_name() << ", " + << AUDIOCPP_SYSTEM_NAME_STRING << " " << AUDIOCPP_SYSTEM_PROCESSOR_STRING << "\n" + << "backends: " << AUDIOCPP_BUILD_BACKENDS_STRING << "\n"; +} + +void print_build_info_summary(std::ostream & out) { + out << "audio.cpp " << AUDIOCPP_VERSION_STRING + << " (git " << AUDIOCPP_GIT_SHA_STRING << ", " << build_type() << ")" + << " [backends: " << AUDIOCPP_BUILD_BACKENDS_STRING << "]\n"; +} + +} // namespace minitts::app diff --git a/app/common/build_info.h b/app/common/build_info.h new file mode 100644 index 000000000..64f01cc9f --- /dev/null +++ b/app/common/build_info.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace minitts::app { + +void print_build_info(std::ostream & out); +void print_build_info_summary(std::ostream & out); + +} // namespace minitts::app diff --git a/app/common/build_info_config.h.in b/app/common/build_info_config.h.in new file mode 100644 index 000000000..bebb520e4 --- /dev/null +++ b/app/common/build_info_config.h.in @@ -0,0 +1,11 @@ +#pragma once + +#define AUDIOCPP_VERSION_STRING "@AUDIOCPP_VERSION@" +#define AUDIOCPP_GIT_SHA_STRING "@AUDIOCPP_GIT_SHA@" +#define AUDIOCPP_GIT_DATE_STRING "@AUDIOCPP_GIT_DATE@" +#define AUDIOCPP_BUILD_TYPE_STRING "@CMAKE_BUILD_TYPE@" +#define AUDIOCPP_COMPILER_ID_STRING "@CMAKE_CXX_COMPILER_ID@" +#define AUDIOCPP_COMPILER_VERSION_STRING "@CMAKE_CXX_COMPILER_VERSION@" +#define AUDIOCPP_SYSTEM_NAME_STRING "@CMAKE_SYSTEM_NAME@" +#define AUDIOCPP_SYSTEM_PROCESSOR_STRING "@CMAKE_SYSTEM_PROCESSOR@" +#define AUDIOCPP_BUILD_BACKENDS_STRING "@AUDIOCPP_BUILD_BACKENDS@" diff --git a/app/server/main.cpp b/app/server/main.cpp index 1fec357ef..bc4287b75 100644 --- a/app/server/main.cpp +++ b/app/server/main.cpp @@ -2,6 +2,8 @@ #include "http.h" #include "runtime.h" +#include "../common/build_info.h" + #include "engine/framework/core/backend.h" #include "engine/framework/debug/trace.h" @@ -66,6 +68,7 @@ void print_help() { << " [--model-spec-override ] [--voice-dir ]\n" << " [--log] [--log-file ]\n" << " [--cors-origins ]\n" + << " --version print build version, commit, compiler, platform, and enabled backends\n" << " --ui serve the embedded WebUI\n" << " --no-ui disable the embedded WebUI\n" << " --ui-management allow WebUI model management and downloads; requires\n" @@ -127,6 +130,10 @@ int main(int argc, char ** argv) { engine::core::print_backend_devices(std::cout); return 0; } + if (has_arg(argc, argv, "--version")) { + minitts::app::print_build_info(std::cout); + return 0; + } if (has_arg(argc, argv, "--help") || has_arg(argc, argv, "-h")) { print_help(); return 0;