Skip to content

Commit fc94dd8

Browse files
Docs Update for C++ [4/4] (Blackholio) (#4169)
# Description of Changes In order to give reviewers a chance to finish in one session the docs are getting split up for the C++ update. This pass contains the following section update: - Unity Blackholio Tutorial - Unreal Blackholio Tutorial - Added /demo/Blackholio/server-cpp # API and ABI breaking changes N/A # Expected complexity level and risk 1 - Just documentation additions # Testing - [x] Manually tested each block
1 parent 2b309bd commit fc94dd8

9 files changed

Lines changed: 2181 additions & 1 deletion

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Build directories
2+
/build/
3+
/build_*/
4+
5+
# IDE files
6+
.vscode/
7+
.idea/
8+
*.swp
9+
*.swo
10+
11+
# OS generated files
12+
.DS_Store
13+
Thumbs.db
14+
15+
# CMake cache
16+
CMakeCache.txt
17+
CMakeFiles/
18+
19+
# Compiled WASM files
20+
*.wasm
21+
*.opt.wasm
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(spacetime_cpp_module LANGUAGES C CXX)
3+
4+
# Set C++ standard
5+
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
# Set the module source file
9+
set(MODULE_SOURCE "src/lib.cpp" CACHE STRING "Source file for the SpacetimeDB module")
10+
11+
# Export compile commands for better IDE support
12+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
13+
14+
# Set optimization level for Release builds
15+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
16+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
17+
endif()
18+
19+
# ------------------------------------------------------------------------------
20+
# SpacetimeDB C++ SDK - Use local SDK from repository
21+
# ------------------------------------------------------------------------------
22+
23+
set(SPACETIMEDB_CPP_SDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../crates/bindings-cpp")
24+
message(STATUS "Using local SpacetimeDB C++ SDK: ${SPACETIMEDB_CPP_SDK_DIR}")
25+
add_subdirectory("${SPACETIMEDB_CPP_SDK_DIR}" "${CMAKE_BINARY_DIR}/_deps/spacetime_cpp_sdk-build")
26+
27+
# Create the main module executable
28+
add_executable(lib ${MODULE_SOURCE})
29+
30+
# Link against the SDK target (preferred alias)
31+
target_link_libraries(lib PRIVATE spacetimedb_cpp_library)
32+
33+
# Configure Emscripten-specific settings for WASM output
34+
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
35+
set(EXPORTED_FUNCS "['_malloc','_free','___describe_module__','___call_reducer__','___call_view__','___call_view_anon__','___call_procedure__']")
36+
37+
# Compile options/defines for WASM
38+
# (apply to both the module and the SDK, so everything sees the same feature flags)
39+
target_compile_options(lib PRIVATE -fno-exceptions)
40+
target_compile_options(spacetimedb_cpp_library PRIVATE -fno-exceptions)
41+
42+
# Uncomment the following to allow unstable features of SpacetimeDB
43+
#target_compile_definitions(lib PRIVATE SPACETIMEDB_UNSTABLE_FEATURES)
44+
#target_compile_definitions(spacetimedb_cpp_library PUBLIC SPACETIMEDB_UNSTABLE_FEATURES)
45+
46+
target_link_options(lib PRIVATE
47+
"SHELL:-sSTANDALONE_WASM=1"
48+
"SHELL:-sWASM=1"
49+
"SHELL:--no-entry"
50+
"SHELL:-sEXPORTED_FUNCTIONS=${EXPORTED_FUNCS}"
51+
"SHELL:-sERROR_ON_UNDEFINED_SYMBOLS=1"
52+
"SHELL:-sFILESYSTEM=0"
53+
"SHELL:-sDISABLE_EXCEPTION_CATCHING=1"
54+
"SHELL:-sALLOW_MEMORY_GROWTH=0"
55+
"SHELL:-sINITIAL_MEMORY=16MB"
56+
"SHELL:-sSUPPORT_LONGJMP=0"
57+
"SHELL:-sSUPPORT_ERRNO=0"
58+
"SHELL:-std=c++20"
59+
"SHELL:-O2"
60+
)
61+
62+
set_target_properties(lib PROPERTIES OUTPUT_NAME "lib" SUFFIX ".wasm")
63+
endif()

0 commit comments

Comments
 (0)