Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: remove vendored lazy_static on no-std #2173

Merged
merged 7 commits into from Jun 22, 2022
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jun 22, 2022

Motivation

Currently, no_std targets use a vendored version of lazy_static that
uses the spin crate's Once type, while the std target uses the
once_cell crate's Lazy type. This is unfortunate, as the
lazy_static macro has a different interface from the Lazy cell type.
This increases the amount of code that differs based on whether or not
std is enabled.

Solution

This branch removes the vendored lazy_static macro and replaces it
with a reimplementation of once_cell::sync::Lazy that uses
spin::Once rather than once_cell::sync::OnceCell as the inner "once
type". Now, all code can be written against a Lazy struct with the
same interface, regardless of whether or not std is enabled.

Note that this change is only against v0.1.x, since the vendored
lazy_static! macro has already been removed on master.

Currently, `no_std` targets use a vendored version of `lazy_static` that
uses the `spin` crate's `Once` type, while the `std` target uses the
`once_cell` crate's `Lazy` type. This is unfortunate, as the
`lazy_static` macro has a different interface from the `Lazy` cell type.
This increases the amount of code that differs based on whether or not
`std` is enabled.

This branch removes the vendored `lazy_static` macro and replaces it
with a reimplementation of `once_cell::sync::Lazy` that uses
`spin::Once` rather than `once_cell::sync::OnceCell` as the inner "once
type". Now, all code can be written against a `Lazy` struct with the
same interface, regardless of whether or not `std` is enabled.
@hawkw hawkw requested a review from a team as a code owner June 22, 2022 20:07
@notgull
Copy link

notgull commented Jun 22, 2022

Doesn't the spin crate have its own implementation of Lazy?

@hawkw
Copy link
Member Author

hawkw commented Jun 22, 2022

Doesn't the spin crate have its own implementation of Lazy?

It does in recent versions. The vendored version used in tracing predates the addition of that API. We could potentially just update the vendored code to a newer version of spin; this felt easier as it didn't involve deleting a bunch of unused code.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw enabled auto-merge (squash) June 22, 2022 22:29
@hawkw hawkw merged commit f7966bd into v0.1.x Jun 22, 2022
@hawkw hawkw deleted the eliza/oncecell-nostd branch June 22, 2022 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants