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

How to retrieve build artifact paths? #3757

Closed
Jascha-N opened this issue Feb 23, 2017 · 10 comments
Closed

How to retrieve build artifact paths? #3757

Jascha-N opened this issue Feb 23, 2017 · 10 comments

Comments

@Jascha-N
Copy link

How do I determine which artifacts cargo produced and where? The used target directory depends on multiple environment variables (e.g. CARGO_TARGETDIR), configuration settings (e.g. build.target-dir and build.target), command-line arguments (--target, --release). Not to mention it gets even more complicated when the package is part of a workspace. Of course it also depends on settings inside Cargo.toml but at least for these settings there's the cargo metadata command.

Now my question is if there is any easy way to know which artifacts were produced and where? Or do I have to parse all of the stuff above and mimic undocumented implementation details of how cargo determines output locations and names? If the latter is the case, then this greatly complicates integrating cargo into any other build system. For my specific use case, I need to provide a post-build step that is project-agnostic, i.e. all of the variables above might change. How should I go about?

@alexcrichton
Copy link
Member

Top level artifacts should always show up in predictable locations (if you're controlling the variables above). Otherwise --message-format=json should print out all paths that are compiled

@Jascha-N
Copy link
Author

Jascha-N commented Feb 23, 2017

Oh right, I completely forgot about that option. However I would still like the possibility to display warnings and error messages in text form. Are these text messages easy to reconstruct from JSON or is some information lost?

EDIT: I'm only interested in top-level binary artifacts, but I do not have control over the variables mentioned. cargo does not seem to output the final file names (inside the release/debug folder) but only the artifacts inside the deps folder. But I guess that is alright since it contains the top-level package as well (albeit with a different suffix). To find out which are the top-level artifacts I could match the package_id against the package_id returned by cargo metadata --no-deps. Is this correct?

@alexcrichton
Copy link
Member

Yeah unfortunately right now once json messages are emitted there's no way to get back the original rendering (currently). It's come up before though and we'd definitely like to be able to enable it!

Also yeah that sounds like a reasonable way to learn about the top-level crate, I believe.

@Jascha-N
Copy link
Author

Would it be possible to have rustc print the original messages in addition to the JSON representation in the same way that cargo does this, i.e. original messages on stderr and JSON on stdout?

@alexcrichton
Copy link
Member

Perhaps yeah, Cargo doesn't currently try to pick which lines are json and which aren't, but we could perhaps soup up the logic. (this'd require changes to the compiler)

@matklad
Copy link
Member

matklad commented Feb 27, 2017

cargo does not seem to output the final file names (inside the release/debug folder)

Fixed in #3752

@alexcrichton
Copy link
Member

Thanks @matklad!

@Jascha-N is that sufficient now perhaps?

@Jascha-N
Copy link
Author

Yeah, thanks, this works fine for now. The only problem I still have is with rustc's messages being in JSON format.

@Jascha-N
Copy link
Author

Jascha-N commented Mar 3, 2017

Actually, having fought with creating a transparent wrapper around cargo for some time now, I can safely say that this is not a solution. There needs to be a better way to obtain the final artifact paths, without butchering all of the rustc output. The only two solutions I can think of is creating a wrapper around rustc that filters out the --error-format json option if --message-format json was not passed to the cargo wrapper or running cargo twice (the second time with --message-format json and output captured) just to obtain the artifact paths. Neither solution is nice in my opinion.

@Jascha-N Jascha-N closed this as completed Mar 5, 2017
@matklad
Copy link
Member

matklad commented Mar 22, 2017

@Jascha-N I've created #3855 about the problem.

elasticdog added a commit to EarthmanMuons/rustops-blueprint that referenced this issue May 20, 2023
There's more work to be done here, but it's a start. Honestly, adding
miniserde just to parse out the Cargo metadata seems way more difficult
than it should be to get an accurate list of the binary artifacts for
the project. There is an unstable `--out-dir` feature to copy artifacts
for you after building, but it hasn't stabilized over the past couple of
years. Not ideal.

See:
- rust-lang/cargo#3757
- rust-lang/cargo#6790 (comment)
- matklad/cargo-xtask#3
elasticdog added a commit to EarthmanMuons/rustops-blueprint that referenced this issue May 20, 2023
There's more work to be done here, but it's a start. Honestly, adding
miniserde just to parse out the Cargo metadata seems way more difficult
than it should be to get an accurate list of the binary artifacts for
the project. There is an unstable `--out-dir` feature to copy artifacts
for you after building, but it hasn't stabilized over the past couple of
years. Not ideal.

See:
- rust-lang/cargo#3757
- rust-lang/cargo#6790 (comment)
- matklad/cargo-xtask#3
elasticdog added a commit to EarthmanMuons/rustops-blueprint that referenced this issue May 20, 2023
There's more work to be done here, but it's a start. Honestly, adding
miniserde just to parse out the Cargo metadata seems way more difficult
than it should be to get an accurate list of the binary artifacts for
the project. There is an unstable `--out-dir` feature to copy artifacts
for you after building, but it hasn't stabilized over the past couple of
years. Not ideal.

See:
- rust-lang/cargo#3757
- rust-lang/cargo#6790 (comment)
- matklad/cargo-xtask#3
github-merge-queue bot pushed a commit to EarthmanMuons/rustops-blueprint that referenced this issue May 20, 2023
There's more work to be done here, but it's a start. Honestly, adding
miniserde just to parse out the Cargo metadata seems way more difficult
than it should be to get an accurate list of the binary artifacts for
the project. There is an unstable `--out-dir` feature to copy artifacts
for you after building, but it hasn't stabilized over the past couple of
years. Not ideal.

See:
- rust-lang/cargo#3757
- rust-lang/cargo#6790 (comment)
- matklad/cargo-xtask#3
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

No branches or pull requests

3 participants