Is it possible to have multiple coexisting Rust in

2019-02-24 10:46发布

问题:

Would it be possible to have a nightly build Rust compiler for convenience (faster build cycle, auto-update) and a dev version of Rust cloned from GitHub for experimentation purposes?

The idea is I have a binary version of Rust for my various project and a version of Rust I can hack on, without them causing havoc between each other.

If it matters, assume my OS is Ubuntu 64-bit.

回答1:

The current solution is to use rustup. Once installed, you can install multiple toolchains:

rustup install nightly
rustup install stable
rustup install 1.7

If you have a local build of Rust, you can link it as a toolchain

rustup toolchain link my-development /path/to/rust/code

You can pick a default toolchain

rustup default stable

Or add an override toolchain for a specific directory

cd /my/cool/project
rustup override set nightly

If you want to just use a different toolchain temporarily, you can use the "plus syntax":

rustc +1.7 --help
cargo +nightly build

In other cases you can use rustup run to run any arbitrary command in a specific toolchain:

rustup run nightly any command you want here 

See also:

  • How to execute cargo test using the nightly channel?


回答2:

Sure. In the development version, use the --prefix option to ./configure, e.g. --prefix=~/opt/rust-dev, and then its installed files will be contained entirely inside that directory.



回答3:

You also don't need to install your development version. You could just make symlink from somewhere in your $PATH to the rustc binary that lives somewhere inside the source tree/build directory, the compiler will find its dynamically linked dependencies and it will emit binaries that know about that path too (if even dynamically linked).



回答4:

Try envirius.

It allows you to create any number of environments with any version of the rust.

For the first time it will download the source code of the rust and will compile it. And it will take some time. But second and subsequent attempts will takes under 10 seconds as it just will copy the binaries into the target environment.

For example:

➥ nv mk --rust=0.9
Creating environment: rust-0.9 ...
 * installing rust==0.9 ...
 * done (in 5 secs.)

➥ nv ls
Available environment(s):
rust-0.9

➥ nv on rust-0.9
Environment rust-0.9 activated.

(rust-0.9) ➥ rustc -v
rustc 0.9


回答5:

Try to configure your IDE. Though I am working on Windows computer, I think the idea is similar to Ubuntu.

First, I've installed 3 versions of Rust into:

C:\Rust\64 beta MSVC 1.9
C:\Rust\64 nightly MSVC 1.10
C:\Rust\64 stable MSVC 1.8

Then I configured my IDE (in this case, IntelliJ IDEA 2016 + Rust Plug-In) to use different versions of Rust depending on build selector.

After this I can compile my code with different Rust versions just by selecting build-config from toolbar.



标签: settings rust