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

Add a method for a dependency to 'push' an artifact up the dependency tree #5644

Open
zacps opened this issue Jun 21, 2018 · 5 comments
Open
Labels
A-crate-dependencies Area: [dependencies] of any kind C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-rfc Status: Needs an RFC to make progress.

Comments

@zacps
Copy link

zacps commented Jun 21, 2018

Motivation: alacritty/alacritty#1374 (comment)

In the case above our binary crate depends on another binary (winpty-agent) which is built by one of it's dependants. At the moment there is no easy way for our crate to access artifacts produced in a dependencies target directory, unless it's a library linked by cargo.

alacritty <- Binary needed here
    winpty
        winpty-sys <- Binary built here

My suggestion is too add an output to the build script called 'publishes' which contains a name of an artifact produced by the build script. Setting this will make cargo copy it into any crates which require it as a dependency. In this scenario winpty-sys AND winpty would set publishes to the name of the binary. It would be copied into winpty's target directory, then into alacritty's target directory.

@matklad matklad added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jun 26, 2018
@matklad
Copy link
Member

matklad commented Jun 26, 2018

Currently, Cargo does not support working with arbitrary artifacts, resources, etc: it handles only dependencies between Rust libraries, where a Rust library is a very rigidly defined concept.

While it is possible in theory to add such feature to Cargo, it would definitely require a significant amount of design work, and I personally not sure that it aligns well with the way Cargo works today.

I wonder if this can be solved outside of Cargo, though? Presumably, you need the binary in the specific location to make packaging and tests work? Could you explicitly run cargo build --package winpty --bin winpty as a separate step in the CI build?

@zacps
Copy link
Author

zacps commented Jun 26, 2018

winpty is in a different repository to alacritty, if I understand your suggestion correctly we'd need to add a build script to clone winpty, build it, copy it to alacritty and build alacritty.

In my mind that's basically complex enough to require a makefile, which is not ideal considering this is exclusively for Windows...

I know cargo is not currently planning to deal with this and I respect the decision to not want to add features to try to deal with it without much planning. However I feel like this is a pretty simple solution that wouldn't get in the way of any future work.

@matklad
Copy link
Member

matklad commented Jun 26, 2018

winpty is in a different repository to alacritty, if I understand your suggestion correctly we'd need to add a build script to clone winpty, build it, copy it to alacritty and build alacritty.

Hm, the binary that you are interested in is actually in C++, and not in Rust, right? I've missed this originally. I was trying to say that something like this works:

~/tmp/foo master*
λ cat Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]

[dependencies]
ripgrep = "*"

~/tmp/foo master*
λ cargo build -p ripgrep --bin rg
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs

~/tmp/foo master*
λ ls target/debug/ | ./target/debug/rg rg
.rwxr-xr-x  44M matklad 27 Jun  0:22 rg
.rw-r--r-- 1.2k matklad 27 Jun  0:22 rg.d

but you can't use this trick if the binary is in C++...

@zacps
Copy link
Author

zacps commented Jun 26, 2018

Yeah it's built by the build script.

Repository is here, on the rust branch.

https://github.com/zacps/winpty

@epage
Copy link
Contributor

epage commented Oct 19, 2023

FYI there has been interest in "artifact dependencies", see rust-lang/rfcs#2887

@epage epage added A-crate-dependencies Area: [dependencies] of any kind S-needs-rfc Status: Needs an RFC to make progress. labels Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-crate-dependencies Area: [dependencies] of any kind C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-rfc Status: Needs an RFC to make progress.
Projects
None yet
Development

No branches or pull requests

3 participants