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 harness field to cargo metadata output #11846

Open
jordanisaacs opened this issue Mar 14, 2023 · 4 comments
Open

Add harness field to cargo metadata output #11846

jordanisaacs opened this issue Mar 14, 2023 · 4 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata

Comments

@jordanisaacs
Copy link

jordanisaacs commented Mar 14, 2023

Problem

For third party rust compilation tools, we would like to follow the behavior of cargo. This requires using cargo metadata and its respective crate for parsing Cargo.toml files. However, the harness value is missing from the metadata output. Thus cannot follow the correct behavior for things like [[bench]] which tend to use harness = false resulting in --test. See here.

Proposed Solution

Simple add a harness value to the cargo metadata output.

Notes

No response

@jordanisaacs jordanisaacs added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 14, 2023
@epage
Copy link
Contributor

epage commented Mar 15, 2023

For third party rust compilation tools,

This part stood out to me. I'm assuming you'll be needing more than just harness for doing this. Would it be possible to further enumerate your needs so we can talk about them as a whole rather than piecemeal?

Out of curiosity, are you able to say what this tool is?

Also, as an FYI, we have a Zulip stream dedicated to build system integrators](https://rust-lang.zulipchat.com/#narrow/stream/334885-t-cargo.2Fbuild-integration), in case that becomes useful in the future

@jordanisaacs
Copy link
Author

jordanisaacs commented Mar 15, 2023

It is for nix's build system. Specifially the buildRustCrate build function from nixpkgs and crate2nix. The buildRustCrate nix function invokes rustc in a very nix specific way, but attempts to follow some of the standards set by cargo such as file layout & build target kinds. While crate2nix is a codegen tool for taking Cargo.toml and Cargo.lock (relying on cargo metadata) and generating a nix file that compiles the crate and its dependencies using invocations of buildRustCrate function.

crate2nix/buildRustCrate currently has limited support for tests, examples, benches, etc. I am working on better support but ran into the fact that harness is not outputted by cargo metadata. This is important because many benches use harness = false and use criterion. Note: buildRustCrate does not rely on any cargo metadata functionality. But, crate2nix relies on it to generate the correct codegen. An WIP PR for buildRustCrate has each target take a harness paraemeter in its nix function. In a future crate2nix PR I would like to use cargo metadata to output the correct harness parameter in the invokation of buildRustCrate.

It's still very much WIP but I think the only other piece that is missing from the serialization is bench for knowing whether by default it should be compiled in bench mode. These seem reasonable as other pieces such as test and doc are already serialized.

I hope this made some sense as a quick overview of my needs & what crate2nix & buildRustCrate as they are pretty complicated. Also thanks for the zulipchat link, I did not know about it.

@epage
Copy link
Contributor

epage commented Mar 20, 2023

Thanks for the explanation!

@epage epage changed the title Add harness to cargo metadata output Add harness field to cargo metadata output Oct 16, 2023
@qwandor
Copy link

qwandor commented Nov 15, 2023

I'm running into the same issue with cargo_embargo, a tool we're using in Android to generate Soong build files for third-party crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants