How to test if crate is working across `#[cfg(target_pointer_width = "${xx}"]` where `${xx}` = `"16"`, `"32"`, `"64"`

Context

I am the author of sosecrets-rs and right now, I am writing RTSecret<T, MEC: typenum::Unsigned>, which represents a secret that would return an Err or panics only if the value of its internal counter (a counter that measures the number of time a secret is exposed, I name it as ec) exceeds the runtime unsigned integer value represented by the type parameter MEC.

I implement a certain trait according to the target_pointer_width differently with the configuration flag. (sosecrets-rs/src/traits.rs at feature/runtime-secret-#37-condtype-on-mec-only · jymchng/sosecrets-rs · GitHub)

Question

How can I test that this implementation is working correctly across the different targets that have different pointer widths?

There is no way other than to build for such targets, because only such a build will actually exercise those properties.

If you're concerned only with your cfgs being correct, then a cargo check may be sufficient; if you need to run tests then you'll need an emulator for a 16-bit target.

1 Like