From a4505526b8257468e55952d869289676e8d6b961 Mon Sep 17 00:00:00 2001 From: nk125 Date: Mon, 5 Aug 2024 08:20:55 -0600 Subject: [PATCH] DPP: De-const have_voice option and add coroutines support. (#4824) * fix(dpp): Remove repeated have_voice condition * feat(dpp): Make have_voice option modifiable De-const have_voice option and enables optional download of voice libraries * feat(dpp): Add coroutine support Adds a configurable option to enable coroutine support * fix(dpp)!: Change have_voice to voice inside package As mentioned in the same pull request, prefixes like have_ are discouraged in xmake packages. BREAKING CHANGES: This WILL break xmake scripts that use the have_voice flag, IMO it's better to keep the previous have_voice flag as a deprecated alias of the new voice flag, and in the next version of D++ completely remove it from the package. * fix(dpp): Add C++ minimum version for test If coroutines are enabled, C++20 is required or the compilation will fail even though the test only requires C++17 to work, as dpp automatically includes coroutines if the macro is defined without checking C++ version * fix(dpp): Set C++ language for library dinamically The current configuration wasn't proper and when coroutines were enabled, the C++ version would change to C++17 sporadically, ignoring the later C++20 specification that was done later. Now the C++ version will adjust correctly to the coro flag. * style(dpp): Remove requested empty lines * feat(dpp): Re-add have_voice flag with deprecated warning This will bring up again have_voice to avoid codebase breakage, but with many deprecation warnings around to prevent new users to define it. --- packages/d/dpp/port/xmake.lua | 27 ++++++++++++++++++++++---- packages/d/dpp/xmake.lua | 36 +++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/packages/d/dpp/port/xmake.lua b/packages/d/dpp/port/xmake.lua index 22d9e0f3172..83dd198dbf0 100644 --- a/packages/d/dpp/port/xmake.lua +++ b/packages/d/dpp/port/xmake.lua @@ -1,14 +1,33 @@ add_rules("mode.debug", "mode.release") - -add_requires("fmt", "nlohmann_json", "libsodium", "libopus", "openssl", "zlib") +add_requires("fmt", "nlohmann_json", "openssl", "zlib") +option("coro", {default = false}) +option("voice", {default = true}) +if has_config("voice") then + add_requires("libopus", "libsodium") +end target("dpp") set_kind("$(kind)") - set_languages("c++17") add_includedirs("include", "include/dpp") add_headerfiles("include/(dpp/**.h)") add_files("src/dpp/**.cpp") - add_packages("fmt", "nlohmann_json", "libsodium", "libopus", "openssl", "zlib") + add_packages("fmt", "nlohmann_json", "openssl", "zlib") + + if has_config("voice") then + add_packages("libopus", "libsodium") + add_defines("HAVE_VOICE") + end + + if has_config("coro") then + add_defines("DPP_CORO") + end + + local target_cpp_lang = "c++17" + if has_config("coro") then + target_cpp_lang = "c++20" + end + + set_languages(target_cpp_lang) add_defines("DPP_BUILD", "DPP_USE_EXTERNAL_JSON") diff --git a/packages/d/dpp/xmake.lua b/packages/d/dpp/xmake.lua index fc0d40de563..aba68b11a96 100644 --- a/packages/d/dpp/xmake.lua +++ b/packages/d/dpp/xmake.lua @@ -53,7 +53,9 @@ package("dpp") add_deps("nlohmann_json", "openssl", "zlib") - add_configs("have_voice", { description = "Enable voice support for the library.", default = true, type = "boolean" , readonly = true}) + add_configs("voice", { description = "Enable voice support for the library.", default = true, type = "boolean" , readonly = false}) + add_configs("have_voice", { description = "Enable voice support for the library (Deprecated flag, move out to newer version 'voice').", default = false, type = "boolean" , readonly = false}) + add_configs("coro", { description = "Enable experimental coroutines support for the library.", default = false, type = "boolean" , readonly = false}) if is_plat("linux", "macosx") then add_syslinks("pthread") @@ -64,13 +66,27 @@ package("dpp") package:add("defines", "DPP_STATIC") end if package:config("have_voice") then + wprint([[ + === Deprecation Warning === + You should move out to use voice flag, instead of have_voice + Deprecated: + add_requires("dpp", { + configs = {have_voice = true} + }) + New (Recommended): + add_requires("dpp", { + configs = {voice = true} + }) + This flag will be removed soon, please migrate ASAP! + ]]) + end + if package:config("voice") then package:add("defines", "HAVE_VOICE") package:add("deps", "libsodium", "libopus") end - if package:config("have_voice") then - package:add("defines", "HAVE_VOICE") - package:add("deps", "libsodium", "libopus") + if package:config("coro") then + package:add("defines", "DPP_CORO") end if package:version():le("v10.0.13") then @@ -103,7 +119,11 @@ package("dpp") io.replace("include/dpp/restrequest.h", "#include ", "#include ", {plain = true}) os.rmdir("include/dpp/nlohmann") - local configs = {} + local configs = { + voice = package:config("voice") or package:config("have_voice"), + coro = package:config("coro") + } + if package:version():ge("v10.0.29") and package:is_plat("windows") then configs.cxflags = "/bigobj /Gy" end @@ -112,6 +132,10 @@ package("dpp") end) on_test(function (package) + local test_cpp_ver = "c++17" + if package:config("coro") then + test_cpp_ver = "c++20" + end assert(package:check_cxxsnippets({test = [[ void test() { dpp::cluster bot(std::getenv("BOT_TOKEN")); @@ -124,5 +148,5 @@ package("dpp") }); bot.start(false); } - ]]}, {configs = {languages = "c++17"}, includes = "dpp/dpp.h"})) + ]]}, {configs = {languages = test_cpp_ver}, includes = "dpp/dpp.h"})) end)