Skip to content

Commit

Permalink
Support more targets (#42)
Browse files Browse the repository at this point in the history
With the release of rustls v0.21.8, a lot more architectures are
supported now.
  • Loading branch information
CryZe committed Oct 24, 2023
1 parent 4fcce82 commit 4178f59
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 67 deletions.
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "splits-io-api"
version = "0.3.0"
version = "0.3.1"
authors = ["Christopher Serr <christopher.serr@gmail.com>"]
edition = "2021"
documentation = "https://docs.rs/splits-io-api/"
Expand All @@ -21,22 +21,23 @@ include = [

[dependencies]
http = "0.2.0"
serde = { version = "1.0.99", features = ["derive"] }
serde_json = "1.0.40"
serde = "1.0.189"
serde_derive = "1.0.189"
serde_json = "1.0.107"
snafu = { version = "0.7.1", default-features = false, features = ["std"] }
url = "2.1.0"
uuid = { version = "1.1.2", default-features = false, features = ["serde"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(target_family = "wasm"))'.dependencies]
hyper = { version = "0.14.1", default-features = false, features = ["tcp", "client", "http2"] }

[target.'cfg(all(any(target_os = "linux", target_family = "windows", target_os = "macos"), any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64")))'.dependencies]
hyper-rustls = { version = "0.23.0", default-features = false, features = ["native-tokio", "http2", "tls12"] }
[target.'cfg(all(any(target_os = "linux", target_family = "windows", target_os = "macos"), any(target_arch = "arm", target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64", target_arch = "loongarch64", all(target_arch = "mips", target_endian = "little"), all(target_arch = "mips64", target_endian = "little"), all(target_arch = "powerpc", target_endian = "big"), target_arch = "powerpc64", target_arch = "riscv64", target_arch = "s390x")))'.dependencies]
hyper-rustls = { version = "0.24.1", default-features = false, features = ["native-tokio", "http2", "tls12"] }

[target.'cfg(all(not(target_arch = "wasm32"), not(all(any(target_os = "linux", target_family = "windows", target_os = "macos"), any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64")))))'.dependencies]
[target.'cfg(all(not(target_family = "wasm"), not(all(any(target_os = "linux", target_family = "windows", target_os = "macos"), any(target_arch = "arm", target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64", target_arch = "loongarch64", all(target_arch = "mips", target_endian = "little"), all(target_arch = "mips64", target_endian = "little"), all(target_arch = "powerpc", target_endian = "big"), target_arch = "powerpc64", target_arch = "riscv64", target_arch = "s390x")))))'.dependencies]
hyper-tls = "0.5.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(target_family = "wasm")'.dependencies]
js-sys = "0.3.31"
wasm-bindgen = "0.2.51"
wasm-bindgen-futures = "0.4.4"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async fn get_json<T: serde::de::DeserializeOwned>(
serde_json::from_reader(reader).context(JsonSnafu)
}

#[derive(serde::Deserialize)]
#[derive(serde_derive::Deserialize)]
struct ApiError {
#[serde(alias = "message")]
error: Box<str>,
Expand Down
8 changes: 4 additions & 4 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
mod native;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
pub use self::native::*;

#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
mod wasm;
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
pub use self::wasm::*;
44 changes: 36 additions & 8 deletions src/platform/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@ use hyper::body::Buf;
#[cfg(all(
any(target_os = "linux", target_family = "windows", target_os = "macos"),
any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "loongarch64",
all(target_arch = "mips", target_endian = "little"),
all(target_arch = "mips64", target_endian = "little"),
all(target_arch = "powerpc", target_endian = "big"),
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "s390x",
),
))]
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
#[cfg(not(all(
any(target_os = "linux", target_family = "windows", target_os = "macos"),
any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "loongarch64",
all(target_arch = "mips", target_endian = "little"),
all(target_arch = "mips64", target_endian = "little"),
all(target_arch = "powerpc", target_endian = "big"),
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "s390x",
),
)))]
use hyper_tls::HttpsConnector;
Expand All @@ -42,10 +56,17 @@ impl Client {
#[cfg(all(
any(target_os = "linux", target_family = "windows", target_os = "macos"),
any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "loongarch64",
all(target_arch = "mips", target_endian = "little"),
all(target_arch = "mips64", target_endian = "little"),
all(target_arch = "powerpc", target_endian = "big"),
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "s390x",
),
))]
let https = HttpsConnectorBuilder::new()
Expand All @@ -56,10 +77,17 @@ impl Client {
#[cfg(not(all(
any(target_os = "linux", target_family = "windows", target_os = "macos"),
any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "aarch64",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "loongarch64",
all(target_arch = "mips", target_endian = "little"),
all(target_arch = "mips64", target_endian = "little"),
all(target_arch = "powerpc", target_endian = "big"),
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "s390x",
),
)))]
let https = HttpsConnector::new();
Expand Down
28 changes: 12 additions & 16 deletions src/race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub async fn get(client: &Client, id: Uuid) -> Result<Race, Error> {
}

/// The settings for a Race.
#[derive(Default, serde::Serialize)]
#[derive(Default, serde_derive::Serialize)]
pub struct Settings<'a> {
/// The ID of the Game that is being raced.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -176,8 +176,10 @@ pub struct Settings<'a> {
}

/// The type of update to perform on the given property.
#[derive(Default)]
pub enum Update<T> {
/// Keep the previous value of the property.
#[default]
Keep,
/// Clear the value of the property.
Clear,
Expand All @@ -191,12 +193,6 @@ impl<T> Update<T> {
}
}

impl<T> Default for Update<T> {
fn default() -> Self {
Update::Keep
}
}

impl<T: serde::Serialize> serde::Serialize for Update<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -210,7 +206,7 @@ impl<T: serde::Serialize> serde::Serialize for Update<T> {
}

/// The new properties to use for a Race when performing an update.
#[derive(Default, serde::Serialize)]
#[derive(Default, serde_derive::Serialize)]
pub struct UpdateSettings<'a> {
/// The update to perform for the ID of the Game that is being raced.
#[serde(skip_serializing_if = "Update::is_keep")]
Expand Down Expand Up @@ -305,15 +301,15 @@ pub enum JoinAs<'a> {
Ghost(&'a str),
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct JoinToken<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
join_token: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
entry: Option<JoinEntry<'a>>,
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct JoinEntry<'a> {
run_id: &'a str,
}
Expand Down Expand Up @@ -376,22 +372,22 @@ pub async fn leave(client: &Client, race_id: Uuid, entry_id: Uuid) -> Result<(),
Ok(())
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct UpdateEntry<T> {
entry: T,
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct ReadyState {
readied_at: Option<&'static str>,
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct FinishState {
finished_at: Option<&'static str>,
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct ForfeitState {
forfeited_at: Option<&'static str>,
}
Expand Down Expand Up @@ -599,12 +595,12 @@ pub async fn get_chat(client: &Client, id: Uuid) -> Result<Vec<ChatMessage>, Err
Ok(chat_messages)
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct SendMessage<'a> {
chat_message: SendMessageBody<'a>,
}

#[derive(serde::Serialize)]
#[derive(serde_derive::Serialize)]
struct SendMessageBody<'a> {
body: &'a str,
}
Expand Down
6 changes: 3 additions & 3 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ pub async fn get(client: &Client, id: &str, historic: bool) -> Result<Run, Error
Ok(run)
}

#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
struct UploadResponse {
id: Box<str>,
claim_token: Box<str>,
presigned_request: PresignedRequest,
}

#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
struct PresignedRequest {
uri: Box<str>,
fields: PresignedRequestFields,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[derive(Debug, serde_derive::Deserialize, serde_derive::Serialize)]
struct PresignedRequestFields {
key: Box<str>,
policy: Box<str>,
Expand Down
24 changes: 12 additions & 12 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use uuid::Uuid;
/// A Category is a ruleset for a Game (Any%, 100%, MST, etc.) and an optional container for Runs.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#category)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Category {
/// The time and date at which this category was created on Splits.io. This field conforms to
/// ISO 8601.
Expand All @@ -20,7 +20,7 @@ pub struct Category {
/// A Chat Message is a shortform message sent by a user to a Race
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#chat-message)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct ChatMessage {
/// The contents of the message.
pub body: Box<str>,
Expand All @@ -39,7 +39,7 @@ pub struct ChatMessage {
/// An Entry represents a Runner's participation in a Race or a ghost of a past Run.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#entry)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Entry {
/// The time and date at which this Entry was created on Splits.io. This field conforms to ISO
/// 8601.
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct Entry {
/// A Game is a collection of information about a game, and a container for Categories.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#game)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Game {
/// The known speedrun categories for this game.
pub categories: Option<Vec<Category>>,
Expand All @@ -100,7 +100,7 @@ pub struct Game {
/// Information about a past attempt associated with a Run.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#history)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct RunItemHistories {
/// The corresponding attempt number this attempt was.
pub attempt_number: u32,
Expand All @@ -113,7 +113,7 @@ pub struct RunItemHistories {
/// A Run maps 1:1 to an uploaded splits file.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#run)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Run {
/// The number of run attempts recorded by the timer that generated the run's source file, if
/// supported by the source timer.
Expand Down Expand Up @@ -178,7 +178,7 @@ pub struct Run {
/// A Runner is a user who has at least one run tied to their account.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#runner)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Runner {
/// The avatar of the user.
#[serde(default)]
Expand All @@ -204,7 +204,7 @@ pub struct Runner {
/// Information about a past attempt of a segment.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#history)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct SegmentItemHistories {
/// The corresponding attempt number this attempt was.
pub attempt_number: u32,
Expand All @@ -217,7 +217,7 @@ pub struct SegmentItemHistories {
/// A Segment maps to a single piece of a run, also called a split.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#segment)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Segment {
/// Gametime duration in milliseconds of the segment.
#[serde(default)]
Expand Down Expand Up @@ -284,7 +284,7 @@ pub struct Segment {
/// A Race is a live competition between multiple Runners who share a start time for their run.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#race)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Race {
/// Any attachments supplied by the race creator for the benefit of other entrants (e.g. for
/// randomizers).
Expand Down Expand Up @@ -324,7 +324,7 @@ pub struct Race {
/// A file that is attached to a Race.
///
/// [API Documentation](https://github.com/glacials/splits-io/blob/master/docs/api.md#attachment)
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, serde_derive::Deserialize)]
pub struct Attachment {
/// The unique ID of the attachment.
pub id: Uuid,
Expand All @@ -337,7 +337,7 @@ pub struct Attachment {
}

/// The permission set for a Race.
#[derive(Copy, Clone, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Copy, Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Visibility {
/// Anyone can join the race.
Expand Down

0 comments on commit 4178f59

Please sign in to comment.