Jason Larabie 52b6c66fa1
Add C++ Bindings (#3544)
# 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>
2026-02-07 04:26:45 +00:00

1.5 KiB

sdk-test-view-cpp

C++ implementation of the SpacetimeDB view test module. This mirrors the Rust sdk-test-view module to ensure feature parity between the C++ and Rust SDKs.

Overview

This module tests the C++ bindings' view functionality including:

  • ViewContext views - Views with caller identity
  • AnonymousViewContext views - Views without caller identity
  • Optional return types - std::optional<T>
  • Vector return types - std::vector<T>
  • Table joins - Combining data from multiple tables
  • Filtering - Using indexed fields for efficient queries
  • Complex queries - Multi-table joins with filtering logic

Tables

  • player - Player entities with unique identities
  • player_level - Player levels indexed for filtering
  • player_location - Player positions with active status

Views

my_player

Returns the caller's player record.

  • Context: ViewContext (requires sender)
  • Returns: std::optional<Player>

my_player_and_level

Returns the caller's player joined with their level.

  • Context: ViewContext (requires sender)
  • Returns: std::optional<PlayerAndLevel>

players_at_level_0

Returns all players at level 0.

  • Context: AnonymousViewContext (no sender needed)
  • Returns: std::vector<Player>

nearby_players

Returns all active players within 5 units of the caller.

  • Context: ViewContext (requires sender)
  • Returns: std::vector<PlayerLocation>

Building

emcmake cmake -B build
cmake --build build

The output will be build/lib.wasm.