Skip to main content

moon v1.5 - Rust tier 2 and 3 support

· 3 min read
Miles Johnson

With this release, we're announcing not just tier 2, but also tier 3 support for the Rust language.

As big fans of Rust (moon is written in it), we're stoked to finally add full language support, and to integrate our first non-JavaScript language! This release is rather massive, and required a ton of internal work, most of which we'll skip over.

Instead we'll only talk about the key features that you, the consumers, will actually care about. To start, we've started working on a Rust handbook, that outlines how to enable Rust, what kind of integrations we support, and a handful of common questions.

New rust configurations

Languages in moon are enabled through configuration blocks in .moon/toolchain.yml, and Rust is no different. We now support a rust toolchain setting (view all available settings).

.moon/toolchain.yml
rust:
version: '1.69.0'

When the rust setting is defined, it will enable the language and deep platform integration, and when the version field is defined, it will further enable toolchain support. Both of these features provide heavy automation, improving the overall developer experience.

This is fantastic, but what if another Rust project in the monorepo requires a different toolchain channel/version? If so, they can use the new toolchain.rust setting in moon.yml to define project-level overrides.

<project>/moon.yml
toolchain:
rust:
version: '1.58.0'

New rust task platform

The main benefit of Rust language support is that tasks can be ran within the context of our Rust platform integration. This can easily be done by setting the project's language to "rust" in moon.yml.

This will set the platform of all tasks within the project to "rust", unless they have been explicitly configured to something else.

<project>/moon.yml
language: 'rust'
type: 'application'

If you're mixing languages within a single project, and can't use the language setting above, you can define platform on the task directly.

<project>/moon.yml
tasks:
build:
command: 'cargo build'
platform: 'rust'

We also attempt to detect this automatially by comparing command names and checking for the existence of files like Cargo.toml.

Updated moon init command

As part of this release, we've also updated the moon init command to support initializing Rust. By default, the command will prompt you on whether to install Rust or not, otherwise, when --yes is passed, the language will be installed if a Cargo.toml file is detected in the destination directory.

If you already have a moon workspace, you can pass --tool rust to install Rust into the workspace.

$ moon init --tool rust

Updated moon docker commands

And lastly, we also want to provide a great Dockerfile experience when using Rust. The moon docker scaffold command has been updated to copy Cargo.toml, Cargo.lock, rust-toolchain.toml, and other Rust/Cargo related files. When using Cargo workspaces, nested Cargo.toml files are also scaffolded.

RUN moon docker scaffold rust-app

Furthermore, we've also updated the moon docker prune command to remove the entire target directory, greatly reducing the size of the image. Pruning makes the assumption that it's being ran after a release profile has been built.

RUN moon run rust-app:build-release
RUN moon docker prune

Other changes

View the official release for a full list of changes.