I'm writing a runtime for a programming language implementation in Rust. I'm planning on linking in this runtime with the compiled code I generate, so to keep the binary small I don't want to rely on std.
When I try to cargo test my runtime, I get errors saying saying that std::slice::AsSlice can't be found, which I found is because some of the test harness requires std library code.
How do I go about testing this code? Is there a way to conditionally include the #![no_std] pragma, i.e. still include the std library while testing? I've also tried creating a separate test crate with the std library included, extern crateing the runtime crate into it and running my tests there, but that has introduced a whole new set of issues.
You can cfg_attr to conditionally set no_std.
#![cfg_attr(not(test), no_std)]
#[cfg(test)]
#[macro_use]
extern crate std;
(The #[macro_use] part is optional.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With