BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Rust 1.8 Introduces New Cargo-based Build System and more

Rust 1.8 Introduces New Cargo-based Build System and more

This item in japanese

Rust 1.8 adds a couple of new language features and a number of improvements to the standard library. Additionally, it introduces a new Cargo-based build system for rustc which can be seen as the first step towards bootstrapping Rust.

The first new feature concerns operators in the “operator equals” family, such as += and -=, which can be now overloaded using traits. This makes it possible to write the following code to define += for the Count class:

use std::ops::AddAssign;

#[derive(Debug)]
struct Count { 
    value: i32,
}

impl AddAssign for Count {
    fn add_assign(&mut self, other: Count) {
        self.value += other.value;
    }
}

The second syntax change to Rust is a minor one, that allows to omit previously required curly braces when defining a struct with no fields, e.g.:

struct Foo; // this is correct, whereas previously struct Foo {} was required

This change will make it slightly easier to write macros, which will not need to treat that as a special case, as well as switching from empty and non-empty versions of structs.

More substantially, Rust 1.8 introduces a new build system based on Cargo to eventually replace Make. According to Rust developer Alex Crichton, submitter of the mentioned PR that implements this change, several reasons led to the new build system:

  • Makefiles are often impenetrable, which has the effect of making it very hard to change it when needs be;
  • make, though highly portable, is not “infinitely” portable and this is most notably demonstrated by the lack of a default make on Windows systems;
  • moving to Cargo for the Rust compiler and standard library should add more uniformity to the development process for Rust programmers and also enable the use of commonly used tools such as the crates.io package manager;

All of the above listed benefits have a high cost, though, since Rust make-based build system has been carefully crafted and tuned for years. So, the process to replace make will be a “long road”, writes Crichton.

As mentioned, the availability of a 100%-Rust build system can be seen as the first step towards fully bootstrapping Rust, which should come in Rust 1.10.

Finally, Rust 1.8 adds further stabilization to its standard library, specifically with UTF–16-related methods, various time-related APIs, and the traits needed for operator overloading mentioned above.

Another new feature in Rust 1.8, which is still considered to be of beta quality, though, is rustup, which allow developers to install additional versions of stdlib for different platforms and thus make it easier to handle cross compilation by, e.g., automatically handling all dependency requirements:

$ rustup target add x86_64-unknown-linux-musl
  info: downloading component 'rust-std' for 'x86_64-unknown-linux-musl'
  13.77 MiB / 13.77 MiB (100.00%) 1.47 MiB/s ETA: 0s
  info: installing component 'rust-std' for
  'x86_64-unknown-linux-musl'

Rust 1.8 can be downloaded from its install page, while detailed release notes are available on GitHub.

Rate this Article

Adoption
Style

BT