Enable test-only code via feature instead of target_arch.#291
Enable test-only code via feature instead of target_arch.#291japaric merged 3 commits intoknurling-rs:mainfrom
Conversation
japaric
left a comment
There was a problem hiding this comment.
The approach looks good to me.
I think you meant to put the cfg instead the quote! macros though. See my inline comments.
|
|
||
| [features] | ||
| # WARNING: for internal use only, not covered by semver guarantees | ||
| unstable-test = [] |
There was a problem hiding this comment.
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
|
|
||
| quote!(match () { | ||
| #[cfg(target_arch = "x86_64")] | ||
| #[cfg(feature = "unstable-test")] |
There was a problem hiding this comment.
this (cfg inside quote!) seems fine because internp is an implementation detail and only used within defmt non-public / non-user-facing code.
| }; | ||
| quote!(match () { | ||
| #[cfg(target_arch = "x86_64")] | ||
| #[cfg(feature = "unstable-test")] |
There was a problem hiding this comment.
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
}| // (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.
nit: this module should be renamed as it's no longer x86 only
| - 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.
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. |
japaric
left a comment
There was a problem hiding this comment.
This is great 💯 Thanks for implementing this!
Fixes #223
target_arch = "x86_64"withfeature = "unstable-test"everywhereCargo.tomls--features unstable-testin CI script