Skip to content

contrary to manifest, cargo does not build src/bin/*.rs when toml contains [[bin]] #4013

@boxofrox

Description

@boxofrox

According to http://doc.crates.io/manifest.html#the-project-layout...

Cargo will also treat any files located in src/bin/*.rs as executables.

... which is presented as an invariant. There is no mention that this is conditional.

My project started out with with a few binaries src/bin/*.rs. When src/bin/daemon.rs ballooned, I refactored it into src/bin/daemon/main.rs and organized extracted code into modules under src/bin/daemon.

Once I added a [[bin]] entry to Cargo.toml, cargo build only builds the daemon binary, and no longer adheres to the quote above.

I see two options here:

  1. Update the quoted portion of the manifest to indicate that *Cargo will treat any files located in /src/bin/*.rs as executables unless the toml contains a [[bin]] section.

  2. Modify the behavior of cargo to comply with the docs. cargo treats any files located in src/bin/*.rs that are not otherwise defined in a [[bin]] section as executables.

    a. cargo fetches list of binaries from src/bin/*.rs.
    b. cargo replaces any binaries from src/bin/*.rs with respective [[bin]] entries found in toml.
    c. cargo builds all executables in said list.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions