cmpute / dashu

A library set of arbitrary precision numbers implemented in Rust.
Apache License 2.0
76 stars 9 forks source link

Macro changes to fix some build combinations #18

Closed eduardosm closed 1 year ago

eduardosm commented 1 year ago

Currently, building with

cargo build --all-targets --workspace

will make the build fail. --all-targets means that tests are also compiled (but not run) and --workspace means that all the crates of the workspace are compiled. This caused the dashu-macros crate to be compiled with the embedded feature enabled, which caused tests to fail to compile (because it was looking for types in dashu::* instead of dashu_*).

There are other situations that could trigger this issue. If you had some crate A that depends on dashu-macros, dashu-int and B. B is another crate that depends on dashu, so it will pull dashu-macros with the embedded feature enabled, causing macros to fail in crate A.

To fix this, the embedded feature flag is removed and there are now two variants for each macro, a non-embedded one and an embedded one. The non-embedded variants are visible in in the dashu-macros crate and the embedded variants are hidden in dashu-macros and re-exported in the dashu crate.

cmpute commented 1 year ago

Thanks for proposing the fix! Do you think it's better to re-export the macro in the meta crate with alias? (e.g. use dashu_macro::ubig_embedded as ubig), by this way we can move all the documentation into the dashu-macro crate.

Besides, this will require a major version bump. I have a plan to publish a v0.3.1 version, so it will be merged after that.

eduardosm commented 1 year ago

Moving documentation to the dashu-macros crate for the embedded macros will cause doc-tests to fail because it won't find the dashu crate.

/// For numbers that are small enough (fits in a [u32]), the literal can
/// be assigned to a constant.
///
/// ```
/// use dashu::{ibig, integer::IBig};
///
/// const A: IBig = ibig!(-123);
/// const B: IBig = ibig!(0x123);
/// const C: IBig = ibig!(-0xffff_ffff);
/// ```
---- src/lib.rs - dbig_embedded (line 273) stdout ----
error[E0433]: failed to resolve: use of undeclared crate or module `dashu`
 --> src/lib.rs:274:5
  |
3 | use dashu::{ibig, integer::IBig};
  |     ^^^^^ use of undeclared crate or module `dashu`

And we cannot make dashu-macros depend on dashu because it would create a cyclic dependency between dashu and dashu-macros.

cmpute commented 1 year ago

I think it's a very clever fix! Thanks!

cmpute commented 1 year ago

v0.3.1 is released, and the next planned version is v0.4. So I fixed some conflicts and merged this PR, thanks for your contribution!