Skip to content

Commit

Permalink
Decouple derive dependencies
Browse files Browse the repository at this point in the history
This decouples the `derive` dependencies from their main dependencies.
This allows them to compile in parallel, ensuring faster compile times.
Additionally the `livesplit-hotkey` crate now doesn't depend on any
`derive` dependency anymore, as it barely needed them.
  • Loading branch information
CryZe committed Aug 25, 2023
1 parent 8973c18 commit 61368e7
Show file tree
Hide file tree
Showing 64 changed files with 268 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
groups:
wasmtime:
patterns:
- "wasmtime*"
- "wasi-common"
reviewers:
- CryZe
41 changes: 0 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@ jobs:
- Linux thumbv7neon
- Linux aarch64
- Linux aarch64 musl
- Linux mips
- Linux mips musl
- Linux mips64
- Linux mips64 musl
- Linux mips64el
- Linux mips64el musl
- Linux mipsel
- Linux mipsel musl
- Linux powerpc
- Linux powerpc64
Expand Down Expand Up @@ -385,13 +380,6 @@ jobs:
target: aarch64-unknown-linux-musl
dylib: skip

- label: Linux mips
target: mips-unknown-linux-gnu
auto_splitting: skip
networking: skip
# FIXME: Networking Tests fail due to missing OpenSSL
# https://github.com/LiveSplit/livesplit-core/issues/308

- label: Linux mips musl
target: mips-unknown-linux-musl
auto_splitting: skip
Expand All @@ -400,13 +388,6 @@ jobs:
# https://github.com/LiveSplit/livesplit-core/issues/308
dylib: skip

- label: Linux mips64
target: mips64-unknown-linux-gnuabi64
auto_splitting: skip
networking: skip
# FIXME: Networking Tests fail due to missing OpenSSL
# https://github.com/LiveSplit/livesplit-core/issues/308

- label: Linux mips64 musl
target: mips64-unknown-linux-muslabi64
auto_splitting: skip
Expand All @@ -415,28 +396,6 @@ jobs:
# https://github.com/LiveSplit/livesplit-core/issues/308
dylib: skip

- label: Linux mips64el
target: mips64el-unknown-linux-gnuabi64
auto_splitting: skip
networking: skip
# FIXME: Networking Tests fail due to missing OpenSSL
# https://github.com/LiveSplit/livesplit-core/issues/308

- label: Linux mips64el musl
target: mips64el-unknown-linux-gnuabi64
auto_splitting: skip
networking: skip
# FIXME: Networking Tests fail due to missing OpenSSL
# https://github.com/LiveSplit/livesplit-core/issues/308
dylib: skip

- label: Linux mipsel
target: mipsel-unknown-linux-gnu
auto_splitting: skip
networking: skip
# FIXME: Networking Tests fail due to missing OpenSSL
# https://github.com/LiveSplit/livesplit-core/issues/308

- label: Linux mipsel musl
target: mipsel-unknown-linux-musl
auto_splitting: skip
Expand Down
17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ members = ["capi", "capi/bind_gen", "crates/*"]

[dependencies]
# core
base64-simd = { version = "0.8.0", default-features = false, features = ["alloc"] }
bytemuck = { version = "1.9.1", default-features = false, features = ["derive"] }
base64-simd = { version = "0.8.0", default-features = false, features = [
"alloc",
] }
bytemuck = { version = "1.9.1", default-features = false }
bytemuck_derive = { version = "1.4.1", default_features = false }
cfg-if = "1.0.0"
itoa = { version = "1.0.3", default-features = false }
time = { version = "0.3.3", default-features = false }
Expand All @@ -44,12 +47,14 @@ libm = "0.2.1"
livesplit-hotkey = { path = "crates/livesplit-hotkey", version = "0.7.0", default-features = false }
livesplit-title-abbreviations = { path = "crates/livesplit-title-abbreviations", version = "0.3.0" }
memchr = { version = "2.3.4", default-features = false }
simdutf8 = { version = "0.1.4", default-features = false, features = ["aarch64_neon"] }
serde = { version = "1.0.98", default-features = false, features = [
simdutf8 = { version = "0.1.4", default-features = false, features = [
"aarch64_neon",
] }
serde = { version = "1.0.186", default-features = false, features = ["alloc"] }
serde_derive = { version = "1.0.186", default_features = false }
serde_json = { version = "1.0.60", default-features = false, features = [
"alloc",
"derive",
] }
serde_json = { version = "1.0.60", default-features = false, features = ["alloc"] }
smallstr = { version = "0.3.0", default-features = false }
snafu = { version = "0.7.0", default-features = false }
unicase = "2.6.0"
Expand Down
28 changes: 23 additions & 5 deletions crates/livesplit-hotkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,41 @@ windows-sys = { version = "0.48.0", features = [
[target.'cfg(target_os = "linux")'.dependencies]
crossbeam-channel = { version = "0.5.6", optional = true }
evdev = { version = "0.12.1", optional = true }
mio = { version = "0.8.0", default-features = false, features = ["os-ext", "os-poll"], optional = true }
mio = { version = "0.8.0", default-features = false, features = [
"os-ext",
"os-poll",
], optional = true }
nix = { version = "0.26.1", features = ["user"], optional = true }
promising-future = { version = "0.2.4", optional = true }
x11-dl = { version = "2.20.0", optional = true }

[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
wasm-bindgen = { version = "0.2.54", optional = true }
web-sys = { version = "0.3.28", default-features = false, features = ["Gamepad", "GamepadButton", "EventTarget", "KeyboardEvent", "Navigator", "Window"], optional = true }
web-sys = { version = "0.3.28", default-features = false, features = [
"EventTarget",
"Gamepad",
"GamepadButton",
"KeyboardEvent",
"Navigator",
"Window",
], optional = true }
js-sys = { version = "0.3.28", default-features = false, optional = true }

[dependencies]
cfg-if = "1.0.0"
serde = { version = "1.0.98", default-features = false, features = ["derive", "alloc"] }
snafu = { version = "0.7.0", default-features = false }
serde = { version = "1.0.186", default-features = false, features = ["alloc"] }
bitflags = "2.0.1"

[features]
default = ["std"]
std = ["snafu/std", "serde/std", "crossbeam-channel", "evdev", "mio", "nix", "promising-future", "windows-sys", "x11-dl"]
std = [
"crossbeam-channel",
"evdev",
"mio",
"nix",
"promising-future",
"serde/std",
"windows-sys",
"x11-dl",
]
wasm-web = ["wasm-bindgen", "web-sys", "js-sys"]
74 changes: 73 additions & 1 deletion crates/livesplit-hotkey/src/key_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ impl<'de> serde::de::Visitor<'de> for KeyCodeVisitor {
}

/// Every [`KeyCode`] is grouped into one of these classes.
#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone, Serialize, Deserialize)]
#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)]
pub enum KeyCodeClass {
/// The *writing system keys* are those that change meaning (i.e., they
/// produce different key values) based on the current locale and keyboard
Expand Down Expand Up @@ -1248,6 +1248,78 @@ pub enum KeyCodeClass {
NonStandard,
}

impl KeyCodeClass {
/// Returns the name of the key code.
pub const fn name(self) -> &'static str {
match self {
Self::WritingSystem => "WritingSystem",
Self::Functional => "Functional",
Self::ControlPad => "ControlPad",
Self::ArrowPad => "ArrowPad",
Self::Numpad => "Numpad",
Self::Function => "Function",
Self::Media => "Media",
Self::Legacy => "Legacy",
Self::Gamepad => "Gamepad",
Self::NonStandard => "NonStandard",
}
}
}

impl FromStr for KeyCodeClass {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"WritingSystem" => Self::WritingSystem,
"Functional" => Self::Functional,
"ControlPad" => Self::ControlPad,
"ArrowPad" => Self::ArrowPad,
"Numpad" => Self::Numpad,
"Function" => Self::Function,
"Media" => Self::Media,
"Legacy" => Self::Legacy,
"Gamepad" => Self::Gamepad,
"NonStandard" => Self::NonStandard,
_ => return Err(()),
})
}
}

impl Serialize for KeyCodeClass {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.name())
}
}

impl<'de> Deserialize<'de> for KeyCodeClass {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(KeyCodeClassVisitor)
}
}

struct KeyCodeClassVisitor;

impl<'de> serde::de::Visitor<'de> for KeyCodeClassVisitor {
type Value = KeyCodeClass;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a valid key code class")
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
KeyCodeClass::from_str(v).map_err(|()| serde::de::Error::custom("invalid key code class"))
}
}

impl KeyCode {
/// Combines the key code with the modifiers to form a [`Hotkey`].
pub fn with_modifiers(self, modifiers: Modifiers) -> Hotkey {
Expand Down
20 changes: 18 additions & 2 deletions crates/livesplit-hotkey/src/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::thread::JoinHandle;
use std::{fmt, thread::JoinHandle};

use crate::{Hotkey, KeyCode};
use crossbeam_channel::Sender;
Expand All @@ -10,7 +10,7 @@ mod evdev_impl;
mod x11_impl;

/// The error type for this crate.
#[derive(Debug, Copy, Clone, snafu::Snafu)]
#[derive(Debug, Copy, Clone)]
#[non_exhaustive]
pub enum Error {
/// The hotkey was already registered.
Expand All @@ -29,6 +29,22 @@ pub enum Error {
ThreadStopped,
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::AlreadyRegistered => "The hotkey was already registered.",
Self::NotRegistered => "The hotkey to unregister was not registered.",
Self::EvDev => "Failed fetching events from evdev.",
Self::EPoll => "Failed polling the event file descriptors.",
Self::NoXLib => "Failed dynamically linking to X11.",
Self::OpenXServerConnection => "Failed opening a connection to the X11 server.",
Self::ThreadStopped => "The background thread stopped unexpectedly.",
})
}
}

/// The result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;

Expand Down
18 changes: 17 additions & 1 deletion crates/livesplit-hotkey/src/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ use crate::{Hotkey, KeyCode, Modifiers};
use std::{
collections::{hash_map::Entry, HashMap},
ffi::c_void,
fmt,
sync::{mpsc::channel, Arc, Mutex},
thread,
};

/// The error type for this crate.
#[derive(Debug, snafu::Snafu)]
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// The hotkey was already registered.
Expand All @@ -46,6 +47,21 @@ pub enum Error {
ThreadStoppedUnexpectedly,
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::AlreadyRegistered => "The hotkey was already registered.",
Self::NotRegistered => "The hotkey to unregister was not registered.",
Self::CouldntCreateEventTap => "Failed creating the event tap.",
Self::CouldntCreateRunLoopSource => "Failed creating the run loop source.",
Self::CouldntGetCurrentRunLoop => "Failed getting the current run loop.",
Self::ThreadStoppedUnexpectedly => "The background thread stopped unexpectedly.",
})
}
}

/// The result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;

Expand Down
13 changes: 11 additions & 2 deletions crates/livesplit-hotkey/src/other/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use crate::{Hotkey, KeyCode};
use alloc::string::String;
use alloc::{fmt, string::String};

/// The error type for this crate.
#[derive(Debug, snafu::Snafu)]
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {}

#[cfg(feature = "std")]
impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
Ok(())
}
}

/// The result type for this crate.
pub type Result<T> = core::result::Result<T, Error>;

Expand Down
15 changes: 14 additions & 1 deletion crates/livesplit-hotkey/src/wasm_web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use web_sys::{window, Event, Gamepad, GamepadButton, KeyboardEvent};
use std::{
cell::{Cell, RefCell},
collections::hash_map::{Entry, HashMap},
fmt,
rc::Rc,
sync::{Arc, Mutex},
};

/// The error type for this crate.
#[derive(Debug, snafu::Snafu)]
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// The hotkey was already registered.
Expand All @@ -22,6 +23,18 @@ pub enum Error {
FailedToCreateHook,
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::AlreadyRegistered => "The hotkey was already registered.",
Self::NotRegistered => "The hotkey to unregister was not registered.",
Self::FailedToCreateHook => "Failed creating the hook.",
})
}
}

/// The result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;

Expand Down
Loading

0 comments on commit 61368e7

Please sign in to comment.