Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 39 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,49 @@ 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
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: Add MSBuild to PATH
uses: microsoft/setup-msbuild@30375c66a4eea26614e0d39710365f22f8b0af57 # v3.0.0

- name: Generate CMake
run: cmake -B build -G "Visual Studio 17 2022" -DDPP_NO_VCPKG=ON -DDPP_MODULES=ON -DDPP_BUILD_TEST=OFF -DAVX_TYPE=AVX0
env:
DONT_RUN_VCPKG: true

- name: Build module example
run: cmake --build build --target using_modules_example --config Release --parallel 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this target exist? I can't see it anywhere in this PR. If it does exist, it's not being built for Windows.

This is causing CI to fail

@Mishura4 Mishura4 Jul 19, 2026

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.

I asked for examples to be built in CI but yes the CI needs to be fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah i'm happy with that, it's just the fact that the using_modules_example target doesn't look like it exists

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
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_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 Down
27 changes: 25 additions & 2 deletions docpages/example_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,42 @@
# 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
-fprebuilt-module-path=${CMAKE_SOURCE_DIR}/../../build/library/CMakeFiles/dpp.dir
)
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
2 changes: 1 addition & 1 deletion docpages/include/coro_warn.dox
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\warning D++ Coroutines are currently only supported by D++ on g++ 13, clang/LLVM 14, and MSVC 19.37 or above. Additionally, your program has to support C++20.
\warning D++ coroutines are currently only supported by D++ on g++ 13, clang/LLVM 14, and MSVC 19.37 or above. Additionally, your program has to support C++20.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would remove this change, doesn't really match the capitalisation across the board but also better to keep changes to a minimum

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 only supported by D++ on g++ 15, clang/LLVM 17, and MSVC 17.6 or above. Additionally, your program has to support C++20.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry to nitpick, could we word this to be 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
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 constexpr uint8_t FORMAT_VERSION = 131;

/**
* @brief Represents a token which identifies the type of value which follows it
Expand Down
4 changes: 2 additions & 2 deletions include/dpp/httpsclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

namespace dpp {

static inline const std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, "
inline const std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, "
+ to_hex(DPP_VERSION_MAJOR, false) + "." + to_hex(DPP_VERSION_MINOR, false) + "." + to_hex(DPP_VERSION_PATCH, false) + ")";

static inline constexpr const char* DISCORD_HOST = "https://discord.com";
inline constexpr const char* DISCORD_HOST = "https://discord.com";

/**
* @brief HTTP connection status
Expand Down
Loading
Loading