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

Allow bitflags v1 and v2 to coexist #894

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

manushT
Copy link

@manushT manushT commented Nov 27, 2024

The patch breaks cargo's additive features

Fixes #877.

@jonathanpallant
Copy link
Contributor

Unfortunately this doesn't work because Library A might use defmt to describe some data type and expect the bitflags v1 API whilst Library B might use defmt but expect the bitflags v2 API (if we add it).

You could have a feature flag for bitflags v2 so that we keep the dependency list as short as possible, but it has to be additional and exported as a different macro with a different name.

@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch 4 times, most recently from 705a4d2 to aabac90 Compare November 29, 2024 13:46
@jonathanpallant
Copy link
Contributor

The CHANGELOG was reformatted. Can you rebase?

@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch 2 times, most recently from 0ffa167 to 5f6ef8a Compare November 29, 2024 14:34
@jonathanpallant
Copy link
Contributor

The format check failed, I'm afraid.

CHANGELOG.md Outdated
@@ -69,6 +69,7 @@ We have several packages which live in this repository. Changes are tracked sepa
* [#845] `decoder`: fix println!() records being printed with formatting
* [#843] `defmt`: Sort IDs of log msgs by severity to allow runtime filtering by severity
* [#822] `CI`: Run `cargo semver-checks` on every PR
* [#877]:`defmt`: Allow `bitflags` v1 and v2 to coexist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This change was made to Defmt-next because defmt-0.3.9 has already been released so it needs to be in the section above.
  2. This should refer to the PR, which is Allow bitflags v1 and v2 to coexist #894.
  3. You will need to add a URL for [#894] down at the bottom of the file for the link to be valid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch 2 times, most recently from b923d69 to b27ffe3 Compare November 29, 2024 14:45
CHANGELOG.md Outdated
@@ -27,6 +27,7 @@ We have several packages which live in this repository. Changes are tracked sepa
> A highly efficient logging framework that targets resource-constrained devices, like microcontrollers

[defmt-next]: https://github.com/knurling-rs/defmt/compare/defmt-v0.3.9...main
[defmt-next]: https://github.com/knurling-rs/defmt/pull/894
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a markdown link for [defmt-next] which was correct. You can't add another.

The change you've made needs to be listed under ## [defmt-next] heading.

@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch from b27ffe3 to c3cca96 Compare November 29, 2024 15:05
@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch 3 times, most recently from 58cab23 to 5a22752 Compare November 29, 2024 15:23
CHANGELOG.md Show resolved Hide resolved
defmt/src/lib.rs Show resolved Hide resolved
let bits_access = if is_v2 {
quote! { bits() }
} else {
quote! { bits}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
quote! { bits}
quote! { bits }

@jonathanpallant
Copy link
Contributor

@manushT - we still have an outstanding comment on this one.

@Urhengulas Urhengulas added the pr waits on: author Pull Request requires changes from the author label Jan 8, 2025
@@ -8,6 +8,9 @@ use crate::{Format, Formatter, Str};
pub use self::integers::*;
pub use bitflags::bitflags;

#[cfg(feature = "bitflagsv2")]
pub use bitflagsv2::bitflags as bitflagsv2;
Copy link

@vic1707 vic1707 Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may I ask for the bitflags traits (Bits & Flags) to also be re-exported.

Suggested change
pub use bitflagsv2::bitflags as bitflagsv2;
pub use bitflagsv2::{bitflags as bitflagsv2, Bits, Flags};

I need them, and other users might want them too, for a project and would prefer relying on the version installed by defmt instead of listing it manually.
Refers to #923

Copy link
Contributor

@jonathanpallant jonathanpallant Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable - perhaps for v2 import the whole crate like:

pub use bitflags::{bitflags, self};

#[cfg(feature = "bitflagsv2")]
pub use bitflagsv2::{bitflags as bitflagsv2, self};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manushT any thoughts on this one?

@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch 3 times, most recently from ce922bb to fb82c87 Compare January 15, 2025 12:31
Copy link

@LeonMatthesKDAB LeonMatthesKDAB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good to me, only two nitpicks.

defmt/src/lib.rs Outdated Show resolved Hide resolved
defmt/src/lib.rs Outdated Show resolved Hide resolved
defmt/src/lib.rs Outdated Show resolved Hide resolved
@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch from fb82c87 to abd313a Compare January 15, 2025 13:16
@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch from abd313a to e8f6af3 Compare January 29, 2025 16:01
defmt/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@jonathanpallant jonathanpallant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit on some formatting, and I like the proposal for re-exporting some useful types from the crate (to save people having to go and pull in the exact one that defmt is using).

I think this requires a Wire Format Version bump? In which case I think it's blocked until after 1.0. Maybe we should do a Version 5 with the encoded symbols and a bunch of other stuff.

@manushT manushT force-pushed the allow-bitflags-v1-and-v2-to-coexist branch from 6a14e99 to a648875 Compare January 31, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr waits on: author Pull Request requires changes from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow bitflags v1 and v2 to coexist
5 participants