Skip to content

Commit fae8713

Browse files
add the basic_room example, github workflow and README
1 parent 7dde7cb commit fae8713

7 files changed

Lines changed: 345 additions & 193 deletions

File tree

.github/workflow/builds.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Build examples against latest LiveKit SDK (via CMake)
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
10+
env:
11+
# Used by LiveKitSDK.cmake when VERSION=latest (it looks for env GITHUB_TOKEN by default)
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
14+
jobs:
15+
build:
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- os: ubuntu-latest
21+
name: linux-x64
22+
- os: macos-latest
23+
name: macos-arm64
24+
- os: windows-latest
25+
name: windows-x64
26+
27+
name: Build (${{ matrix.name }})
28+
runs-on: ${{ matrix.os }}
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
# ---------- deps ----------
35+
- name: Install deps (Ubuntu)
36+
if: runner.os == 'Linux'
37+
shell: bash
38+
run: |
39+
set -eux
40+
sudo apt-get update
41+
sudo apt-get install -y \
42+
cmake ninja-build pkg-config \
43+
protobuf-compiler libprotobuf-dev \
44+
libssl-dev \
45+
curl
46+
47+
- name: Install deps (macOS)
48+
if: runner.os == 'macOS'
49+
shell: bash
50+
run: |
51+
set -eux
52+
brew update
53+
brew install cmake ninja protobuf
54+
55+
- name: Install deps (Windows)
56+
if: runner.os == 'Windows'
57+
shell: pwsh
58+
run: |
59+
choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
60+
choco install -y ninja
61+
# curl is available on windows-latest; no need for jq/unzip since CMake does the download/extract.
62+
63+
# ---------- configure + build ----------
64+
- name: Configure (Unix)
65+
if: runner.os != 'Windows'
66+
shell: bash
67+
run: |
68+
set -eux
69+
cmake -S . -B build -G Ninja \
70+
-DCMAKE_BUILD_TYPE=Release
71+
72+
- name: Build (Unix)
73+
if: runner.os != 'Windows'
74+
shell: bash
75+
run: |
76+
set -eux
77+
cmake --build build --config Release
78+
79+
- name: Configure (Windows)
80+
if: runner.os == 'Windows'
81+
shell: pwsh
82+
run: |
83+
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
84+
85+
- name: Build (Windows)
86+
if: runner.os == 'Windows'
87+
shell: pwsh
88+
run: |
89+
cmake --build build --config Release
90+
91+
# ---------- smoke test ----------
92+
# LiveKitSDK.cmake typically extracts into: build/_deps/livekit-sdk/<bundle-root>
93+
# We’ll locate the extracted SDK root robustly and set runtime env vars from it.
94+
- name: Smoke test (Linux/macOS)
95+
if: runner.os != 'Windows'
96+
shell: bash
97+
run: |
98+
set -eux
99+
100+
sdk_root="$(ls -d build/_deps/livekit-sdk/* | head -n 1)"
101+
echo "SDK root: ${sdk_root}"
102+
ls -la "${sdk_root}/lib" || true
103+
104+
if [[ "$RUNNER_OS" == "Linux" ]]; then
105+
export LD_LIBRARY_PATH="${sdk_root}/lib:${LD_LIBRARY_PATH:-}"
106+
else
107+
export DYLD_LIBRARY_PATH="${sdk_root}/lib:${DYLD_LIBRARY_PATH:-}"
108+
fi
109+
110+
./build/basic_room --help || true
111+
112+
- name: Smoke test (Windows)
113+
if: runner.os == 'Windows'
114+
shell: pwsh
115+
run: |
116+
$sdkRoot = Get-ChildItem -Directory "build\_deps\livekit-sdk" | Select-Object -First 1
117+
if (-not $sdkRoot) { throw "SDK root not found under build\_deps\livekit-sdk" }
118+
Write-Host "SDK root: $($sdkRoot.FullName)"
119+
120+
# Prefer bin first; keep lib too (some packages put dlls in lib)
121+
$env:PATH = "$($sdkRoot.FullName)\bin;$($sdkRoot.FullName)\lib;$env:PATH"
122+
123+
.\build\basic_room.exe --help 2>$null
124+
125+
# ---------- upload build output ----------
126+
- name: Upload binary
127+
uses: actions/upload-artifact@v4
128+
with:
129+
name: basic_room-${{ matrix.name }}
130+
path: |
131+
build/basic_room*
132+
build/basic_room.exe
133+
retention-days: 7

CMakeLists.txt

Lines changed: 10 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,21 @@
11
cmake_minimum_required(VERSION 3.20)
22
project(livekit_cpp_example_collection LANGUAGES CXX)
3-
43
set(CMAKE_CXX_STANDARD 17)
54
set(CMAKE_CXX_STANDARD_REQUIRED ON)
65

7-
# -------- User knobs --------
8-
# Default to the version you mentioned. Users can override:
9-
# cmake -S . -B build -DLIVEKIT_SDK_VERSION=0.1.9
10-
set(LIVEKIT_SDK_VERSION "0.1.9" CACHE STRING "LiveKit C++ SDK version to download")
11-
12-
# Optional: enforce integrity if you have the sha256 for that specific asset.
13-
# Users can pass:
14-
# -DLIVEKIT_SDK_SHA256=<hash>
15-
set(LIVEKIT_SDK_SHA256 "" CACHE STRING "Optional sha256 for the downloaded SDK archive")
16-
17-
# Where to unpack inside the build directory
18-
set(LIVEKIT_SDK_DIR "${CMAKE_BINARY_DIR}/_deps/livekit-sdk" CACHE PATH "Where to unpack the LiveKit SDK")
19-
20-
# -------- Detect platform triple --------
21-
# We’re detecting the *host* because these examples are built natively.
22-
# (If you later want cross-compile, this should key off CMAKE_SYSTEM_* instead.)
23-
set(_host_os "")
24-
if(WIN32)
25-
set(_host_os "windows")
26-
elseif(APPLE)
27-
set(_host_os "macos")
28-
elseif(UNIX)
29-
set(_host_os "linux")
30-
else()
31-
message(FATAL_ERROR "Unsupported host OS")
32-
endif()
33-
34-
set(_host_arch "")
35-
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
36-
set(_host_arch "x64")
37-
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
38-
set(_host_arch "arm64")
39-
else()
40-
message(FATAL_ERROR "Unsupported host arch: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
41-
endif()
42-
43-
# Map to your release artifact naming
44-
# Adjust if you use different naming (e.g., macos-x86_64 vs macos-x64)
45-
if(_host_os STREQUAL "macos" AND _host_arch STREQUAL "x64")
46-
# If your asset is named macos-x86_64 instead, change this to "macos-x86_64"
47-
set(SDK_TRIPLE "macos-x64")
48-
else()
49-
set(SDK_TRIPLE "${_host_os}-${_host_arch}")
50-
endif()
51-
52-
# -------- Compute archive name + URL --------
53-
if(_host_os STREQUAL "windows")
54-
set(SDK_EXT "zip")
55-
else()
56-
set(SDK_EXT "tar.gz")
57-
endif()
58-
59-
set(SDK_ARCHIVE "livekit-sdk-${SDK_TRIPLE}-${LIVEKIT_SDK_VERSION}.${SDK_EXT}")
60-
set(SDK_URL "https://github.com/livekit/client-sdk-cpp/releases/download/v${LIVEKIT_SDK_VERSION}/${SDK_ARCHIVE}")
61-
62-
# Where to download
63-
set(SDK_DL_DIR "${CMAKE_BINARY_DIR}/_downloads")
64-
set(SDK_ARCHIVE_PATH "${SDK_DL_DIR}/${SDK_ARCHIVE}")
65-
66-
# The extracted SDK root will look like:
67-
# <LIVEKIT_SDK_DIR>/livekit-sdk-<triple>-<ver>/
68-
set(SDK_EXTRACTED_ROOT "${LIVEKIT_SDK_DIR}/livekit-sdk-${SDK_TRIPLE}-${LIVEKIT_SDK_VERSION}")
6+
# Make "include(LiveKitSDK)" search in ./cmake
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
698

70-
# -------- Download + extract (configure-time) --------
71-
file(MAKE_DIRECTORY "${SDK_DL_DIR}")
72-
file(MAKE_DIRECTORY "${LIVEKIT_SDK_DIR}")
9+
set(LIVEKIT_SDK_VERSION "latest" CACHE STRING "LiveKit C++ SDK version (e.g. 0.2.0 or latest)")
7310

74-
if(NOT EXISTS "${SDK_EXTRACTED_ROOT}")
75-
message(STATUS "LiveKit SDK not found at: ${SDK_EXTRACTED_ROOT}")
76-
message(STATUS "Downloading: ${SDK_URL}")
11+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
12+
include(LiveKitSDK)
7713

78-
if(LIVEKIT_SDK_SHA256 STREQUAL "")
79-
file(DOWNLOAD
80-
"${SDK_URL}"
81-
"${SDK_ARCHIVE_PATH}"
82-
SHOW_PROGRESS
83-
STATUS _dl_status
84-
TLS_VERIFY ON
85-
)
86-
else()
87-
file(DOWNLOAD
88-
"${SDK_URL}"
89-
"${SDK_ARCHIVE_PATH}"
90-
SHOW_PROGRESS
91-
STATUS _dl_status
92-
TLS_VERIFY ON
93-
EXPECTED_HASH "SHA256=${LIVEKIT_SDK_SHA256}"
94-
)
95-
endif()
96-
97-
list(GET _dl_status 0 _dl_code)
98-
list(GET _dl_status 1 _dl_msg)
99-
if(NOT _dl_code EQUAL 0)
100-
message(FATAL_ERROR "Failed to download ${SDK_URL}\nStatus: ${_dl_code}\nMessage: ${_dl_msg}")
101-
endif()
102-
103-
message(STATUS "Extracting: ${SDK_ARCHIVE_PATH}")
104-
105-
# Clean any previous partial extraction
106-
file(REMOVE_RECURSE "${SDK_EXTRACTED_ROOT}")
107-
108-
if(_host_os STREQUAL "windows")
109-
# CMake can extract zip with -E tar
110-
execute_process(
111-
COMMAND "${CMAKE_COMMAND}" -E tar xvf "${SDK_ARCHIVE_PATH}"
112-
WORKING_DIRECTORY "${LIVEKIT_SDK_DIR}"
113-
RESULT_VARIABLE _xret
114-
)
115-
else()
116-
execute_process(
117-
COMMAND "${CMAKE_COMMAND}" -E tar xvf "${SDK_ARCHIVE_PATH}"
118-
WORKING_DIRECTORY "${LIVEKIT_SDK_DIR}"
119-
RESULT_VARIABLE _xret
120-
)
121-
endif()
122-
123-
if(NOT _xret EQUAL 0)
124-
message(FATAL_ERROR "Failed to extract ${SDK_ARCHIVE_PATH} (code=${_xret})")
125-
endif()
126-
endif()
127-
128-
if(NOT EXISTS "${SDK_EXTRACTED_ROOT}/lib/cmake")
129-
message(FATAL_ERROR
130-
"Extracted SDK does not look valid (missing lib/cmake).\n"
131-
"Expected root: ${SDK_EXTRACTED_ROOT}\n"
132-
"If the archive root folder name differs, adjust SDK_EXTRACTED_ROOT logic."
133-
)
134-
endif()
135-
136-
# -------- Make find_package(LiveKit) work --------
137-
# Your SDK installs a config package under <prefix>/lib/cmake/...
138-
# The most robust approach is to push <prefix> onto CMAKE_PREFIX_PATH.
139-
list(PREPEND CMAKE_PREFIX_PATH "${SDK_EXTRACTED_ROOT}")
140-
141-
# Some packages also require explicit *_DIR; keep as a fallback option:
142-
# set(LiveKit_DIR "${SDK_EXTRACTED_ROOT}/lib/cmake/LiveKit" CACHE PATH "" FORCE)
14+
livekit_sdk_setup(
15+
VERSION "${LIVEKIT_SDK_VERSION}"
16+
SDK_DIR "${CMAKE_BINARY_DIR}/_deps/livekit-sdk"
17+
GITHUB_TOKEN "$ENV{GITHUB_TOKEN}"
18+
)
14319

14420
find_package(LiveKit CONFIG REQUIRED)
145-
146-
# -------- Build examples --------
14721
add_subdirectory(basic_room)
148-

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
11
# cpp-example-collection
2-
A collection of small examples for the LiveKit C++ SDK: https://github.com/livekit/client-sdk-cpp
2+
This repository contains a collection of small, self-contained examples for the
3+
[LiveKit C++ SDK](https://github.com/livekit/client-sdk-cpp).
4+
5+
The goal of these examples is to demonstrate common usage patterns of the
6+
LiveKit C++ SDK (connecting to a room, publishing tracks, RPC, data streams,
7+
etc.) without requiring users to build the SDK from source.
8+
9+
10+
## How the SDK is provided
11+
12+
These examples **automatically download a prebuilt LiveKit C++ SDK release**
13+
from GitHub at CMake configure time.
14+
15+
This is handled by the cmake helper: [LiveKitSDK.cmake ](https://github.com/livekit-examples/cpp-example-collection/cmake/LiveKitSDK.cmake)
16+
17+
## Selecting a LiveKit SDK version
18+
19+
By default, the examples download the **latest released** LiveKit C++ SDK.
20+
21+
You can pin a specific SDK version using the `LIVEKIT_SDK_VERSION` CMake option.
22+
23+
### Examples
24+
25+
Use the latest release:
26+
```bash
27+
cmake -S . -B build
28+
# Or use a specific version (recommended for reproducibility):
29+
cmake -S . -B build -DLIVEKIT_SDK_VERSION=0.2.0
30+
```
31+
32+
Reconfigure to change versions:
33+
```bash
34+
rm -rf build
35+
cmake -S . -B build -DLIVEKIT_SDK_VERSION=0.3.1
36+
```
37+
38+
39+
### Building the examples
40+
#### macOS / Linux
41+
```bash
42+
cmake -S . -B build # add -DLIVEKIT_SDK_VERSION=0.2.0 if using a specific version
43+
cmake --build build
44+
```
45+
46+
#### Windows (Visual Studio generator)
47+
```powershell
48+
cmake -S . -B build # add -DLIVEKIT_SDK_VERSION=0.2.0 if using a specific version
49+
cmake --build build --config Release
50+
```
51+
52+
The Livekit Release SDK is downloaded into **build/_deps/livekit-sdk/**
53+
54+
### Running the examples
55+
56+
After building, example binaries are located under:
57+
```bash
58+
build/<example-name>/
59+
```
60+
61+
For example:
62+
```bash
63+
./build/basic_room/basic_room --url <ws-url> --token <token>
64+
```
65+
66+
### Supported platforms
67+
68+
Prebuilt SDKs are downloaded automatically for:
69+
* Windows: x64
70+
* macOS: x64, arm64 (Apple Silicon)
71+
* Linux: x64
72+
73+
If no matching SDK is available for your platform, CMake configuration will fail with a clear error.

0 commit comments

Comments
 (0)