SergioBenitez / state

A Rust library for safe and effortless global and thread-local state management.
Other
207 stars 13 forks source link

Is Loom needed in published crate? #28

Closed thgoebel closed 2 days ago

thgoebel commented 4 days ago

loom is listed as a dependency of state on crates.io: https://crates.io/crates/state/0.6.0/dependencies This is likely because the release was build with --cfg loom when it was published.

However, as I understand it, loom is only needed for testing and the production crate should use std?

So loom shouldn't be a dependency of the crates.io release. As a nice side-effect, not being forced to depend on loom allows me (as a user of state) to keep my dependency closure nice and small.

SergioBenitez commented 4 days ago

It's not required at all; that's just the way crates.io shows the dependency. Try depending on state and looking at your cargo.lock file.

thgoebel commented 4 days ago

Okay, interesting. cargo adds loom and the whole closure to Cargo.lock, but when building it doesn't build loom:

$ cargo version
cargo 1.79.0 (ffa9cf99a 2024-06-03)

$ cargo new repro

$ cd repro

$ cargo build

$ cat Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "repro"
version = "0.1.0"

$ cargo add state
    Updating crates.io index
      Adding state v0.6.0 to dependencies
             Features:
             - tls
    Updating crates.io index
     Locking 52 packages to latest compatible versions
      Adding aho-corasick v1.1.3
      Adding cc v1.0.104
      Adding cfg-if v1.0.0
      Adding generator v0.7.5 (latest: v0.8.1)
      Adding itoa v1.0.11
      Adding lazy_static v1.5.0
      Adding libc v0.2.155
      Adding log v0.4.22
      Adding loom v0.5.6 (latest: v0.7.2)
      Adding matchers v0.1.0 (latest: v0.2.0)
      Adding memchr v2.7.4
      Adding nu-ansi-term v0.46.0 (latest: v0.50.0)
      Adding once_cell v1.19.0
      Adding overload v0.1.1
      Adding pin-project-lite v0.2.14
      Adding proc-macro2 v1.0.86
      Adding quote v1.0.36
      Adding regex v1.10.5
      Adding regex-automata v0.1.10 (latest: v0.4.7)
      Adding regex-automata v0.4.7
      Adding regex-syntax v0.6.29 (latest: v0.8.4)
      Adding regex-syntax v0.8.4
      Adding rustversion v1.0.17
      Adding ryu v1.0.18
      Adding scoped-tls v1.0.1
      Adding serde v1.0.203
      Adding serde_derive v1.0.203
      Adding serde_json v1.0.120
      Adding sharded-slab v0.1.7
      Adding smallvec v1.13.2
      Adding state v0.6.0
      Adding syn v2.0.68
      Adding thread_local v1.1.8
      Adding tracing v0.1.40
      Adding tracing-attributes v0.1.27
      Adding tracing-core v0.1.32
      Adding tracing-log v0.2.0
      Adding tracing-subscriber v0.3.18
      Adding unicode-ident v1.0.12
      Adding valuable v0.1.0
      Adding winapi v0.3.9
      Adding winapi-i686-pc-windows-gnu v0.4.0
      Adding winapi-x86_64-pc-windows-gnu v0.4.0
      Adding windows v0.48.0 (latest: v0.58.0)
      Adding windows-targets v0.48.5 (latest: v0.52.6)
      Adding windows_aarch64_gnullvm v0.48.5 (latest: v0.52.6)
      Adding windows_aarch64_msvc v0.48.5 (latest: v0.52.6)
      Adding windows_i686_gnu v0.48.5 (latest: v0.52.6)
      Adding windows_i686_msvc v0.48.5 (latest: v0.52.6)
      Adding windows_x86_64_gnu v0.48.5 (latest: v0.52.6)
      Adding windows_x86_64_gnullvm v0.48.5 (latest: v0.52.6)
      Adding windows_x86_64_msvc v0.48.5 (latest: v0.52.6)

$ cat Cargo.lock
<snip>long list of all the dependencies, including loom</snip>

$ cargo tree
repro v0.1.0 (/home/thore/workspace/repro)
└── state v0.6.0

$ cargo build
   Compiling state v0.6.0
   Compiling repro v0.1.0 (/home/thore/workspace/repro)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s

So while it pollutes the Cargo.lock, it doesn't pollute the actual build. And it's probably a cargo issue, so closing?

SergioBenitez commented 2 days ago

I guess it makes some sense it would add it to the Cargo.lock. But it definitely shouldn't be building it, and it isn't, so that's good. Closing.