Skip to content

Commit ddb270e

Browse files
Add modules unit test
1 parent b14691c commit ddb270e

31 files changed

+251
-82
lines changed

.github/workflows/test-docs-examples.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ permissions:
1818
jobs:
1919
test_docs_examples:
2020
name: Test build examples
21-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-24.04
2222
concurrency:
2323
group: ${{ github.workflow }}-${{ github.ref }}
2424
cancel-in-progress: true
@@ -35,17 +35,19 @@ jobs:
3535
submodules: recursive
3636

3737
- name: Install apt packages
38-
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
38+
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
3939

4040
- name: Generate CMake
41-
run: mkdir build && cd build && cmake -DDPP_NO_VCPKG=ON -DAVX_TYPE=T_fallback -DDPP_CORO=ON -DCMAKE_BUILD_TYPE=Debug ..
41+
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 ..
4242
env:
43-
CXX: g++-12
43+
CXX: clang++-20
4444

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

4850
- name: Test compile examples
49-
run: cd docpages/example_code && mkdir build && cd build && cmake .. && make -j2
51+
run: cd docpages/example_code && mkdir build && cd build && cmake -G Ninja .. && cmake --build . -j2
5052
env:
51-
CXX: g++-12
53+
CXX: clang++-20

CMakeLists.txt

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OF
3333
option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF)
3434
option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF)
3535
option(DPP_TEST_VCPKG "Force VCPKG build without VCPKG installed (for development use only!)" OFF)
36-
option(DPP_MODULES "Support for C++20 modules" OFF)
36+
option(DPP_MODULES "Support for C++20 modules (experimental)" OFF)
3737

3838
include(CheckCXXSymbolExists)
3939
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -161,38 +161,3 @@ if (NOT WIN32)
161161
target_link_libraries(dpp PRIVATE std::filesystem)
162162
endif()
163163

164-
if (DPP_MODULES)
165-
message("-- C++20 Modules support: ${Green}ENABLED${ColourReset}")
166-
add_library(dpp_module)
167-
168-
target_sources(dpp_module
169-
PUBLIC
170-
FILE_SET CXX_MODULES
171-
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/dpp.cppm"
172-
)
173-
174-
target_compile_features(dpp_module PUBLIC cxx_std_20)
175-
176-
target_include_directories(dpp_module PUBLIC
177-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
178-
$<INSTALL_INTERFACE:include>
179-
)
180-
181-
target_link_libraries(dpp_module PUBLIC dpp)
182-
183-
add_library(dpp::module ALIAS dpp_module)
184-
185-
# Installation
186-
install(TARGETS dpp_module
187-
EXPORT ${PROJECT_NAME}Targets
188-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
189-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
190-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
191-
FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dpp/include
192-
)
193-
194-
target_compile_definitions(dpp PUBLIC DPP_MODULES)
195-
else()
196-
message("-- C++20 Modules support: ${Red}DISABLED${ColourReset} (enable with -DDPP_MODULES=ON)")
197-
endif()
198-

docpages/example_code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ project(documentation_tests)
3333

3434
string(ASCII 27 Esc)
3535

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

3939
file(GLOB example_list ./*.cpp)

docpages/example_code/attachments1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
bot.on_log(dpp::utility::cout_logger());
77

88
/* The event is fired when someone issues your commands */
9-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
9+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1010
/* Check which command they ran */
1111
if (event.command.get_command_name() == "file") {
1212
dpp::message msg(event.command.channel_id, "Hey there, I've got a new file!");

docpages/example_code/autocomplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323
});
2424

2525
/* The interaction create event is fired when someone issues your commands */
26-
bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) {
26+
bot.on_slashcommand([](const dpp::slashcommand_t & event) {
2727

2828
/* Check which command they ran */
2929
if (event.command.get_command_name() == "blep") {

docpages/example_code/cache_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main() {
2323
});
2424

2525
/* The event is fired when someone issues your commands */
26-
bot.on_slashcommand([&bot, &message_cache](const dpp::slashcommand_t& event) {
26+
bot.on_slashcommand([&message_cache](const dpp::slashcommand_t& event) {
2727
/* Check which command they ran */
2828
if (event.command.get_command_name() == "get") {
2929

docpages/example_code/components.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int main() {
77
bot.on_log(dpp::utility::cout_logger());
88

99
/* The event is fired when someone issues your commands */
10-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
10+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1111
/* Check which command they ran */
1212
if (event.command.get_command_name() == "button") {
1313
/* Create a message */
@@ -33,7 +33,7 @@ int main() {
3333
/* When a user clicks your button, the on_button_click event will fire,
3434
* containing the custom_id you defined in your button.
3535
*/
36-
bot.on_button_click([&bot](const dpp::button_click_t& event) {
36+
bot.on_button_click([](const dpp::button_click_t& event) {
3737
/* Button clicks are still interactions, and must be replied to in some form to
3838
* prevent the "this interaction has failed" message from Discord to the user.
3939
*/

docpages/example_code/components2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
bot.on_log(dpp::utility::cout_logger());
77

88
/* The event is fired when someone issues your commands */
9-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
9+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1010
/* Check which command they ran */
1111
if (event.command.get_command_name() == "math") {
1212

@@ -40,7 +40,7 @@ int main() {
4040
}
4141
});
4242

43-
bot.on_button_click([&bot](const dpp::button_click_t & event) {
43+
bot.on_button_click([](const dpp::button_click_t & event) {
4444
if (event.custom_id == "10") {
4545
event.reply(dpp::message("You got it right!").set_flags(dpp::m_ephemeral));
4646
} else {

docpages/example_code/components3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int main() {
77
bot.on_log(dpp::utility::cout_logger());
88

99
/* The event is fired when someone issues your commands */
10-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
10+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1111
/* Check which command they ran */
1212
if (event.command.get_command_name() == "select") {
1313
/* Create a message */
@@ -33,7 +33,7 @@ int main() {
3333
/* When a user clicks your select menu , the on_select_click event will fire,
3434
* containing the custom_id you defined in your select menu.
3535
*/
36-
bot.on_select_click([&bot](const dpp::select_click_t & event) {
36+
bot.on_select_click([](const dpp::select_click_t & event) {
3737
/* Select clicks are still interactions, and must be replied to in some form to
3838
* prevent the "this interaction has failed" message from Discord to the user.
3939
*/

docpages/example_code/components3_rolemenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
bot.on_log(dpp::utility::cout_logger());
77

88
/* The event is fired when someone issues your commands */
9-
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
9+
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
1010
/* Check which command they ran */
1111
if (event.command.get_command_name() == "select") {
1212
/* Create a message */

0 commit comments

Comments
 (0)