Skip to content

Commit eb4707a

Browse files
committed
Make protocol authentication optional behind a feature flag.
Currently, the `hyper` crate (dependency of `reqwest`) causes linker errors when you attempt to compile a consumer of `steven_protocol` as a dylib. Compiling as a dylib is not uncommon for quick iteration; notably popularized by the Bevy game engine. See rust-lang/rust#82151 (comment).
1 parent a79d5d8 commit eb4707a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

protocol/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ version = "0.0.1"
44
authors = [ "Thinkofdeath <[email protected]>", "iceiix <[email protected]>" ]
55
edition = "2021"
66

7+
[features]
8+
# Enables support for authenticating with Mojang servers.
9+
auth = ["reqwest"]
10+
11+
default = ["auth"]
12+
713
[dependencies]
814
serde = "1.0.132"
915
serde_json = "1.0.73"
@@ -26,4 +32,4 @@ path = "../std_or_web"
2632
version = "0"
2733

2834
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
29-
reqwest = { version = "0.11.8", features = [ "blocking" ]}
35+
reqwest = { version = "0.11.8", features = [ "blocking" ], optional = true }

protocol/src/protocol/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ pub enum Error {
10191019
Disconnect(format::Component),
10201020
IOError(io::Error),
10211021
Json(serde_json::Error),
1022+
#[cfg(feature = "auth")]
10221023
#[cfg(not(target_arch = "wasm32"))]
10231024
Reqwest(reqwest::Error),
10241025
}
@@ -1035,6 +1036,7 @@ impl convert::From<serde_json::Error> for Error {
10351036
}
10361037
}
10371038

1039+
#[cfg(feature = "auth")]
10381040
#[cfg(not(target_arch = "wasm32"))]
10391041
impl convert::From<reqwest::Error> for Error {
10401042
fn from(e: reqwest::Error) -> Error {
@@ -1051,6 +1053,7 @@ impl ::std::fmt::Display for Error {
10511053
Error::Disconnect(ref val) => write!(f, "{}", val),
10521054
Error::IOError(ref e) => e.fmt(f),
10531055
Error::Json(ref e) => e.fmt(f),
1056+
#[cfg(feature = "auth")]
10541057
#[cfg(not(target_arch = "wasm32"))]
10551058
Error::Reqwest(ref e) => e.fmt(f),
10561059
}

protocol/src/protocol/mojang.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const LOGIN_URL: &str = "https://authserver.mojang.com/authenticate";
2828
const REFRESH_URL: &str = "https://authserver.mojang.com/refresh";
2929
const VALIDATE_URL: &str = "https://authserver.mojang.com/validate";
3030

31+
#[cfg(feature = "auth")]
3132
#[cfg(not(target_arch = "wasm32"))]
3233
impl Profile {
3334
pub fn login(username: &str, password: &str, token: &str) -> Result<Profile, super::Error> {

0 commit comments

Comments
 (0)