Is it possible to run nightly cargo with stable rustc

Viewed 253

In our project we need to use an unstable cargo option --out-dir, but we still want to use stable rustc to build our rust code. Is this possible?

2 Answers

You can use the __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS environment variable to override the Cargo channel. As the name suggests, it's not really intended to be used. But you can! Keep in mind that with this approach you only get the unstable features included in the latest stable release (and important fixes for unstable features aren't going to get backported to the stable branch, because this shouldn't be used)

# Allow unstable options in Cargo, but use stable rustc
__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS=nightly cargo build -Z unstable-options

You should be able to configure the nightly cargo executable to use the stable rustc compiler by modifying the build.rustc key. You could delegate this to the stable compiler if rustup is installed by setting the value to be rustup run stable rustc.

Related