Skip to content

Commit cda3a9c

Browse files
committed
refactor: split core modules out into foundation
1 parent 0b85860 commit cda3a9c

File tree

20 files changed

+99
-40
lines changed

20 files changed

+99
-40
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/StardustXR/stardust-xr-server/"
1010
homepage = "https://stardustxr.org"
1111

1212
[workspace]
13-
members = ["codegen"]
13+
members = ["codegen", "foundation"]
1414

1515
[[bin]]
1616
name = "stardust-xr-server"
@@ -176,3 +176,6 @@ git = "https://github.com/StardustXR/core.git"
176176

177177
[dependencies.stardust-xr-server-codegen]
178178
path = "codegen"
179+
180+
[dependencies.stardust-xr-server-foundation]
181+
path = "foundation"

foundation/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
edition = "2024"
3+
name = "stardust-xr-server-foundation"
4+
version = "0.1.0"
5+
6+
[features]
7+
default = []
8+
profile_tokio = ["tokio/tracing"]
9+
10+
[dependencies]
11+
# small utility thingys
12+
rustc-hash = "2.0.0"
13+
parking_lot = "0.12.3"
14+
dashmap = "6.1.0"
15+
16+
# rust errors/logging
17+
color-eyre = { version = "0.6.3", default-features = false }
18+
thiserror = "2.0.11"
19+
20+
# (de)serialization
21+
serde = { version = "1.0.205", features = ["derive"] }
22+
23+
# mathy stuffs
24+
tokio = { version = "1.39.2", features = ["rt-multi-thread", "signal", "time"] }
25+
26+
[dependencies.stardust-xr-wire]
27+
git = "https://github.com/StardustXR/core.git"
28+
# path = "../core/wire"
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ pub enum ServerError {
3636
#[macro_export]
3737
macro_rules! bail {
3838
($msg:literal $(,)?) => {
39-
return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($msg)));
39+
return Err($crate::error::ServerError::from(color_eyre::eyre::eyre!($msg)));
4040
};
4141
($err:expr $(,)?) => {
42-
return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($err)));
42+
return Err($crate::error::ServerError::from(color_eyre::eyre::eyre!($err)));
4343
};
4444
($fmt:expr, $($arg:tt)*) => {
45-
return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($fmt, $($arg)*)));
45+
return Err($crate::error::ServerError::from(color_eyre::eyre::eyre!($fmt, $($arg)*)));
4646
};
4747
}
4848

@@ -55,17 +55,17 @@ macro_rules! ensure {
5555
};
5656
($cond:expr, $msg:literal $(,)?) => {
5757
if !$cond {
58-
return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($msg)));
58+
return Err($crate::error::ServerError::from(color_eyre::eyre::eyre!($msg)));
5959
}
6060
};
6161
($cond:expr, $err:expr $(,)?) => {
6262
if !$cond {
63-
return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($err)));
63+
return Err($crate::error::ServerError::from(color_eyre::eyre::eyre!($err)));
6464
}
6565
};
6666
($cond:expr, $fmt:expr, $($arg:tt)*) => {
6767
if !$cond {
68-
return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($fmt, $($arg)*)));
68+
return Err($crate::error::ServerError::from(color_eyre::eyre::eyre!($fmt, $($arg)*)));
6969
}
7070
};
7171
}
File renamed without changes.

foundation/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub mod delta;
2+
pub mod error;
3+
pub mod id;
4+
pub mod registry;
5+
pub mod resource;
6+
pub mod task;
7+
8+
pub use id::*;
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::sync::{Arc, LazyLock, Weak};
99

1010
#[derive(Debug)]
1111
pub struct Registry<T: Send + Sync + ?Sized>(MaybeLazy<DashMap<usize, Weak<T>>>);
12-
1312
impl<T: Send + Sync + ?Sized> Registry<T> {
1413
pub const fn new() -> Self {
1514
Registry(MaybeLazy::Lazy(LazyLock::new(DashMap::default)))
@@ -91,7 +90,6 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
9190
self.0.iter().all(|v| v.value().strong_count() == 0)
9291
}
9392
}
94-
9593
impl<T: Send + Sync + ?Sized> Clone for Registry<T> {
9694
fn clone(&self) -> Self {
9795
Self(self.0.clone())
@@ -102,7 +100,6 @@ impl<T: Send + Sync + ?Sized> Default for Registry<T> {
102100
Self::new()
103101
}
104102
}
105-
106103
impl<T: Send + Sync + Sized> FromIterator<Arc<T>> for Registry<T> {
107104
fn from_iter<I: IntoIterator<Item = Arc<T>>>(iter: I) -> Self {
108105
Registry(MaybeLazy::NonLazy(
@@ -175,6 +172,11 @@ impl<T: Send + Sync + ?Sized> OwnedRegistry<T> {
175172
self.lock().clear();
176173
}
177174
}
175+
impl<T: Send + Sync + ?Sized> Default for OwnedRegistry<T> {
176+
fn default() -> Self {
177+
Self::new()
178+
}
179+
}
178180
impl<T: Send + Sync + ?Sized> Clone for OwnedRegistry<T> {
179181
fn clone(&self) -> Self {
180182
Self(Mutex::new(self.0.lock().clone()))
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use stardust_xr_wire::values::ResourceID;
22
use std::{
33
ffi::OsStr,
44
path::{Path, PathBuf},
5+
sync::LazyLock,
56
};
67

7-
use super::client::Client;
8-
9-
lazy_static::lazy_static! {
10-
static ref THEMES: Vec<PathBuf> = std::env::var("STARDUST_THEMES").map(|s| s.split(':').map(PathBuf::from).collect()).unwrap_or_default();
11-
}
8+
static THEMES: LazyLock<Vec<PathBuf>> = LazyLock::new(|| {
9+
std::env::var("STARDUST_THEMES")
10+
.map(|s| s.split(':').map(PathBuf::from).collect())
11+
.unwrap_or_default()
12+
});
1213

1314
fn has_extension(path: &Path, extensions: &[&OsStr]) -> bool {
1415
if let Some(path_extension) = path.extension() {
@@ -18,9 +19,9 @@ fn has_extension(path: &Path, extensions: &[&OsStr]) -> bool {
1819
}
1920
}
2021

21-
pub fn get_resource_file(
22+
pub fn get_resource_file<'a>(
2223
resource: &ResourceID,
23-
client: &Client,
24+
base_prefixes: impl Iterator<Item = &'a PathBuf>,
2425
extensions: &[&OsStr],
2526
) -> Option<PathBuf> {
2627
match resource {
@@ -30,10 +31,9 @@ pub fn get_resource_file(
3031
}
3132
ResourceID::Namespaced { namespace, path } => {
3233
let file_name = path.file_name()?;
33-
let base_prefixes = client.base_resource_prefixes.lock().clone();
3434
THEMES
3535
.iter()
36-
.chain(base_prefixes.iter())
36+
.chain(base_prefixes)
3737
.filter_map(|prefix| {
3838
let prefixed_path = prefix.clone().join(namespace).join(path);
3939
let parent = prefixed_path.parent()?;
File renamed without changes.

0 commit comments

Comments
 (0)