-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Enable test-only code via feature instead of target_arch. #291
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach looks good to me.
I think you meant to put the cfg instead the quote! macros though. See my inline comments.
@@ -12,6 +12,10 @@ version = "0.1.1" | |||
[lib] | |||
proc-macro = true | |||
|
|||
[features] | |||
# WARNING: for internal use only, not covered by semver guarantees | |||
unstable-test = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the feature is necessary in this crate. The proc macro code is emitting cfg(feature = "unstable-test")
but not using the Cargo feature.
EDIT: after reading the rest of the PR, I see that we do want this
macros/src/lib.rs
Outdated
@@ -924,11 +924,11 @@ pub fn internp(ts: TokenStream) -> TokenStream { | |||
let section = format!(".defmt.prim.{}", sym); | |||
|
|||
quote!(match () { | |||
#[cfg(target_arch = "x86_64")] | |||
#[cfg(feature = "unstable-test")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this (cfg inside quote!
) seems fine because internp
is an implementation detail and only used within defmt non-public / non-user-facing code.
macros/src/lib.rs
Outdated
@@ -992,11 +992,11 @@ fn mksym(string: &str, tag: &str, is_log_statement: bool) -> TokenStream2 { | |||
format_ident!("S") | |||
}; | |||
quote!(match () { | |||
#[cfg(target_arch = "x86_64")] | |||
#[cfg(feature = "unstable-test")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cfg
however will end in the code emitted by the logging macros, write!
, intern!
, etc. I'm not sure if that's the behavior we want.
The other option is make the defmt macros always emit the fetch_add_string_index
version if its "unstable-test" feature is enabled.
EDIT: OK, after reading the rest of the PR. I think this should be:
if cfg!(feature = "unstable-test") {
quote!(/* .. */) // fetch add string version
} else {
quote!(/* .. */) // linker version
}
src/lib.rs
Outdated
@@ -574,7 +574,7 @@ impl Formatter { | |||
// these need to be in a separate module or `unreachable!` will end up calling `defmt::panic` and | |||
// this will not compile | |||
// (using `core::unreachable!` instead of `unreachable!` doesn't help) | |||
#[cfg(target_arch = "x86_64")] | |||
#[cfg(feature = "unstable-test")] | |||
mod x86_64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this module should be renamed as it's no longer x86 only
@@ -43,7 +43,7 @@ jobs: | |||
shell: bash | |||
- name: Run tests on Ubuntu/Windows | |||
if: matrix.os != 'macOS-latest' | |||
run: cargo test --workspace | |||
run: cargo test --workspace --features unstable-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in addition to this I think we should also run: RUSTFLAGS='--deny warnings' cargo check --features unstable-test
(there's a previous build step that does this without the --features)
Thanks for the review. Nice catch about the macros, I didn't think about that at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great 💯 Thanks for implementing this!
Fixes #223
target_arch = "x86_64"
withfeature = "unstable-test"
everywhereCargo.toml
s--features unstable-test
in CI script