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

Build kinds support #285

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

jordanisaacs
Copy link
Contributor

@jordanisaacs jordanisaacs commented Mar 20, 2023

Add build kind support (relying on NixOS/nixpkgs#221440). Uses a new parameter buildKinds, same as the new buildRustCrate parameter. All dependencies will only build lib.

A breaking change is the removal of the runTests option. It is now a tools function, crateWithTest that handles the buildKinds for your when you call it. This is so you can override the testCrate derivation with your own version (eg if you only want to two derivations: one with tests + examples + benches, and then the final one).

TODO:

  1. Merge new cargo metadata and utilize it in codegen: Add harness field to cargo metadata output rust-lang/cargo#11846
  2. Figure out dev dependencies & building the library (see below comment)

Closes: #284 #145

@jordanisaacs
Copy link
Contributor Author

Passes all the crate2nix tests!

@jordanisaacs
Copy link
Contributor Author

Been playing around with this in a project of mine and it works great. The one issue I see which I am not sure the best way to fix (whether in buildRustCrate or crate2nix) is the ergonomics of dev dependencies.

Tests/examples/benches that are not the library test, rely on the library itself as a dependency. This is not reflected in the dependency list generated by crate2nix. You can get around this by adding lib to the build kinds, BUT then the library gets built with the dev dependencies. Open to suggestions.

kind: target
.kind
.first()
.context("Target shouuld have kind")?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.context("Target shouuld have kind")?
.context("Target should have kind")?

Comment on lines +111 to +113
# TODO (when cargo merges metadata):
# harness
# bench
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR rust-lang/cargo#11847 got closed due to inactivity. Do you still intend to resume this?

@@ -48,15 +48,15 @@
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

@flokli
Copy link
Contributor

flokli commented Dec 11, 2023

@jordanisaacs did you keep tinkering with this? We'd like to build benchmarks with crate2nix for Tvix, so I'm curious to see if I can help out somehow.

@jordanisaacs
Copy link
Contributor Author

@flokli It was a pretty big change that needs changes in three projects (crate2nix, cargo, and nixpkgs) and it didn't get any reviews so stopped pushing it forward. I would love to see this stuff get merged though.

I see the way forward being getting the nixpkgs PR merged first. That needs reviewers which you could help with. Then we can revisit crate2nix and what we need merged into cargo (e.g. what metadata do we need).

@jordanisaacs
Copy link
Contributor Author

I do need to rebase the nixpkgs commit though. Will try and do it sometime this week.

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.

Support for build kinds (examples, benches, etc.)
2 participants