paupino / rust-decimal

Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
https://docs.rs/rust_decimal/
MIT License
1.03k stars 183 forks source link

1.34.0 breaks with cyclic dependency when installed with "macros" feature #641

Closed notonamap closed 9 months ago

notonamap commented 9 months ago

Hey there,

using the package with the new "macros" feature seems to be broken atm.

cargo new --bin foo
cd foo

cargo add rust_decimal --features macros 
    Updating crates.io index
      Adding rust_decimal v1.34.0 to dependencies.
             Features:
             + macros
             + serde
             + std
             31 deactivated features
    Updating crates.io index
error: cyclic package dependency: package `rust_decimal v1.34.0` depends on itself. Cycle:
package `rust_decimal v1.34.0`
    ... which satisfies dependency `rust_decimal = "^1.31"` of package `rust_decimal_macros v1.34.0`
    ... which satisfies dependency `rust_decimal_macros = "^1.33"` of package `rust_decimal v1.34.0`
    ... which satisfies dependency `rust_decimal = "^1.34.0"` of package `foo`

not sure how this is best addressed. proc-macro seems to depend on the from_str decimal stuff. maybe the macro feature needs to be put into a third crate that then reexports macro + decimal? would change the whole project structure so might be a bit overkill.. also definitely not an expert on the intricacies of proc-macros.

rust_decimal: -> decimal (currently rust_decimal) -> macros -> decimal

paupino commented 9 months ago

I think I know what this is - I’m missing an = in the dependency chain. Sorry about this - I’ll get a fix out later today. In the meantime the workaround is to not use the feature and import the macros crate explicitly.

paupino commented 9 months ago

I'm hoping the hotfix (once it propagates) will fix this. If not, then I'll likely pull the feature and work towards the ultimate solution (removing the cyclic dependency altogether).

Will give it a few minutes to propagate and reopen this issue if it doesn't fix it.

paupino commented 9 months ago

Ugh - unfortunately it doesn't fix it. I'm going to pull the feature for the meantime while I work on a better solution for 1.35

paupino commented 9 months ago

The documentation in the main branch now describes the appropriate workaround for including macros. I have a plan for how to implement the macros without the circular dependency - I'll see if I can get something in for the next minor version.

To save a lookup:

cargo add rust_decimal
cargo add rust_decimal_macros

Afterwards, you will need to include the macros where you want to use them. i.e.

use rust_decimal_macros::dec;

let num = dec!(123);