Hi there,
I guess I'm not understanding the static concept of Rust in case of how it is treated across crates.
I've created a crate lets name it provider. This crate provides a public static variable:
pub static VARIABLE: SomeType = SomeType::new();
The SomeType here takes care that mutable exclusive access to data and functions of the VARIABLEis guaranteed.
Now I've two different crates that use this one as a dependency. Let's call them consumer-one and consumer-two.
My expectation now was, that either consumer see's always the same static VARIABLE. So if consumer-one does some initialization on this static variable the consumer-two could expect the static variable has performed initialization as well. But I've seen that each crate seem to "instantiate" it's own version of the static VARIABLE. If I print the linker symbols created for the final binary I have confirmed that there are really 2 different symbols for the same static VARIABLE created.
The question now is: Is this function as designed and I do something wrong conceptually are is there a specific trick required to make this staticreally global across the both consumer crates?
That the pub static seem to be a dependent crate local is quite confusing me....
Concerning the versioning issue, you could check your Cargo.lock (manually or via something like cargo-tree) whether indeed two different versions of provider are pulled in.
Thanks for the response and the efforts to reproduce the setup nicely and confirm that it indeed should work as I expect (assuming always the same crate version is factored in). I'll check the versions and try to create a small reproducible setup to see what might be gone wrong ...
That was the right tip. After checking the Cargo.lock I noticed that the "provider" was picked one time from the local drive and one time from the crates.io. Fixed this and now it's exactly as expected