Platform specific crates

What's the canonical way to create platform-specific crates?

One could obviously put all the code in the crate in a platform-specific module, so that when it's built on an unsupported platform it just becomes an empty bin/lib. Or that the functions on unsupported platforms will panic in runtime informing the caller that the functions are unsupported. This would be extremely annoying, imo, so I hope this is discouraged.

How about panicing in build.rs on unsupported platforms?

But how would this affect crater runs? Is there some metadata one can use to signal to bulk builders to not even attempt to build on certain platforms?

A #![cfg(platform)] in the lib.rs should work just fine - I think you can also do

#[cfg(not(platform))]
compile_error!("This library only supports {platform}!");

To prevent compilation on incorrect platforms entirely.

Don't worry about Crater. Crater will only test the same version of your library from Rust version to Rust version.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.