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

serde is not an optional dependency #42

Closed
pascalkuthe opened this issue Nov 16, 2021 · 6 comments · Fixed by #46
Closed

serde is not an optional dependency #42

pascalkuthe opened this issue Nov 16, 2021 · 6 comments · Fixed by #46

Comments

@pascalkuthe
Copy link

pascalkuthe commented Nov 16, 2021

Judging from how the Cargo.toml is written, I assumed that serde was supposed to be an optional dependency.
However, when inspecting cargo bloat for my project (which uses smol_str) I noticed a long compile time for serde.
I was able to reproduce with an empty project (just an empty src/lib.rs file):

[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
smol_str = "0.1.21"

Running cargo check shows that serde is compiled and running cargo bloat yields

> cargo bloat --time -j 1
Time Crate
3.20s serde
0.39s smol_str

Just as an example for my larger project, serde is still among the top 7 contributors even tough I am not using it at all (and according to cargo tree only depend upon it trough smol_str).

> cargo bloat --time -j 1
 Time Crate
9.99s syn
9.93s hir_def
5.41s rowan
4.40s basedb
3.59s logos_derive
3.49s regex_syntax
3.10s serde
...

I am using the latest stable version (rust 1.56.1 on linux/nixos). Is there any way to remove the serde dependency or am I missing something?

@lnicola
Copy link
Member

lnicola commented Nov 16, 2021

That's probably because of:

default = ["std"]
std = ["serde/std"]

You can try setting default_features = false on smol_str.

@pascalkuthe
Copy link
Author

Ah yes that does fix the problem. Thank you!
If this is intentional it might be nice to document this because to me a feature named "std" didn't suggest a serde dependency.

@lnicola
Copy link
Member

lnicola commented Nov 16, 2021

Is this rust-lang/cargo#3494?

@pascalkuthe
Copy link
Author

pascalkuthe commented Nov 16, 2021

Yeah, that seems like the same issue. Sadly, the feature to fix this isn't stable yet (although the stabilization RFC has been accepted).

After looking at the source code again, I noticed that the std feature is not used at all (in the src code) currently. So maybe just removing the "std" feature from the default features and adding a notice to the README would be an option until then?

@lnicola
Copy link
Member

lnicola commented Nov 16, 2021

I've seen projects with a use-serde feature instead of serde, but I'm not sure how that helps here.

@pascalkuthe
Copy link
Author

I think the real reason for this feature is that serde can also be used with `!#[no_std]~. So someone that wants to this crate with ![no_std] together with serde would disable the std feature (but enable the serde featurure).

bors bot added a commit that referenced this issue Apr 8, 2022
46: Use new optional dependency feature syntax making serde truly optional r=Veykril a=Veykril

Fixes #42
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
bors bot added a commit that referenced this issue Apr 8, 2022
46: Use new optional dependency feature syntax making serde truly optional r=Veykril a=Veykril

Fixes #42
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
@bors bors bot closed this as completed in #46 Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants