# Provide a way to always build required binaries

**URL:** <https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403>\
**Category:** cargo\
**Created:** [August 24, 2023, 1:38pm UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403 "2023-08-24T13:38:54Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![kpreid](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kpreid/32/8484_2.png) [@kpreid](https://internals.rust-lang.org/u/kpreid)\
**Post date:** [August 26, 2023, 12:16am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/21 "2023-08-26T00:16:46Z")

</div>

Ah, I see. Artifact dependencies would allow you to build that configuration instead of having to run two `cargo build`s. You wouldn't be able to publish the package, though, with an unpublished (even if optional) dependency; the rule is that [only dev-dependencies can be missing](https://doc.rust-lang.org/cargo/commands/cargo-package.html#description). You'd have to publish with a modified version of the manifest `Cargo.toml`.

Maybe there could be a separate feature which allows deleting only-for-workspace-development features & dependencies from a package being published.

---

<div class="post-metadata">

**Author:** ![dlight](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dlight/32/8462_2.png) [@dlight](https://internals.rust-lang.org/u/dlight)\
**Post date:** [August 26, 2023, 2:37am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/22 "2023-08-26T02:37:44Z")

</div>

Another thing: if `cargo run` built all binaries, this would break the xtask pattern, which relies on `cargo xtask` being locally aliased to `cargo run --package xtask`, and the build of the xtask binary itself is supposed to be lightweight (so that you can execute tasks without full rebuilds even if you changed some source)

---

<div class="post-metadata">

**Author:** ![mrcnski](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mrcnski/32/11186_2.png) [@mrcnski](https://internals.rust-lang.org/u/mrcnski)\
**Post date:** [September 14, 2023, 10:55am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/23 "2023-09-14T10:55:14Z")

</div>

Does someone have an idea if artifact dependencies would fit our use case?

How far away are artifact dependencies from stable, and can we help move this feature along?

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [September 14, 2023, 11:13am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/24 "2023-09-14T11:13:54Z")

</div>

Cargo has already accepted a related feature. It's not implemented:

> <https://github.com/rust-lang/rfcs/blob/HEAD/text/3028-cargo-binary-dependencies.md>

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [September 14, 2023, 11:21am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/25 "2023-09-14T11:21:32Z")

</div>

> [@mrcnski](#):
>
> Does `cargo install` respect artifact dependencies, i.e. by installing all the required binaries?

It “respects” it, but it will not install them, the binary is built into a temp-dir and a path is provided to you allowing you to either execute it as part of your build.rs or embed it into your crate as a static blob.

---

<div class="post-metadata">

**Author:** ![simonbuchan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/simonbuchan/32/9390_2.png) [@simonbuchan](https://internals.rust-lang.org/u/simonbuchan)\
**Post date:** [September 15, 2023, 8:24am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/26 "2023-09-15T08:24:42Z")

</div>

FWIW I've been using the xtask pattern for a few years, and while it's initially fairly annoying to build your own task runner up front it is quite nice once it's there, and crates like clap and cargo\_metadata make things fairly straightforward.

The main problem I've found is that running tests from ides and the like doesn't work great if there's environmental stuff the build is expecting from the task builder. I'm honestly not sure what a cargo native build should do in those situations, so I'm not really salty about it.

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [September 15, 2023, 11:23am UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/27 "2023-09-15T11:23:33Z")

</div>

> [@simonbuchan](#):
>
> The main problem I've found is that running tests from ides and the like doesn't work great if there's environmental stuff the build is expecting from the task builder. I'm honestly not sure what a cargo native build should do in those situations, so I'm not really salty about it.

I think you can hack something using `config.<tripple>.runner` here:

[https://doc.rust-lang.org/cargo/reference/config.html#configuration-format](https://doc.rust-lang.org/cargo/reference/config.html#configuration-format)

Basically, IDE runs `cargo test`, that internally proxies through your own runner (which may be the same xtrask binary), and that could setup env and whatnot. Probably at some point you'll need to use an env-var to break the cycle and disable the runner.

---

<div class="post-metadata">

**Author:** ![mrcnski](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mrcnski/32/11186_2.png) [@mrcnski](https://internals.rust-lang.org/u/mrcnski)\
**Post date:** [September 15, 2023, 1:09pm UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/28 "2023-09-15T13:09:04Z")

</div>

The xtask pattern looks interesting, and would help with `cargo run` + `cargo build`, but not `cargo install` I think. Wouldn't it be better to have an integrated way to do this with cargo, by extending either `default-members` or artifact dependencies?

But, the artifact deps RFC linked by @kornel explicitly says this is not a goal (as @Nemo157 also pointed out):

> Note that cargo only supplies these dependencies when building your crate. If your program or library requires artifacts at runtime, you will still need to handle that yourself by some other means. Runtime requirements for installed crates are out of scope for this change.

So AFAICT there are two possibilities. And as stated, we're willing to put in the work to implement and stabilize either of these...

1. my original proposal of extending `default-members` (would be faster to stabilize?)
2. extending the scope of artifact dependencies (seems like the better tool for the job?)

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [March 8, 2025, 1:09pm UTC](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403/29 "2025-03-08T13:09:32Z")

</div>

Closed on March 8, 2025, 1:09pm UTC

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/provide-a-way-to-always-build-required-binaries/19403.md?page=1)
