Skip to content

Add cargo build option to select which workspace to look for #9480

Open
@Berjou

Description

@Berjou

Describe the problem you are trying to solve

Currently working on a webapp with the following project structure:

mywebapp/
  |_ backend
    |_ Cargo.toml (defining a mywebapp = { version = "x.x.x", path =" .." } dependency)
  |_ frontend
    |_ Cargo.toml (defining a mywebapp = { version = "x.x.x", path = ".." } dependency)
  |_ src
    |_ root crate source code used by the backend and frontend workspaces
  |_ Cargo.toml (defining `backend` and `frontend` workspaces members)

Note that there is no direct dependency between the frontend and backend workspaces (but they both use common code defined in the root crate).

I can build this code without problem on my dev machine. However, problems appears when trying to setup a CI. Since the frontend and backend need different build dependencies, it make sense I think to use different docker images both using only the strictly required dependencies to build them. For exemple, there is my docker image used to build the backend part of the project:

FROM ekidd/rust-musl-builder AS backend-builder
COPY ./backend/ ./backend/
COPY ./src/ ./src/
COPY ./Cargo.toml .
RUN cargo build -p mywebapp-backend

But here, cargo complains that it cannot read frontend/Cargo.toml. Of course, there are multiple way to make this work, but none of them feels right:

  • COPY the frontend directory as well, but that means giving access to files that should not be needed to my docker image.
  • do not COPY directories and mount the root crate as a volume, but again give access to unnecessary files to my docker image.
  • move the frontend and backend directories inside a new crates directory and defining workspaces member as crates/* using globing and COPY or mount only the needed crates inside my docker image. This seems to be the cleanest solution so far, but feels like a hacky way to tell cargo to look for the backend workspace and not for the frontend one.

Describe the solution you'd like

I think that a cargo build option allowing the dev to include/exclude/select which workspace to look for (maybe similar to the --package option) would be a cleaner and simpler way to handle this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-workspacesArea: workspacesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions