Skip to content
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

DPP: De-const have_voice option and add coroutines support. #4824

Merged
merged 11 commits into from
Aug 5, 2024
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)
Loading