Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running "cargo install" in a workspace #7124

Closed
Keruspe opened this issue Jul 12, 2019 · 7 comments
Closed

Allow running "cargo install" in a workspace #7124

Keruspe opened this issue Jul 12, 2019 · 7 comments
Labels
A-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-install S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@Keruspe
Copy link
Contributor

Keruspe commented Jul 12, 2019

I have a project that is split into several crates in the same workspace. Some of these crates enable certain features for some dependencies. When I run cargo build from the workspace level, all the subcrates are built and features are properly enabled for the project as a whole.
Now if I want to install those, I have to go into each crate, then run cargo install --path=., which triggers some rebuild for each crate even if I already have a clean release build.

I would love being able to run, at the workspace level, something like cargo install --path=. --all or cargo install --path=. --crates=foo,bar or cargo install --path=foo --path=bar or anything like that, which would trigger a single build for all the crates, and then proceed with the install

@Keruspe Keruspe added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 12, 2019
@kaimast
Copy link

kaimast commented Sep 23, 2019

I'm surprised this is not supported yet.

@jacobmischka
Copy link

jacobmischka commented Jun 23, 2021

It does seem strange that it's unsupported. I'm currently just manually copying the binaries from the workspace target dir to .cargo/bin or somewhere else in my PATH, but that really shouldn't be necessary.

penberg added a commit to chiselstrike/chiselstrike that referenced this issue Nov 4, 2021
Unfortunately, "cargo install" does not know about workspaces:

rust-lang/cargo#7124

So let's add a "scripts/cargo-install" that installs "chiseld" and
"chisel" to "$HOME/.cargo/bin", which makes it easier to use the tool
locally during development.
penberg added a commit to chiselstrike/chiselstrike that referenced this issue Nov 4, 2021
Unfortunately, "cargo install" does not know about workspaces:

rust-lang/cargo#7124

So let's add a "scripts/cargo-install" that installs "chiseld" and
"chisel" to "$HOME/.cargo/bin", which makes it easier to use the tool
locally during development.
@cbs228
Copy link

cbs228 commented Jan 13, 2022

I propose that cargo-install adopt the --workspace flag to install an entire workspace at once. The tricky part will be the interaction with all the other options.

  • --workspace MUST NOT be allowed in combination with crates from a registry. Only --path and --git support workspaces.

  • cargo install --workspace … -- crate1 crate2 MUST install only crate1 and crate2 from the selected workspace. If no crates are specified, all crates are installed.

  • --workspace SHOULD be silently allowed for crates which are not workspaces. cargo build --workspace works just fine on crates which are not workspaces.

  • cargo install --workspace MAY be interpreted to mean "the current workspace—" i.e., per the output of cargo locate-project --workspace. It may be better to be explicit here and require cargo install --workspace --dir .

  • The --features option SHOULD require the package-name/feature-name syntax as the documentation currently suggests it does.

  • --bins and --examples SHOULD apply as they do for individual crates.

  • The singular --bin and --example are trickier. Right now, trying to install a non-existing target is an error. Perhaps these options should not be allowed in conjunction with --workspace.

Did I miss anything?

In the meanwhile, nightly appears to have:

cargo build --release --workspace --out-dir somewhere/on/my/path

This may permit install-like behavior for workspaces. This does not use the cargo-install machinery. It won't register the crates for cargo install --list or permit future overwrites with cargo-install.

@ghost
Copy link

ghost commented Jul 31, 2022

There seems to be a difference in behavior when installing a workspace binary from Git vs from a local tree? Where cargo install --git=URL works, cargo install --path=. doesn't.

error: found a virtual manifest at `rust-analyzer/Cargo.toml` instead of a package manifest
  • When the toplevel manifest is non-virtual, both cargo install --path=. and cargo install --path=. CRATE throw
error: there is nothing to install in `<TOPLEVEL CRATE>`, because it has no binaries
`cargo install` is only for installing programs, and can't be used with libraries.
To use a library crate, add it as a dependency in a Cargo project instead.

In both cases, cargo install --git=file://$(pwd) works; although, it seems to just scan the entire tree for Cargo manifests. In the following layout, if --bin isn't specified, it might just as well decide to install fuzz_targets binaries instead of crate-bin.

Cargo.toml
   [workspace]
   members = [".", "crate-bin"]
   default-members = ["crate-bin"]
src/
└── lib.rs
fuzz/
├── Cargo.toml
└── fuzz_targets/
crate-bin/
├── Cargo.toml
└── src/main.rs

Note that setting default-members = ["CRATE"] doesn't help in any of the mentioned cases.

graelo added a commit to graelo/tmux-backup that referenced this issue Aug 25, 2022
Building via cargo install needs a root package instead of a virtual
manifest. See <rust-lang/cargo#7124>.
@weihanglo weihanglo added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label May 24, 2023
@weihanglo
Copy link
Member

Triage: Looks pretty similar to #4101.

@johnbchron
Copy link

Bumping this :)

@epage
Copy link
Contributor

epage commented Oct 12, 2023

Closing in favor of #4101. If there is a meaningful distinction that we should keep this open instead, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2023
Arnaud-de-Grandmaison-ARM added a commit to Arnaud-de-Grandmaison-ARM/keybroker-demo that referenced this issue Oct 9, 2024
For some reason, cargo install and cargo build do not do exactly the
same thing.  My commit at

ed6ce14

broke cargo install without us noting it or CI catching it.

This commit adds a test to cover this. It should be noted that Rust does
not yet cargo install with workspace, so we need to point it to each of
the individual binaries that we want to install, for reference see:
 - rust-lang/cargo#7599
 - rust-lang/cargo#4101
 - rust-lang/cargo#7124

We install each of the binaries into a temporary directory that will be
cleaned up automatically by the runner when the job finishes.

Signed-off-by: Arnaud de Grandmaison <arnaud.degrandmaison@arm.com>
Arnaud-de-Grandmaison-ARM added a commit to Arnaud-de-Grandmaison-ARM/keybroker-demo that referenced this issue Oct 9, 2024
For some reason, cargo install and cargo build do not do exactly the
same thing.  My commit at

ed6ce14

broke cargo install without us noting it or CI catching it. This commit
adds a test to cover this.

It should be noted that cargo install does not yet (or still does not !)
play nice with workspace, so we need to point it to each of the
individual binaries that we want to install, for reference see:
 - rust-lang/cargo#7599
 - rust-lang/cargo#4101
 - rust-lang/cargo#7124

We install each of the binaries into a temporary directory provided by
the runner and that will be cleaned up automatically when the job
finishes.

Signed-off-by: Arnaud de Grandmaison <arnaud.degrandmaison@arm.com>
Arnaud-de-Grandmaison-ARM added a commit to veraison/keybroker-demo that referenced this issue Oct 9, 2024
For some reason, cargo install and cargo build do not do exactly the
same thing.  My commit at

Arnaud-de-Grandmaison-ARM@ed6ce14

broke cargo install without us noting it or CI catching it. This commit
adds a test to cover this.

It should be noted that cargo install does not yet (or still does not !)
play nice with workspace, so we need to point it to each of the
individual binaries that we want to install, for reference see:
 - rust-lang/cargo#7599
 - rust-lang/cargo#4101
 - rust-lang/cargo#7124

We install each of the binaries into a temporary directory provided by
the runner and that will be cleaned up automatically when the job
finishes.

Signed-off-by: Arnaud de Grandmaison <arnaud.degrandmaison@arm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-workspaces Area: workspaces C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-install S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

8 participants