Instructions for running Fuchsia host-side tests in miri. The examples use the
miri is an interpreter for Rust code which you can use as a powerful tool to find undefined behavior (UB) in Rust code, analogous to sanitizers for C and C++ like UBSan.
Install rustup and run
Add a nightly toolchain if you don't already have one:
$ rustup install nightly
Add the miri component:
$ rustup +nightly component add miri
cargo miri requires a
Cargo.toml manifest for your crate.
Configure your build to include the test you want to run and to generate Cargo.toml's:
$ fx set PRODUCT.BOARD --with //src/sys/lib/cm_rust:tests --cargo-toml-gen
Run a build:
$ fx build
Link the generated manifest into your source repository:
$ fx gen-cargo '//src/sys/lib/cm_rust:cm_rust_test_executable(//build/toolchain:host_x64)'
See the cargo on Fuchsia docs for more information.
cargo miri must compile a fresh Rust sysroot, which requires access to
external crates which are not vendored in the Fuchsia tree.
src/.cargo/config in your editor and comment out the configuration for
--- a/src/.cargo/config +++ b/src/.cargo/config @@ -1,8 +1,8 @@ -[source.crates-io] -replace-with = "vendored-sources" +#[source.crates-io] +#replace-with = "vendored-sources" -[source.vendored-sources] -directory = "../third_party/rust_crates/vendor" +#[source.vendored-sources] +#directory = "../third_party/rust_crates/vendor"
cargo +nightly miri setup.
Change to the same directory as the generated
$ cd src/sys/lib/cm_rust
$ cargo +nightly miri test