Document many-target projects

Open
#8,960 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
documentation

Research direction

Start with the Cargo targets documentation at cargo/reference/cargo-targets.html#binaries and review the explanations of main.rs, lib.rs, and binary targets. Add a clear explanation that each binary target is its own crate, that main.rs and lib.rs can coexist, and a simple many-target example with imports. Done means newcomers can follow the example without needing Discord.

Written by the indexing model from the issue text.

Description

A-documenting-cargo-itself C-feature-request S-needs-design

I have to go to DIscord to ask even simplest questions.

I was trying to add a new binary target to my project, which currently only has main.rs. It didn't work out of the box - my use crate:: didn't work (now it's obvious). I looked for doc and found this: https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries
Following things were properly documented so I found them:

  • needed to change my mod x to pub mod x in the source code
  • you need to use lib.rs for imports (this was pretty cryptic but I guessed it from "library's public API" wording)

What is not mentioned, and should:

  • Every binary target is its own crate. This is not obvious at all. It's kinda obvious if you think about them as Linux object files, but "crate" is more abstract term created solely for Rust and it needs to be properly defined from the ground up.
  • Main.rs and lib.rs are not mutually exclusive.

A simple example project repository, together with source files with proper imports, with multiple targets, main.rs and lib.rs, would resolve this issue in no time. "Cargo cookbook" in form of file directories on Github would be most useful and probably the best way to figure things out.

Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/cargo

All issues in rust-lang/cargo

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.