Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Stabilize cargo-script

Metadata
Point of contactEd Page
StatusProposed
FlagshipHigher-level Rust
Tracking issuerust-lang/rust-project-goals#119
Zulip channelN/A (an existing stream can be re-used or new streams can be created on request)
Stabilizationtrue
Teamscargo, compiler, lang, rustdoc
Task owners(none)

Summary

Stabilize support for “cargo script”, the ability to have a single file that contains both Rust code and a Cargo.toml.

Motivation

Being able to have a Cargo package in a single file can reduce friction in development and communication, improving bug reports, educational material, prototyping, and development of small utilities.

The status quo

Today, at minimum a Cargo package is at least two files (Cargo.toml and either main.rs or lib.rs). The Cargo.toml has several required fields.

To share this in a bug report, people resort to

  • Creating a repo and sharing it
  • A shell script that cats out to multiple files
  • Manually specifying each file
  • Under-specifying the reproduction case (likely the most common due to being the easiest)

To create a utility, a developer will need to run cargo new, update the Cargo.toml and main.rs, and decide on a strategy to run this (e.g. a shell script in the path that calls cargo run --manifest-path ...).

Cargo has had unstable Cargo script support for years. New, unstable syntax has been added and gone through rounds of testing. A stabilization report exists for frontmatter syntax but work is needed to finish going through that process and then on Cargo’s side.

The next 6 months

Work with T-lang, T-cargo, and other affected teams as we go through the stabilization process.

TaskOwner(s)Notes
T-rustdoc decide on frontmatter in doctestsowner
Implement behavior for frontmatter in doctestsowner

The “shiny future” we are working towards

Team asks

TeamSupport levelNotes
cargoSmallStabilization process
compilerSmallReviewing any further compiler changes
langSmallStabilization discussions
rustdocSmallDesign decision and PR review

Frequently asked questions