-
-
Notifications
You must be signed in to change notification settings - Fork 201
feat: Add C++ modules support #1530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 15 commits
cc86cef
b9e4215
868782b
1d41aa9
ce88aff
7defeb8
15dbf83
6c828af
349c958
2eb60f1
6d39166
531227d
d887c03
8cf7f90
55eadfb
d87cb46
b1699de
ac09477
4a12d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
mikomikotaishi marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
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") | ||
|
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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I can see that, but why?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clang obtains the BMI paths through
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Jaskowicz1 marked this conversation as resolved.
Outdated
|
||
| -fprebuilt-module-path=${CMAKE_SOURCE_DIR}/../../build/library/CMakeFiles/dpp.dir | ||
| ) | ||
| endif() | ||
| endforeach(example) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include <string> | ||
| #include <typeinfo> | ||
|
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; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| \page using_modules Using D++ with C++ modules | ||
|
|
||
|
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 | ||
| 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> | ||
|
Mishura4 marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.