Skip to content

Commit e62dbbb

Browse files
committed
fix: improve cross-platform build scripts and documentation
- Initialize optional variables in build.sh to fix 'unbound variable' errors - Fix protozero_plugin.o removal to handle both Debug/Release and ignore missing errors - Add debug-examples presets for Windows/Linux/macOS in CMakePresets.json - Fix build.cmd clean to properly clean both Debug and Release configurations - Fix vcpkg debug DLL naming (libprotobufd.dll vs libprotobuf.dll) - Update README_BUILD.md to use build scripts instead of raw cmake commands
1 parent b516036 commit e62dbbb

File tree

5 files changed

+167
-86
lines changed

5 files changed

+167
-86
lines changed

CMakeLists.txt

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,14 @@ if(UNIX AND NOT APPLE)
245245
if(NOT CMAKE_AR)
246246
find_program(CMAKE_AR ar REQUIRED)
247247
endif()
248+
# Remove protozero_plugin.o from static library to avoid duplicate symbols
249+
# The file may not exist in all builds, so we use '|| true' to ignore errors
248250
add_custom_command(
249251
TARGET build_rust_ffi
250252
POST_BUILD
251-
COMMAND ${CMAKE_AR} -dv "${RUST_LIB_RELEASE}" protozero_plugin.o
252-
COMMENT "Removing protozero_plugin.o from liblivekit_ffi.a"
253+
COMMAND ${CMAKE_AR} -dv "${RUST_LIB_RELEASE}" protozero_plugin.o || true
254+
COMMAND ${CMAKE_AR} -dv "${RUST_LIB_DEBUG}" protozero_plugin.o || true
255+
COMMENT "Removing protozero_plugin.o from liblivekit_ffi.a (if present)"
253256
)
254257
endif()
255258

@@ -367,48 +370,50 @@ if(LIVEKIT_IS_TOPLEVEL)
367370
set(VCPKG_LIB_DIR_DEBUG "${LIVEKIT_ROOT_DIR}/vcpkg_installed/x64-windows/debug/lib")
368371
set(VCPKG_LIB_DIR_RELEASE "${LIVEKIT_ROOT_DIR}/vcpkg_installed/x64-windows/lib")
369372

370-
# List of required DLL files (runtime)
371-
set(REQUIRED_DLLS
372-
"libprotobuf.dll"
373-
# "libprotobuf-lite.dll"
374-
# "libprotoc.dll"
375-
"abseil_dll.dll"
373+
# vcpkg uses 'd' suffix for debug builds (e.g., libprotobufd.dll)
374+
# We need to copy with the correct source name but keep the output name consistent
375+
376+
# abseil_dll.dll (same name for both debug and release)
377+
add_custom_command(
378+
TARGET livekit POST_BUILD
379+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
380+
"$<IF:$<CONFIG:Debug>,${VCPKG_BIN_DIR_DEBUG}/abseil_dll.dll,${VCPKG_BIN_DIR_RELEASE}/abseil_dll.dll>"
381+
"$<TARGET_FILE_DIR:livekit>/abseil_dll.dll"
382+
COMMENT "Copying abseil_dll.dll to lib directory"
383+
VERBATIM
376384
)
377385

378-
# List of required LIB files (for linking)
379-
set(REQUIRED_LIBS
380-
"libprotobuf.lib"
381-
# "libprotobuf-lite.lib"
382-
# "libprotoc.lib"
383-
"abseil_dll.lib"
386+
# libprotobuf.dll - debug version has 'd' suffix
387+
add_custom_command(
388+
TARGET livekit POST_BUILD
389+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
390+
"$<IF:$<CONFIG:Debug>,${VCPKG_BIN_DIR_DEBUG}/libprotobufd.dll,${VCPKG_BIN_DIR_RELEASE}/libprotobuf.dll>"
391+
"$<TARGET_FILE_DIR:livekit>/$<IF:$<CONFIG:Debug>,libprotobufd.dll,libprotobuf.dll>"
392+
COMMENT "Copying libprotobuf DLL to lib directory"
393+
VERBATIM
384394
)
385395

386-
# Copy DLLs to the lib output directory
387-
foreach(DLL_FILE ${REQUIRED_DLLS})
388-
add_custom_command(
389-
TARGET livekit POST_BUILD
390-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
391-
"$<IF:$<CONFIG:Debug>,${VCPKG_BIN_DIR_DEBUG}/${DLL_FILE},${VCPKG_BIN_DIR_RELEASE}/${DLL_FILE}>"
392-
"$<TARGET_FILE_DIR:livekit>/${DLL_FILE}"
393-
COMMENT "Copying ${DLL_FILE} to lib directory"
394-
VERBATIM
395-
)
396-
endforeach()
396+
# abseil_dll.lib (same name for both debug and release)
397+
add_custom_command(
398+
TARGET livekit POST_BUILD
399+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
400+
"$<IF:$<CONFIG:Debug>,${VCPKG_LIB_DIR_DEBUG}/abseil_dll.lib,${VCPKG_LIB_DIR_RELEASE}/abseil_dll.lib>"
401+
"$<TARGET_FILE_DIR:livekit>/abseil_dll.lib"
402+
COMMENT "Copying abseil_dll.lib to lib directory"
403+
VERBATIM
404+
)
397405

398-
# Copy LIBs (import libraries) to the lib output directory
399-
foreach(LIB_FILE ${REQUIRED_LIBS})
400-
add_custom_command(
401-
TARGET livekit POST_BUILD
402-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
403-
"$<IF:$<CONFIG:Debug>,${VCPKG_LIB_DIR_DEBUG}/${LIB_FILE},${VCPKG_LIB_DIR_RELEASE}/${LIB_FILE}>"
404-
"$<TARGET_FILE_DIR:livekit>/${LIB_FILE}"
405-
COMMENT "Copying ${LIB_FILE} to lib directory"
406-
VERBATIM
407-
)
408-
endforeach()
406+
# libprotobuf.lib - debug version has 'd' suffix
407+
add_custom_command(
408+
TARGET livekit POST_BUILD
409+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
410+
"$<IF:$<CONFIG:Debug>,${VCPKG_LIB_DIR_DEBUG}/libprotobufd.lib,${VCPKG_LIB_DIR_RELEASE}/libprotobuf.lib>"
411+
"$<TARGET_FILE_DIR:livekit>/$<IF:$<CONFIG:Debug>,libprotobufd.lib,libprotobuf.lib>"
412+
COMMENT "Copying libprotobuf LIB to lib directory"
413+
VERBATIM
414+
)
409415

410-
message(STATUS "Third-party DLLs will be copied to lib directory: ${REQUIRED_DLLS}")
411-
message(STATUS "Third-party LIBs will be copied to lib directory: ${REQUIRED_LIBS}")
416+
message(STATUS "Third-party dependencies will be copied to lib directory")
412417
endif()
413418
endif()
414419

CMakePresets.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@
8282
"VCPKG_MANIFEST_FEATURES": "examples"
8383
}
8484
},
85+
{
86+
"name": "windows-debug-examples",
87+
"displayName": "Windows x64 Debug with Examples",
88+
"description": "Build for Windows x64 Debug with example applications",
89+
"inherits": "windows-base",
90+
"binaryDir": "${sourceDir}/build",
91+
"cacheVariables": {
92+
"LIVEKIT_BUILD_EXAMPLES": "ON",
93+
"VCPKG_MANIFEST_FEATURES": "examples"
94+
}
95+
},
8596
{
8697
"name": "linux-release",
8798
"displayName": "Linux Release",
@@ -113,6 +124,17 @@
113124
"LIVEKIT_BUILD_EXAMPLES": "ON"
114125
}
115126
},
127+
{
128+
"name": "linux-debug-examples",
129+
"displayName": "Linux Debug with Examples",
130+
"description": "Build for Linux Debug with example applications",
131+
"inherits": "linux-base",
132+
"binaryDir": "${sourceDir}/build",
133+
"cacheVariables": {
134+
"CMAKE_BUILD_TYPE": "Debug",
135+
"LIVEKIT_BUILD_EXAMPLES": "ON"
136+
}
137+
},
116138
{
117139
"name": "macos-release",
118140
"displayName": "macOS Release",
@@ -143,6 +165,17 @@
143165
"CMAKE_BUILD_TYPE": "Release",
144166
"LIVEKIT_BUILD_EXAMPLES": "ON"
145167
}
168+
},
169+
{
170+
"name": "macos-debug-examples",
171+
"displayName": "macOS Debug with Examples",
172+
"description": "Build for macOS Debug with example applications",
173+
"inherits": "macos-base",
174+
"binaryDir": "${sourceDir}/build",
175+
"cacheVariables": {
176+
"CMAKE_BUILD_TYPE": "Debug",
177+
"LIVEKIT_BUILD_EXAMPLES": "ON"
178+
}
146179
}
147180
],
148181
"buildPresets": [
@@ -161,6 +194,11 @@
161194
"configurePreset": "windows-release-examples",
162195
"configuration": "Release"
163196
},
197+
{
198+
"name": "windows-debug-examples",
199+
"configurePreset": "windows-debug-examples",
200+
"configuration": "Debug"
201+
},
164202
{
165203
"name": "linux-release",
166204
"configurePreset": "linux-release"
@@ -173,6 +211,10 @@
173211
"name": "linux-release-examples",
174212
"configurePreset": "linux-release-examples"
175213
},
214+
{
215+
"name": "linux-debug-examples",
216+
"configurePreset": "linux-debug-examples"
217+
},
176218
{
177219
"name": "macos-release",
178220
"configurePreset": "macos-release"
@@ -184,6 +226,10 @@
184226
{
185227
"name": "macos-release-examples",
186228
"configurePreset": "macos-release-examples"
229+
},
230+
{
231+
"name": "macos-debug-examples",
232+
"configurePreset": "macos-debug-examples"
187233
}
188234
]
189235
}

README_BUILD.md

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,74 @@ sudo apt update && sudo apt install -y \
4646
brew install cmake ninja protobuf abseil
4747
```
4848

49-
### Method 1: Using CMake Presets (Recommended)
49+
## Quick Start
5050

51-
The project provides a `CMakePresets.json` configuration file for simplified building.
51+
### Method 1: Using Build Scripts (Recommended)
5252

53-
**Windows (requires VCPKG_ROOT):**
53+
The project provides `build.cmd` (Windows) and `build.sh` (Linux/macOS) scripts for simplified building.
54+
55+
**Windows:**
5456
```powershell
55-
# Set vcpkg root
57+
# Set vcpkg root (required for Windows)
5658
$env:VCPKG_ROOT = "C:\path\to\vcpkg"
5759
58-
# Configure and build
59-
cmake --preset windows-release
60-
cmake --build --preset windows-release
60+
# Build Release version
61+
.\build.cmd release
62+
63+
# Build Release with examples
64+
.\build.cmd release-examples
65+
66+
# Build Debug version
67+
.\build.cmd debug
68+
69+
# Build Debug with examples
70+
.\build.cmd debug-examples
6171
62-
# To build with examples
63-
cmake --preset windows-release-examples
64-
cmake --build --preset windows-release-examples
72+
# Clean build artifacts
73+
.\build.cmd clean
74+
75+
# Full clean (C++ + Rust + generated files)
76+
.\build.cmd clean-all
6577
```
6678

67-
**Linux (uses system packages):**
79+
**Linux:**
6880
```bash
69-
# Configure and build
70-
cmake --preset linux-release
71-
cmake --build --preset linux-release
81+
# Install system dependencies first (see Prerequisites above)
82+
83+
# Build Release version
84+
./build.sh release
85+
86+
# Build Release with examples
87+
./build.sh release-examples
88+
89+
# Build Debug version
90+
./build.sh debug
91+
92+
# Build Debug with examples
93+
./build.sh debug-examples
7294

73-
# To build with examples
74-
cmake --preset linux-release-examples
75-
cmake --build --preset linux-release-examples
95+
# Clean build artifacts
96+
./build.sh clean
97+
98+
# Full clean
99+
./build.sh clean-all
76100
```
77101

78-
**macOS (uses Homebrew packages):**
102+
**macOS:**
79103
```bash
80-
# Configure and build
81-
cmake --preset macos-release
82-
cmake --build --preset macos-release
104+
# Install Homebrew dependencies first (see Prerequisites above)
105+
106+
# Build Release version
107+
./build.sh release
108+
109+
# Build Release with examples
110+
./build.sh release-examples
111+
112+
# Build Debug version
113+
./build.sh debug
83114

84-
# To build with examples
85-
cmake --preset macos-release-examples
86-
cmake --build --preset macos-release-examples
115+
# Build Debug with examples
116+
./build.sh debug-examples
87117
```
88118

89119
#### Important Notes for Linux
@@ -116,17 +146,6 @@ export LIBCLANG_PATH=/usr/lib/llvm-14/lib # Adjust version as needed
116146
- Cause: Rust bindgen cannot locate libclang library
117147
- Solution: Set `LIBCLANG_PATH` environment variable pointing to your LLVM installation
118148

119-
**macOS:**
120-
```bash
121-
# Configure and build
122-
cmake --preset macos-release
123-
cmake --build --preset macos-release
124-
125-
# To build with examples
126-
cmake --preset macos-release-examples
127-
cmake --build --preset macos-release-examples
128-
```
129-
130149
### Method 2: Using vcpkg Manifest Mode
131150

132151
vcpkg will automatically install all required dependencies based on `vcpkg.json`.

build.cmd

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,34 @@ echo ==^> Build complete!
143143
goto :eof
144144

145145
:clean
146-
echo ==^> Cleaning CMake targets...
147-
if exist "%BUILD_DIR%" (
148-
cmake --build "%BUILD_DIR%" --target clean
149-
) else (
150-
echo (skipping) %BUILD_DIR% does not exist.
146+
echo ==^> Cleaning CMake targets ^(Debug + Release^)...
147+
if not exist "%BUILD_DIR%\CMakeCache.txt" (
148+
echo ^(skipping^) Build directory does not exist or is not configured.
149+
goto :eof
151150
)
151+
echo Cleaning Debug...
152+
cmake --build "%BUILD_DIR%" --target clean --config Debug 2>nul
153+
echo Cleaning Release...
154+
cmake --build "%BUILD_DIR%" --target clean --config Release 2>nul
155+
echo ==^> Clean complete.
152156
goto :eof
153157

154158
:clean_all
155-
echo ==^> Running full clean-all (C++ + Rust)...
156-
if exist "%BUILD_DIR%" (
157-
cmake --build "%BUILD_DIR%" --target clean_all
158-
) else (
159-
echo (info) %BUILD_DIR% does not exist; doing manual deep clean...
159+
echo ==^> Running full clean-all ^(C++ + Rust^)...
160+
if exist "%BUILD_DIR%\CMakeCache.txt" (
161+
cmake --build "%BUILD_DIR%" --target clean_all 2>nul
160162
)
161163

164+
echo Removing Rust debug artifacts...
162165
if exist "%PROJECT_ROOT%\client-sdk-rust\target\debug" (
163-
echo Removing Rust debug artifacts...
164166
rmdir /s /q "%PROJECT_ROOT%\client-sdk-rust\target\debug" 2>nul
165167
)
168+
echo Removing Rust release artifacts...
166169
if exist "%PROJECT_ROOT%\client-sdk-rust\target\release" (
167-
echo Removing Rust release artifacts...
168170
rmdir /s /q "%PROJECT_ROOT%\client-sdk-rust\target\release" 2>nul
169171
)
172+
echo Removing build directory...
170173
if exist "%BUILD_DIR%" (
171-
echo Removing build directory...
172174
rmdir /s /q "%BUILD_DIR%" 2>nul
173175
)
174176
echo ==^> Clean-all complete.

build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ BUILD_TYPE="Release"
77
VERBOSE=""
88
PRESET=""
99

10+
# Initialize optional variables (required for set -u)
11+
DO_BUNDLE=""
12+
DO_ARCHIVE=""
13+
PREFIX=""
14+
ARCHIVE_NAME=""
15+
GENERATOR=""
16+
MACOS_ARCH=""
17+
LIVEKIT_VERSION=""
18+
1019
# Detect OS for preset selection
1120
detect_os() {
1221
case "$(uname -s)" in

0 commit comments

Comments
 (0)