Skip to content

Commit

Permalink
Make protocol authentication optional behind a feature flag.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
BGR360 committed Jan 25, 2022
1 parent a79d5d8 commit eb4707a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ version = "0.0.1"
authors = [ "Thinkofdeath <thinkofdeath@spigotmc.org>", "iceiix <ice_ix@protonmail.ch>" ]
edition = "2021"

[features]
# Enables support for authenticating with Mojang servers.
auth = ["reqwest"]

default = ["auth"]

[dependencies]
serde = "1.0.132"
serde_json = "1.0.73"
Expand All @@ -26,4 +32,4 @@ path = "../std_or_web"
version = "0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
reqwest = { version = "0.11.8", features = [ "blocking" ]}
reqwest = { version = "0.11.8", features = [ "blocking" ], optional = true }
3 changes: 3 additions & 0 deletions protocol/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ pub enum Error {
Disconnect(format::Component),
IOError(io::Error),
Json(serde_json::Error),
#[cfg(feature = "auth")]
#[cfg(not(target_arch = "wasm32"))]
Reqwest(reqwest::Error),
}
Expand All @@ -1035,6 +1036,7 @@ impl convert::From<serde_json::Error> for Error {
}
}

#[cfg(feature = "auth")]
#[cfg(not(target_arch = "wasm32"))]
impl convert::From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Error {
Expand All @@ -1051,6 +1053,7 @@ impl ::std::fmt::Display for Error {
Error::Disconnect(ref val) => write!(f, "{}", val),
Error::IOError(ref e) => e.fmt(f),
Error::Json(ref e) => e.fmt(f),
#[cfg(feature = "auth")]
#[cfg(not(target_arch = "wasm32"))]
Error::Reqwest(ref e) => e.fmt(f),
}
Expand Down
1 change: 1 addition & 0 deletions protocol/src/protocol/mojang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const LOGIN_URL: &str = "https://authserver.mojang.com/authenticate";
const REFRESH_URL: &str = "https://authserver.mojang.com/refresh";
const VALIDATE_URL: &str = "https://authserver.mojang.com/validate";

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

0 comments on commit eb4707a

Please sign in to comment.