Freeze required compiler version and toolchain in the cargo.toml

As a side question to this one, I would like to know if something is available to freeze required compiler version and toolchain (preferably specific per platform) in cargo.toml (or alternative), so that every developer builds fresh project clone with the same rust compiler and tool chain? If it is not available, how this can be achieved?

PS: If you know scala world, you might see it as an analogy of declaration of required scala compiler version and required sbt version, used to built a project. So, for rust it would be declaration of required rust compiler version, toolchain and cargo. 3rd party cargo tools are covered in the referred above thread.

With docker. Freezing compiler is not enough, to ensure the same results, you will often need specific version of various libraries or programs, in essence - you want to control whole environment.

I do production and ci builds this way. I am more about dev machines. Do you run ide in a container too? Ide needs consistent build environment too.

And also. Freezing compiler and toolchain would cover my needs completely. I understand there are other big projects with more complicated dependencies than rustc only.

The way I always worked was just to have sort of script that contains all apt-get commands or version checks to make sure right versions are installed but developers use whatever os, ide or editor they want. With test, staging and production builds being run in controlled environment it was never a problem, but there is no reason not to use docker for that too. I think it depends on the developers - most people I work with have they preferred ide, distro and other tools and wouldn't react well to attempts to control those (beside ensuring that whatever they use causes no issues).

rustup lets you put a .rust-toolchain file in your project, which will then use that version of rustc/cargo in that directory.


Great. That is exactly what I was looking for.!

1 Like

This should probably be more widely publicised. I’ve been using Rust for a year or two and would consider myself a fairly advanced user, yet have never seen this mentioned despite all the people requesting the ability to pin cargo to a specific version.


Update: the file should be named without a dot.

I have managed to freeze rust compiler version. It does not allow to fix toolchain specific for a host (it is OK, reasonable behavior).
I have not found how to freeze cargo version using this approach. Is cargo version defined and corresponds to rust compiler version??? I have noticed some cargo is also pulled when I pulled new compiler with rustup…