Skip to content

Added '--deps-only' to {build, doc} subcommands#3567

Closed
KalitaAlexey wants to merge 1 commit into
rust-lang:masterfrom
KalitaAlexey:make-deps-only-arg
Closed

Added '--deps-only' to {build, doc} subcommands#3567
KalitaAlexey wants to merge 1 commit into
rust-lang:masterfrom
KalitaAlexey:make-deps-only-arg

Conversation

@KalitaAlexey

@KalitaAlexey KalitaAlexey commented Jan 20, 2017

Copy link
Copy Markdown
Contributor

Please don't merge it.
I haven't added tests.

It works, I just want to hear opinions.
Which subcommands can support "--deps-only"?

How can I prevent the bot from building?

Soon I will describe my changes.

Unresolved questions

What to do if --deps-only is passed but there are no dependencies?

What to do if both --deps-only and --no-deps are passed to cargo doc?

@rust-highfive

Copy link
Copy Markdown

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@KalitaAlexey

Copy link
Copy Markdown
Contributor Author

@rust-highfive, stop build.

@KalitaAlexey

Copy link
Copy Markdown
Contributor Author

@brson,
Hi. I want to write a test checking that there is a library in deps folder. The library has metadata-suffix.
How to deal with it?

@alexcrichton

Copy link
Copy Markdown
Member

cc #2644

I'm not personally sold on the motivation for such a feature here to add it to Cargo yet. Perhaps we could continue to gather use cases on the issue itself?

@KalitaAlexey

Copy link
Copy Markdown
Contributor Author

@alexcrichton,
It is useful and easy to add. Why can't we?

@KalitaAlexey

Copy link
Copy Markdown
Contributor Author

cc #2801

@alexcrichton

Copy link
Copy Markdown
Member

The implementation is not as easy as you might think. For example the implementation here is incorrect. For example it looks like this will still compile the library of the current package if there's a binary.

I'd like to get more information about use cases before we add such a feature. "it is useful" to me isn't a concrete reason as to why this feature is motivated.

@KalitaAlexey

KalitaAlexey commented Jan 23, 2017

Copy link
Copy Markdown
Contributor Author

@alexcrichton,

For example it looks like this will still compile the library of the current package if there's a binary.

I can't understand that. Can you rephrase that please?

I will check whether it still compiles a library.

For me it is useful only for cargo doc because my library can be broken and I want to see a documentation to fix my problem, but some people also would like to have it for cargo build.

@alexcrichton

Copy link
Copy Markdown
Member

@KalitaAlexey I'd encourage you to add some tests to this PR to see the behavior. You can try adding a project with both a library and a binary and then assert that cargo build --no-deps doesn't compile the library.

@KalitaAlexey

Copy link
Copy Markdown
Contributor Author

@alexcrichton,
Did you mean cargo build --deps-only?

@alexcrichton

Copy link
Copy Markdown
Member

Ah yes, I do

@KalitaAlexey

Copy link
Copy Markdown
Contributor Author

Currently I little time.
When I have time I will improve this.

@alexcrichton

Copy link
Copy Markdown
Member

Closing due to inactivity, but feel free to resubmit with comments addressed!

@atodorov

atodorov commented Aug 2, 2017

Copy link
Copy Markdown

@alexcrichton I'm a +1 for using this inside Docker but I'm not sure if we can do this. In my Dockerfile I have:

COPY src/ /bdcs-api-rs/
RUN cd /bdcs-api-rs/ && cargo build

What I want to do is:

COPY src/Cargo.toml /bdcs-api-rs/
RUN cd /bdcs-api-rs/ && cargo build --dependencies-only

COPY src/ /bdcs-api-rs/
RUN cd /bdcs-api-rs/ && cargo build

so that I rebuild the dependencies only if they changed and I can reuse the intermediate Docker container running the --dependencies-only step.

Is it possible to implement this option without having the source code available, only Cargo.toml and/or Cargo.lock ? If yes can you point to some places in the code I may be able to produce a PR ?

@alexcrichton

Copy link
Copy Markdown
Member

@atodorov right now Cargo's not really built to cater to that use case unfortunately. Getting that working in a reliable fashion would be pretty difficult.

@atodorov

Copy link
Copy Markdown

FYI I've managed to work around this by using cargo build -p and a small Python script to parse Cargo.toml. Works well for me. If you need to see examples checkout my blog.

@nacardin

nacardin commented Mar 7, 2018

Copy link
Copy Markdown

I just published a cargo extension crate to make this easier. I've been using it in one of my projects. https://crates.io/crates/cargo-build-deps
Feedback via issues/PRs would be appreciated. https://github.com/nacardin/cargo-build-deps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants