mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-10 09:40:23 -04:00
52b6c66fa1
# Description of Changes This adds C++ server bindings (/crate/bindings-cpp) to allow writing C++ 20 modules. - Emscripten WASM build system integration with CMake - Macro-based code generation (SPACETIMEDB_TABLE, SPACETIMEDB_REDUCER, etc) - All SpacetimeDB types supported (primitives, Timestamp, Identity, Uuid, etc) - Product types via SPACETIMEDB_STRUCT - Sum types via SPACETIMEDB_ENUM - Constraints marked with FIELD* macros # API and ABI breaking changes None # Expected complexity level and risk 2 - Doesn't heavily impact any other areas but is complex macro C++ structure to support a similar developer experience, did have a small impact on init command # Testing - [x] modules/module-test-cpp - heavily tested every reducer - [x] modules/benchmarks-cpp - tested through the standalone (~6x faster than C#, ~6x slower than Rust) - [x] modules/sdk-test-cpp - [x] modules/sdk-test-procedure-cpp - [x] modules/sdk-test-view-cpp - [x] Wrote several test modules myself - [x] Quickstart smoketest [Currently in progress] - [ ] Write Blackholio C++ server module --------- Signed-off-by: Jason Larabie <jason@clockworklabs.io> Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: Ryan <r.ekhoff@clockworklabs.io> Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
91 lines
2.4 KiB
C
91 lines
2.4 KiB
C
#pragma once
|
|
|
|
#include <cstdio>
|
|
|
|
/**
|
|
* @file debug.h
|
|
* @brief Conditional debugging macros for SpacetimeDB C++ bindings
|
|
*
|
|
* This header provides conditional debugging output that can be enabled/disabled
|
|
* at compile time to reduce runtime overhead and output clutter.
|
|
*/
|
|
|
|
// Control debug output with compile-time flag
|
|
#ifdef SPACETIMEDB_DEBUG
|
|
#define STDB_DEBUG_ENABLED 1
|
|
#else
|
|
#define STDB_DEBUG_ENABLED 0
|
|
#endif
|
|
|
|
/**
|
|
* @brief Main debug macro - outputs to stderr with [STDB] prefix
|
|
*
|
|
* Usage: STDB_DEBUG("Type %s registered with index %u", type_name.c_str(), index);
|
|
*
|
|
* When SPACETIMEDB_DEBUG is not defined, this compiles to nothing (zero overhead).
|
|
*/
|
|
#if STDB_DEBUG_ENABLED
|
|
#define STDB_DEBUG(fmt, ...) \
|
|
fprintf(stderr, "[STDB] " fmt "\n", ##__VA_ARGS__)
|
|
#else
|
|
#define STDB_DEBUG(fmt, ...) ((void)0)
|
|
#endif
|
|
|
|
/**
|
|
* @brief Verbose debug macro for detailed tracing
|
|
*
|
|
* Usage: STDB_VERBOSE("Processing field %zu: %s", i, field_name);
|
|
*
|
|
* Even more detailed than STDB_DEBUG, only enabled with SPACETIMEDB_VERBOSE.
|
|
*/
|
|
#ifdef SPACETIMEDB_VERBOSE
|
|
#define STDB_VERBOSE(fmt, ...) \
|
|
fprintf(stderr, "[STDB:VERBOSE] " fmt "\n", ##__VA_ARGS__)
|
|
#else
|
|
#define STDB_VERBOSE(fmt, ...) ((void)0)
|
|
#endif
|
|
|
|
/**
|
|
* @brief Error output (always enabled)
|
|
*
|
|
* Usage: STDB_ERROR("Failed to register type: %s", error_msg);
|
|
*
|
|
* Always outputs regardless of debug flags.
|
|
*/
|
|
#define STDB_ERROR(fmt, ...) \
|
|
fprintf(stderr, "[STDB:ERROR] " fmt "\n", ##__VA_ARGS__)
|
|
|
|
/**
|
|
* @brief Warning output (always enabled)
|
|
*
|
|
* Usage: STDB_WARN("Type %s already registered", type_name);
|
|
*
|
|
* Always outputs regardless of debug flags.
|
|
*/
|
|
#define STDB_WARN(fmt, ...) \
|
|
fprintf(stderr, "[STDB:WARN] " fmt "\n", ##__VA_ARGS__)
|
|
|
|
/**
|
|
* @brief Conditional debug macro for specific subsystems
|
|
*
|
|
* Usage: STDB_DEBUG_TYPE("Registered enum %s", enum_name);
|
|
*
|
|
* Can be independently controlled with SPACETIMEDB_DEBUG_TYPE.
|
|
*/
|
|
#ifdef SPACETIMEDB_DEBUG_TYPE
|
|
#define STDB_DEBUG_TYPE(fmt, ...) \
|
|
fprintf(stderr, "[STDB:TYPE] " fmt "\n", ##__VA_ARGS__)
|
|
#else
|
|
#define STDB_DEBUG_TYPE(fmt, ...) ((void)0)
|
|
#endif
|
|
|
|
// Usage example in code:
|
|
// #define SPACETIMEDB_DEBUG // Enable general debugging
|
|
// #include "debug.h"
|
|
//
|
|
// void registerType() {
|
|
// STDB_DEBUG("Starting type registration");
|
|
// STDB_VERBOSE("Detailed step-by-step trace");
|
|
// STDB_ERROR("Something went wrong");
|
|
// STDB_WARN("Non-fatal issue");
|
|
// }
|