-
-
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 all 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Contributor
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. 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
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. I asked for examples to be built in CI but yes the CI needs to be fixed
Contributor
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. Yeah i'm happy with that, it's just the fact that the |
||
| env: | ||
| CXX: g++-12 | ||
| DONT_RUN_VCPKG: true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
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 | ||
| -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,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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| \page using_modules Using D++ with C++ modules | ||
|
|
||
|
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 | ||
| 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. | ||
|
Contributor
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. I would remove this change, doesn't really match the capitalisation across the board but also better to keep changes to a minimum |
||
| 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. | ||
|
Contributor
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. Sorry to nitpick, could we word this to be |
||
| 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.