Skip to content

Commit

Permalink
DPP: De-const have_voice option and add coroutines support. (#4824)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Nk125 authored Aug 5, 2024
1 parent bc255af commit a450552
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
27 changes: 23 additions & 4 deletions packages/d/dpp/port/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
36 changes: 30 additions & 6 deletions packages/d/dpp/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -103,7 +119,11 @@ package("dpp")
io.replace("include/dpp/restrequest.h", "#include <nlohmann/json_fwd.hpp>", "#include <nlohmann/json.hpp>", {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
Expand All @@ -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"));
Expand All @@ -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)

0 comments on commit a450552

Please sign in to comment.