Library: Add compatibility for legacy Tokio 0.2 (#40)

Adds support to the library for tokio 0.2 backward-compatibility. This should hopefully benefit, and prevent lavalink-rs from being blocked on this feature.

These can be reached using, e.g., `gateway-tokio-02`, `driver-tokio-02`, `serenity-rustls-tokio-02`, and `serenity-native-tokio-02` features.

Naturally, this requires some jiggering about with features and the underlying CI, which has been taken care of. Twilight can't be handled in this way, as their last tokio 0.2 version uses the deprecated Discord Gateway v6.
This commit is contained in:
Kyle Simpson
2021-02-04 02:34:07 +00:00
committed by GitHub
parent b2453091e7
commit aaab97511d
24 changed files with 353 additions and 146 deletions

View File

@@ -28,6 +28,13 @@ features = ["tokio-runtime"]
optional = true
version = "0.11"
[dependencies.async-tungstenite-compat]
package = "async-tungstenite"
default-features = false
features = ["tokio-runtime"]
optional = true
version = "0.9"
[dependencies.audiopus]
optional = true
version = "0.2"
@@ -62,7 +69,7 @@ version = "0.8"
[dependencies.serenity]
optional = true
version = "0.10"
version = "^0.10.2"
default-features = false
features = ["voice", "gateway"]
@@ -83,6 +90,12 @@ optional = true
version = "1.0"
default-features = false
[dependencies.tokio-compat]
optional = true
package = "tokio"
version = "0.2"
default-features = false
[dependencies.twilight-gateway]
optional = true
version = "0.3"
@@ -115,20 +128,35 @@ criterion = "0.3"
utils = { path = "utils" }
[features]
# Core features
default = [
"serenity-rustls",
"driver",
"gateway",
]
gateway = [
"gateway-core",
"tokio/sync",
]
gateway-core = [
"dashmap",
"flume",
"parking_lot",
"tokio/sync",
]
driver = [
"async-trait",
"async-tungstenite",
"driver-core",
"tokio/fs",
"tokio/io-util",
"tokio/macros",
"tokio/net",
"tokio/process",
"tokio/rt",
"tokio/sync",
"tokio/time",
]
driver-core = [
"async-trait",
"audiopus",
"byteorder",
"discortp",
@@ -138,21 +166,13 @@ driver = [
"serenity-voice-model",
"spin_sleep",
"streamcatcher",
"tokio/fs",
"tokio/io-util",
"tokio/macros",
"tokio/net",
"tokio/process",
"tokio/rt",
"tokio/sync",
"tokio/time",
"typemap_rev",
"url",
"uuid",
"xsalsa20poly1305",
]
rustls = ["async-tungstenite/tokio-rustls"]
native = ["async-tungstenite/tokio-native-tls"]
rustls = ["async-tungstenite/tokio-rustls", "rustls-marker"]
native = ["async-tungstenite/tokio-native-tls", "native-marker"]
serenity-rustls = ["serenity/rustls_backend", "rustls", "gateway", "serenity-deps"]
serenity-native = ["serenity/native_tls_backend", "native", "gateway", "serenity-deps"]
twilight-rustls = ["twilight", "twilight-gateway/rustls", "rustls", "gateway"]
@@ -162,9 +182,41 @@ simd-zlib = ["twilight-gateway/simd-zlib"]
stock-zlib = ["twilight-gateway/stock-zlib"]
serenity-deps = ["async-trait"]
rustls-marker = []
native-marker = []
# Tokio 0.2 Compatibility features
# These should probably be dropped around the same time as serenity drop them.
rustls-tokio-02 = ["async-tungstenite-compat/tokio-rustls", "rustls-marker", "tokio-02-marker"]
native-tokio-02 = ["async-tungstenite-compat/tokio-native-tls", "native-marker", "tokio-02-marker"]
serenity-rustls-tokio-02 = ["serenity/rustls_tokio_0_2_backend", "rustls-tokio-02", "gateway-tokio-02", "serenity-deps"]
serenity-native-tokio-02 = ["serenity/native_tls_tokio_0_2_backend", "native-tokio-02", "gateway-tokio-02", "serenity-deps"]
gateway-tokio-02 = [
"gateway-core",
"tokio-02-marker",
"tokio-compat/sync",
]
driver-tokio-02 = [
"async-tungstenite-compat",
"driver-core",
"tokio-02-marker",
"tokio-compat/fs",
"tokio-compat/io-util",
"tokio-compat/macros",
"tokio-compat/net",
"tokio-compat/process",
"tokio-compat/rt-core",
"tokio-compat/sync",
"tokio-compat/time",
]
tokio-02-marker = []
# Behaviour altering features.
youtube-dlc = []
builtin-queue = []
# Used for docgen/testing/benchmarking.
full-doc = ["default", "twilight-rustls", "builtin-queue", "stock-zlib"]
internals = []
[[bench]]
@@ -179,4 +231,4 @@ required-features = ["internals"]
harness = false
[package.metadata.docs.rs]
features = ["default", "twilight-rustls", "builtin-queue", "stock-zlib"]
features = ["full-doc"]