# Using miri with custom toolchain

**URL:** <https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199>\
**Category:** uncategorized\
**Created:** [May 20, 2026, 8:18pm UTC](https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199 "2026-05-20T20:18:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![n4n5](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/n4n5/32/38291_2.png) [@n4n5](https://users.rust-lang.org/u/n4n5)\
**Post date:** [May 20, 2026, 8:18pm UTC](https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199/1 "2026-05-20T20:18:21Z")

</div>

I'm trying to use miri with a custom rust build

```sh
# build stage2
./x build src/tools/miri
rustup toolchain link stage2 build/host/stage2
cargo +stage2 miri

```

```rust
info: `cargo` is unavailable for the active toolchain
info: falling back to "/home/USERNAME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo"
Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... fatal error: failed to build sysroot: sysroot build failed; stderr:
error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.

```

Apparently, it is using the cargo stable, but I would like to use the cargo nightly with my custom toolchain.  
Any idea ?

---

<div class="post-metadata">

**Author:** ![n4n5](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/n4n5/32/38291_2.png) [@n4n5](https://users.rust-lang.org/u/n4n5)\
**Post date:** [May 20, 2026, 8:51pm UTC](https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199/2 "2026-05-20T20:51:36Z")

</div>

I think I didn't had the `nightly` installed

```rust
rustup toolchain install nightly

```

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kpreid/32/22420_2.png) [@kpreid](https://users.rust-lang.org/u/kpreid)\
**Post date:** [May 20, 2026, 9:30pm UTC](https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199/3 "2026-05-20T21:30:37Z")

</div>

The fallback behavior is part of `rustup` and is documented here: [Toolchains - The rustup book](https://rust-lang.github.io/rustup/concepts/toolchains.html#custom-toolchains)

---

<div class="post-metadata">

**Author:** ![n4n5](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/n4n5/32/38291_2.png) [@n4n5](https://users.rust-lang.org/u/n4n5)\
**Post date:** [May 20, 2026, 9:33pm UTC](https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199/4 "2026-05-20T21:33:43Z")

</div>

Thanks!

The solution was the note here: [How to build and run the compiler - Rust Compiler Development Guide](https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html)

```rust
Note: the toolchain we’ve built does not include cargo.
In this case, rustup will fall back to using cargo from the installed
nightly, beta, or stable toolchain (in that order).
If you need to use unstable cargo flags, be sure to run rustup install nightly
if you haven’t already. See the rustup documentation on custom toolchains.

```

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [August 18, 2026, 9:33pm UTC](https://users.rust-lang.org/t/using-miri-with-custom-toolchain/140199/5 "2026-08-18T21:33:50Z")

</div>

Closed on August 18, 2026, 9:33pm UTC

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.
