Skip to content

Infer multi-file binaries like src/bin/server/main.rs by convention #4086

@matklad

Description

@matklad

Currently cargo infers binaries from files in src/bin. This works if you binary fits in one file, but if you need more than one file, you have to write custom [[bin]] specification in Cargo.toml.

Looks like a reasonable convention for multifile binary projects is this:

src/
  bin/
    server/
        main.rs
        aux.rs
    client/
        main.rs
        foo.rs

So let's infer src/bin/foo/main.rs as a binary named foo?

This should be mostly backwards compatible change. The only failure case is when someone has src/bin/foo/main.rs which is not a binary, and no [[bin]] sections are present, and this seems unlikely.

A potential edge case is

src/
  bin/
    foo.rs
    foo/
      main.rs

This should be an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyExperience: Easy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions