Skip to content
Open
Show file tree
Hide file tree
Changes from 24 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
56 changes: 49 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,59 @@ 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: clang++-20

test_docs_module_windows:
name: Test build module (Windows)
runs-on: windows-2022
# Experimental: clang-cl C++20 module scanning is only supported from
# CMake 4.4 onwards, and cl.exe cannot consume the nlohmann::json-wrapping
# module. Keep this non-blocking while the toolchain support matures.
continue-on-error: true
concurrency:
group: ${{ github.workflow }}-windows-${{ github.ref }}
cancel-in-progress: true
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
with:
submodules: recursive

- name: Set up MSVC developer environment
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Set up CMake
uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2.2.0
with:
cmake-version: '4.4.x'
github-api-token: ${{ secrets.GITHUB_TOKEN }}

- name: Generate CMake
run: cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=Release -DDPP_NO_VCPKG=ON -DDPP_MODULES=ON -DDPP_BUILD_TEST=ON -DAVX_TYPE=AVX0
env:
DONT_RUN_VCPKG: true

- name: Build module example
run: cmake --build build --target using_modules_example --parallel 2
env:
CXX: g++-12
DONT_RUN_VCPKG: true
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
52 changes: 39 additions & 13 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_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
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 All @@ -34,7 +54,13 @@ write_basic_package_version_file(${DPP_VERSION_FILE}
COMPATIBILITY SameMajorVersion)

## Include the file which allows `find_package(dpp)` to function.
install(FILES "${DPP_ROOT_PATH}/cmake/dpp-config.cmake" "${DPP_VERSION_FILE}" DESTINATION "${DPP_CMAKE_DIR}")
## FindFilesystem.cmake is shipped alongside it because dpp-config.cmake calls
## find_dependency(Filesystem) (the C++20 module links std::filesystem).
install(FILES
"${DPP_ROOT_PATH}/cmake/dpp-config.cmake"
"${DPP_ROOT_PATH}/cmake/FindFilesystem.cmake"
"${DPP_VERSION_FILE}"
DESTINATION "${DPP_CMAKE_DIR}")

## Export the targets to allow other projects to easily include this project
install(EXPORT "${DPP_EXPORT_NAME}" DESTINATION "${DPP_CMAKE_DIR}" NAMESPACE dpp::)
Expand Down
18 changes: 13 additions & 5 deletions cmake/dpp-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## Get current filesystem path (will a prefixed by where this package was installed)
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

## Use this directory to include dpp which has the rest of the project targets
include(${SELF_DIR}/dpp.cmake)
## Make bundled find-modules (e.g. FindFilesystem) discoverable by find_dependency below.
list(APPEND CMAKE_MODULE_PATH "${SELF_DIR}")

include(CMakeFindDependencyMacro)

## Set OpenSSl directory for macos. It is also in our main CMakeLists.txt, but this file is independent from that.
if(APPLE)
Expand All @@ -13,9 +15,15 @@ if(APPLE)
else()
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
find_package(OpenSSL REQUIRED)
endif()

# Search for libdpp dependencies
include(CMakeFindDependencyMacro)
## Search for libdpp dependencies
find_dependency(OpenSSL REQUIRED)

## When D++ is built with C++20 module support the exported module links against the
## std::filesystem imported target on toolchains that need a separate <filesystem>
## library, so consumers must be able to resolve it too. Harmless otherwise.
find_dependency(Filesystem REQUIRED)

## Use this directory to include dpp which has the rest of the project targets
include(${SELF_DIR}/dpp.cmake)
18 changes: 15 additions & 3 deletions docpages/example_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,31 @@
# 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)

find_package(dpp REQUIRED)

set(CMAKE_CXX_EXTENSIONS OFF)

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 -Wno-unused-command-line-argument")
Comment thread
Jaskowicz1 marked this conversation as resolved.
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")

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

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)
target_link_libraries(${examplename}_out dl dpp::dpp mpg123 oggz ogg opusfile opus)
Comment thread
Jaskowicz1 marked this conversation as resolved.
include_directories(/usr/include/opus)

if (DPP_MODULES)
set_target_properties(${examplename}_out PROPERTIES CXX_SCAN_FOR_MODULES ON)
endif()
endforeach(example)
24 changes: 24 additions & 0 deletions docpages/example_code/using_modules.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <string>

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
11 changes: 11 additions & 0 deletions docpages/example_programs/misc/using_modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\page using_modules Using D++ with C++ modules

Comment thread
Jaskowicz1 marked this conversation as resolved.
\include{doc} modules_warn.dox

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
1 change: 1 addition & 0 deletions docpages/include/modules_warn.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\warning D++ modules are currently experimental and are only supported by D++ on g++ 15, clang/LLVM 17, and MSVC 17.6 or above. Additionally, your program has to support C++20.
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
83 changes: 83 additions & 0 deletions include/dpp/dpp.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/************************************************************************************
*
* 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>

#ifdef DPP_USE_EXTERNAL_JSON
#include <nlohmann/json.hpp>
#else
#include <dpp/nlohmann/json.hpp>
#endif

export module dpp;

export extern "C++" {
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
#endif

#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.

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
Loading
Loading