3

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?

Nowibananatzki
  • 756
  • 1
  • 9
  • 19

2 Answers2

2

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.

EvilTak
  • 7,091
  • 27
  • 36
  • The doc says `build.rustc` should be a path to `rustc` program. How do find where `rustc` is stored? – Nowibananatzki Dec 06 '21 at 21:07
  • @Nowibananatzki the docs do not explicitly say so, but from the key's default value (`"rustc"`) and the existence of environment variable overrides, it looks like `build.rustc` can be any string which, when passed to a shell, would invoke the rustc compiler. If you have `rustup` in your `PATH`, setting the `build.rustc` key to `rustup run stable rustc` should delegate the cargo's compiler call to rustup, which would in turn delegate it to the installed stable rustc if my assumption is correct. The actual path of the `rustc` executable will depend on the installation medium (rustup, apt, etc). – EvilTak Dec 06 '21 at 21:48
2

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
smitop
  • 4,770
  • 2
  • 20
  • 53