Skip to content

Commit eea43f1

Browse files
authored
Add shuttle-lazy_static (#234)
1 parent dd6213f commit eea43f1

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"shuttle",
44
"wrappers/shuttle_rand_0.8",
55
"wrappers/shuttle_sync",
6+
"wrappers/lazy_static",
67
]
78

8-
resolver = "2"
9+
resolver = "2"

wrappers/lazy_static/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "shuttle-lazy_static"
3+
version = "1.5.0"
4+
edition = "2024"
5+
6+
[features]
7+
shuttle = ["dep:shuttle-lazy_static-impl"]
8+
9+
spin_no_std = [ "lazy_static/spin_no_std", "shuttle-lazy_static-impl?/spin_no_std" ]
10+
11+
[dependencies]
12+
cfg-if = "1.0"
13+
lazy_static = "1"
14+
shuttle-lazy_static-impl = { path = "./lazy_static_impl", version = "0.1.0", optional = true }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "shuttle-lazy_static-impl"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[features]
7+
spin_no_std = []
8+
9+
[dependencies]
10+
shuttle = { path = "../../../shuttle", version = "*" }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! This crate contains Shuttle's internal implementations of the `lazy_static` crate.
2+
//! Do not depend on this crate directly. Use the `shuttle-lazy_static` crate, which conditionally
3+
//! exposes these implementations with the `shuttle` feature or the original crate without it.
4+
//!
5+
//! [`Shuttle`]: <https://crates.io/crates/shuttle>
6+
//!
7+
//! [`lazy_static`]: <https://crates.io/crates/lazy_static>
8+
9+
// The reason this crate exists and we don't just import directly from shuttle in the wrapper is
10+
// that by doing it like this we can change where the implementation is sourced from without changing
11+
// the wrapper, which is a property needed if one wants the wrapper version to match the version of
12+
// `lazy_static`
13+
pub use shuttle::lazy_static::*;

wrappers/lazy_static/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! This crate provides a Shuttle-compatible implementation and wrapper for [`lazy_static`] in order to make it
2+
//! more ergonomic to run a codebase under Shuttle.
3+
//!
4+
//! [`lazy_static`]: <https://crates.io/crates/lazy_static>
5+
//!
6+
//! To use this crate, add something akin to the following to your Cargo.toml:
7+
//!
8+
//! ```ignore
9+
//! [features]
10+
//! shuttle = [
11+
//! "lazy_static/shuttle",
12+
//! ]
13+
//!
14+
//! [dependencies]
15+
//! lazy_static = { package = "shuttle-lazy_static", version = "1.5" }
16+
//! ```
17+
//!
18+
//! The rest of the codebase then remains unchanged, and running with Shuttle-compatible `lazy_static` can be done via the "shuttle" feature flag.
19+
//!
20+
//! By default the version of `lazy_static` exported is the latest `1.x` version (the same as if you had written `lazy_static = "1"` in your Cargo.toml).
21+
//! If you need to constrain the version of `lazy_static` that you depend on (eg. to pin the version), then this can be done by adding an entry like:
22+
//!
23+
//! ```ignore
24+
//! [dependencies]
25+
//! lazy_static-version-import-dont-use = { package = "lazy_static", version = "=1.5.0" }
26+
//! ```
27+
28+
cfg_if::cfg_if! {
29+
if #[cfg(feature = "shuttle")] {
30+
pub use shuttle_lazy_static_impl::*;
31+
} else {
32+
pub use lazy_static::*;
33+
}
34+
}

0 commit comments

Comments
 (0)