Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cc86cef
Add C++ modules support and update nlohmann::json
mikomikotaishi Dec 27, 2025
b9e4215
Move module to include/ directory, add compiling example program for …
mikomikotaishi Dec 27, 2025
868782b
Add modules unit test
mikomikotaishi Dec 28, 2025
1d41aa9
Trying specific handling for CMake examples
mikomikotaishi Feb 19, 2026
ce88aff
Manually link the module instead of relying on CMake for now
mikomikotaishi Feb 26, 2026
7defeb8
Merge branch 'dev' into dev
mikomikotaishi May 26, 2026
15dbf83
Merge branch 'dev' into dev
mikomikotaishi Jun 29, 2026
6c828af
Merge branch 'dev' into dev
mikomikotaishi Jul 5, 2026
349c958
Remove now irrelevant attributes
mikomikotaishi Jul 5, 2026
2eb60f1
Remove edits to json.hpp
mikomikotaishi Jul 10, 2026
6d39166
Merge branch 'dev' into dev
mikomikotaishi Jul 10, 2026
531227d
Restore removed `-rdynamic` flag
mikomikotaishi Jul 10, 2026
d887c03
Add a static-linux and install-consumer job on CI
mikomikotaishi Jul 10, 2026
8cf7f90
Merge branch 'dev' into dev
mikomikotaishi Jul 10, 2026
55eadfb
Merge branch 'dev' into dev
mikomikotaishi Jul 10, 2026
d87cb46
Merge branch 'dev' into dev
braindigitalis Jul 10, 2026
b1699de
Merge branch 'dev' into dev
mikomikotaishi Jul 18, 2026
ac09477
Apply recommended docs changes
mikomikotaishi Jul 19, 2026
4a12d0c
Add a CI for building the module on Windows
mikomikotaishi Jul 19, 2026
37a91e0
Merge branch 'dev' into dev
mikomikotaishi Jul 25, 2026
81fdff6
Merge branch 'dev' into dev
mikomikotaishi Aug 9, 2026
294146b
Fix reported issues by maintainers
mikomikotaishi Aug 9, 2026
7e8b739
Explicitly disable GNU extensions
mikomikotaishi Aug 23, 2026
54bcd73
Use ClangCL instead of cl.exe, due to error C2039
mikomikotaishi Aug 23, 2026
fd95cb5
Clarify CMake instructions for modules
mikomikotaishi Aug 24, 2026
4f33bf2
Merge branch 'dev' into dev
Jaskowicz1 Aug 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,89 @@ jobs:
with:
name: "libdpp - RPM Package ${{matrix.cfg.name}}"
path: "${{github.workspace}}/build/*.rpm"

# Static library build (BUILD_SHARED_LIBS=OFF)
Comment thread
Jaskowicz1 marked this conversation as resolved.
static-linux:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-static-${{ matrix.cfg.cpp }}-${{ matrix.cfg.version }}
cancel-in-progress: true
name: Static Linux (${{ matrix.cfg.cpp }}-${{ matrix.cfg.version }})
runs-on: ${{ matrix.cfg.os }}
strategy:
fail-fast: false
matrix:
cfg:
- { os: ubuntu-24.04, package: g++-13, cpp: g++, version: 13, concurrency: 4 }
- { os: ubuntu-24.04, package: clang-20, cpp: clang++, version: 20, concurrency: 4 }
steps:
- name: Harden Runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit

- name: Checkout D++
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Setup mold
uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 # v1

- name: Install apt packages
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt update && sudo apt-get install -y ${{ matrix.cfg.package }} pkg-config libopus-dev zlib1g-dev libssl-dev rpm

- name: Generate CMake
run: cmake -B build -DBUILD_SHARED_LIBS=OFF -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release
env:
CXX: ${{ matrix.cfg.cpp }}-${{ matrix.cfg.version }}

- name: Build Project
run: cd build && make -j${{ matrix.cfg.concurrency }}

# Install D++ and consume it from a separate project via find_package(dpp)
install-consumer:
permissions:
contents: read
name: Install & find_package(dpp)
runs-on: ubuntu-24.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit

- name: Checkout D++
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Setup mold
uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 # v1

- name: Install apt packages
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt update && sudo apt-get install -y g++-13 pkg-config libopus-dev zlib1g-dev libssl-dev

- name: Build and install D++
run: |
cmake -B build -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release -DDPP_BUILD_TEST=OFF -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/_install"
cmake --build build -j$(nproc)
cmake --install build
env:
CXX: g++-13

- name: Consume D++ via find_package
run: |
mkdir -p consumer && cd consumer
cat > CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.16)
project(dpp_consumer CXX)
find_package(dpp REQUIRED)
add_executable(consumer main.cpp)
target_link_libraries(consumer dpp::dpp)
EOF
cat > main.cpp <<'EOF'
#include <dpp/dpp.h>
int main() { dpp::cluster bot("token"); return 0; }
EOF
cmake -B build -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/_install" -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
env:
CXX: g++-13
16 changes: 9 additions & 7 deletions .github/workflows/test-docs-examples.yml
Comment thread
mikomikotaishi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
jobs:
test_docs_examples:
name: Test build examples
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -35,17 +35,19 @@ jobs:
submodules: recursive

- name: Install apt packages
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt-get update && sudo apt-get install -y g++-12 libopus-dev zlib1g-dev libmpg123-dev liboggz-dev cmake libfmt-dev libopusfile-dev
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt-get update && sudo apt-get install -y clang-20 libopus-dev ninja-build zlib1g-dev libmpg123-dev liboggz-dev cmake libfmt-dev libopusfile-dev

- name: Generate CMake
run: mkdir build && cd build && cmake -DDPP_NO_VCPKG=ON -DAVX_TYPE=T_fallback -DDPP_CORO=ON -DCMAKE_BUILD_TYPE=Debug ..
run: mkdir build && cd build && cmake -G Ninja -DDPP_NO_VCPKG=ON -DDPP_MODULES=ON -DAVX_TYPE=T_fallback -DDPP_CORO=ON -DCMAKE_BUILD_TYPE=Debug ..
env:
CXX: g++-12
CXX: clang++-20

- name: Build Project
run: cd build && make -j2 && sudo make install
run: cd build && cmake --build . -j2 && sudo ninja install
env:
CXX: clang++-20

- name: Test compile examples
run: cd docpages/example_code && mkdir build && cd build && cmake .. && make -j2
run: cd docpages/example_code && mkdir build && cd build && cmake -G Ninja -DDPP_MODULES=ON .. && cmake --build . -j2
env:
CXX: g++-12
CXX: clang++-20
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

cmake_minimum_required (VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_VOICE_SUPPORT "Build voice support" ON)
option(RUN_LDCONFIG "Run ldconfig after installation" ON)
Expand All @@ -33,6 +33,7 @@ option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OF
option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF)
option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF)
option(DPP_TEST_VCPKG "Force VCPKG build without VCPKG installed (for development use only!)" OFF)
option(DPP_MODULES "Support for C++20 modules (experimental)" OFF)

include(CheckCXXSymbolExists)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -159,3 +160,4 @@ endif()
if (NOT WIN32)
target_link_libraries(dpp PRIVATE std::filesystem)
endif()

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ D++ is a lightweight and efficient library for **Discord** written in **modern C
* Stable [Windows support](https://dpp.dev/buildwindows.html)
* Ready-made compiled packages for Windows, Raspberry Pi (ARM64/ARM7/ARMv6), Debian x86/x64, and RPM based distributions
* Highly scalable for large amounts of guilds and users
* Experimental support for [C++ modules](https://dpp.dev/using_modules.html)

Want to help? Drop me a line or send a PR.

Expand Down
44 changes: 32 additions & 12 deletions cmake/CPackSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,40 @@ set(DPP_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}/${DPP_VERSIONED})

## Pack the binary output
if (WIN32)
install(TARGETS dpp
EXPORT ${DPP_EXPORT_NAME}
LIBRARY DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${DPP_INSTALL_INCLUDE_DIR})
if (DPP_MODULES)
install(TARGETS dpp
EXPORT ${DPP_EXPORT_NAME}
LIBRARY DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${DPP_INSTALL_INCLUDE_DIR}
FILE_SET CXX_MODULES DESTINATION ${DPP_INSTALL_INCLUDE_DIR})
else()
install(TARGETS dpp
EXPORT ${DPP_EXPORT_NAME}
LIBRARY DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${DPP_INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${DPP_INSTALL_INCLUDE_DIR})
endif()
install(DIRECTORY "${DPP_ROOT_PATH}/include/" DESTINATION "${DPP_INSTALL_INCLUDE_DIR}")
else()
install(TARGETS dpp
EXPORT ${DPP_EXPORT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDE_DIR})
if (DPP_MODULES)
install(TARGETS dpp
EXPORT ${DPP_EXPORT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
else()
install(TARGETS dpp
EXPORT ${DPP_EXPORT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
endif()

## Allow for a specific version to be chosen in the `find_package` command
Expand Down
28 changes: 26 additions & 2 deletions docpages/example_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,43 @@
# libmpg123-dev
# dpp latest master with -DDPP_CORO=ON installed sytemwide

cmake_minimum_required (VERSION 3.16)
cmake_minimum_required (VERSION 3.28)
Comment thread
braindigitalis marked this conversation as resolved.
project(documentation_tests)

include("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/colour.cmake")

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -std=c++20 -pthread -O0 -fPIC -rdynamic -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations")
Comment thread
Jaskowicz1 marked this conversation as resolved.
option(DPP_MODULES "Build examples with C++20 modules support" ON)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -std=c++20 -pthread -O0 -fPIC -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")

set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")

# Create gcm.cache directory and symlink to the main build's dpp.gcm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can see that, but why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang obtains the BMI paths through -fprebuilt-module-path which indicates where to scan, but GCC has no such option, and places its BMIs in gcm.cache/, which is why the lookup location is populated with the symlink to the actual interface.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? I've not had to do this with any of my other projects

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/gcm.cache")
file(CREATE_LINK "${CMAKE_SOURCE_DIR}/../../build/library/CMakeFiles/dpp.dir/dpp.gcm"
"${CMAKE_BINARY_DIR}/gcm.cache/dpp.gcm" SYMBOLIC)
endif()

file(GLOB example_list ./*.cpp)
foreach (example ${example_list})
get_filename_component(examplename ${example} NAME)
message(STATUS "Found example '${BoldBlue}${examplename}${ColourReset}'")
add_executable(${examplename}_out ${example})
target_link_libraries(${examplename}_out dl dpp mpg123 oggz ogg opusfile opus)
include_directories(/usr/include/opus)

target_compile_definitions(${examplename}_out PRIVATE DPP_MODULES)
set_target_properties(${examplename}_out PROPERTIES CXX_SCAN_FOR_MODULES ON)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${examplename}_out PRIVATE -fmodules-ts)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${examplename}_out PRIVATE
-fmodules
-mavx2
Comment thread
Jaskowicz1 marked this conversation as resolved.
Outdated
-fprebuilt-module-path=${CMAKE_SOURCE_DIR}/../../build/library/CMakeFiles/dpp.dir
)
endif()
endforeach(example)
25 changes: 25 additions & 0 deletions docpages/example_code/using_modules.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <string>
#include <typeinfo>
Comment thread
Jaskowicz1 marked this conversation as resolved.
Outdated

import dpp;

int main() {
dpp::cluster bot("YOUR_BOT_TOKEN_HERE");

bot.on_slashcommand([](const dpp::slashcommand_t& event) -> void {
if (event.command.get_command_name() == "ping") {
event.reply("Pong!");
}
});

bot.on_ready([&bot](const dpp::ready_t& event) -> void {
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand("ping", "Ping pong!", bot.me.id)
);
}
});

bot.start(dpp::start_type::st_wait);
return 0;
}
1 change: 1 addition & 0 deletions docpages/example_programs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ This section lists examples that do not fit neatly into any of the categories ab
* \subpage setting_status
* \subpage using-emojis
* \subpage using_timers
* \subpage using_modules
9 changes: 9 additions & 0 deletions docpages/example_programs/misc/using_modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\page using_modules Using D++ with C++ modules

Comment thread
Jaskowicz1 marked this conversation as resolved.
D++ is offered as a C++ module, which offers improved compile times over a traditional header.

In order to enable support, you must use C++20 (or later) with any module-supporting compiler. To activate the feature, pass the `DPP_MODULES` flag to CMake. Ensure that the generated build system supports modules (for CMake, this is usually Ninja; note CMake does not currently support modules with Makefile).

Once this is done, simply `import dpp;` and we're good to go!

\include{cpp} using_modules.cpp
2 changes: 1 addition & 1 deletion include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace dpp {
* requests to Discord. This is useful for bots that do not need to receive websocket events as it will save a lot of
* resources.
*/
constexpr uint32_t NO_SHARDS = ~0U;
inline constexpr uint32_t NO_SHARDS = ~0U;

/**
* @brief Types of startup for cluster::start()
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace dpp {
* @brief predefined color constants.
*/
namespace colors {
static constexpr uint32_t
inline constexpr uint32_t
white = 0xFFFFFF,
discord_white = 0xFFFFFE,
light_gray = 0xC0C0C0,
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/discordclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class cluster;
* @brief How many seconds to wait between (re)connections. DO NOT change this.
* It is mandated by the Discord API spec!
*/
constexpr time_t RECONNECT_INTERVAL = 5;
inline constexpr time_t RECONNECT_INTERVAL = 5;

/**
* @brief Represents different event opcodes sent and received on a shard websocket
Expand Down
67 changes: 67 additions & 0 deletions include/dpp/dpp.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/

module;

// Include the entire standard library so it doesn't cause issue in our headers
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <charconv>
#include <condition_variable>
#include <cstddef>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <queue>
#include <shared_mutex>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <variant>
#include <vector>

#include <dpp/export.h>
#include <dpp/compat.h>

export module dpp;

export extern "C++" {
#include <dpp/dpp.h>
#include <dpp/dns.h>
#include <dpp/restrequest.h>
#include <dpp/unicode_emoji.h>
Comment thread
Mishura4 marked this conversation as resolved.
}
2 changes: 1 addition & 1 deletion include/dpp/etf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace dpp {
/**
* @brief Current ETF format version in use
*/
const uint8_t FORMAT_VERSION = 131;
inline const uint8_t FORMAT_VERSION = 131;
Comment thread
Jaskowicz1 marked this conversation as resolved.
Outdated

/**
* @brief Represents a token which identifies the type of value which follows it
Expand Down
Loading
Loading