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
buildRustCrate: only link build deps into build script #82404
Conversation
@GrahamcOfBorg build buildRustCrateTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good and makes sense (if the cargo docs are correct).
Could you add a test the buildRustCrates
that tests this?
Example setup:
Have a dependency A that is used in both the build script and in the actual build (e.g. a simple binary). Then have a version A1 and A2 that differ in some constant they export. Assert for the constant of A1 in build build.rs
file (during build time) and assert for the constant of A2 in the main.rs
(during run-time).
I also have some recollection of an issue where those dependencies were not exactly separated as described in the docs. In any case we should follow the upstream docs and fix downstream users if those fail after this change - if this is in fact correct behavior.
I will try to run this through some tests on a personal collection of crates to see where my recollection of issues comes from. Other then that (and the missing test ;)) this looks really good. Thank you! 👍
a4c8c69
to
58ebcbf
Compare
Thanks for the feedback! I have added a test. Did you means something like this? Or really a single dependent create with feature gating for the constant. |
@GrahamcOfBorg build buildRustCrateTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works on some of my personal projects.
Do you by chance have motivation to add a few more comments in the code paths you touched? It wasn't great so far but I am trying to gradually increase the coverage of comments. At least some notes about what is happening there. The term link
is used very often and to people new to the code base this is probably a bit confusing.
No problem, I'll try to add some comments tonight! |
58ebcbf
to
5ee122f
Compare
I have added some comments to the affected parts. I hope they are clear and helpful. |
5ee122f
to
87381ad
Compare
if [[ -e target/link.build ]]; then | ||
sort -u target/link.build > target/link.build.sorted | ||
mv target/link.build.sorted target/link.build | ||
tr '\n' ' ' < target/link.build > target/link.build_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I don't like about this is that we are using the underscored (e.g. build_
) file name more often now. IMO that should only be used temporarily because of the invocation of sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it's pretty pointless here, even more because link.build
is only use in this phase. I have removed tr
completely here and replaced
EXTRA_BUILD_FLAGS="$EXTRA_BUILD_FLAGS $(cat target/link.build)"
by
EXTRA_BUILD_FLAGS="$EXTRA_BUILD_FLAGS $(tr '\n' ' ' < target/link.build)"
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll tack on another commit, because the temporary files are not necessary at all. It seems that GNU sort support in-place sorts. From the info page:
Write output to output-file instead of standard output. Normally, sort reads all input before opening output-file, so you can sort a file in place by using commands like sort -o F F and cat F | sort -o F.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another commit which sort the linking options in-place. I'll remove it if you don't like it ;).
Thanks! Comments look fine. I had two more minor remarks. |
87381ad
to
0067c79
Compare
According to the Cargo documentation: > The build script does not have access to the dependencies listed in > the dependencies or dev-dependencies section (they’re not built > yet!). Also, build dependencies are not available to the package > itself unless also explicitly added in the [dependencies] table. https://doc.rust-lang.org/cargo/reference/build-scripts.html This change separates linkage of regular dependencies and build dependencies.
0067c79
to
ea6e048
Compare
@GrahamcOfBorg build buildRustCrateTests |
Motivation for this change
According to the Cargo documentation:
https://doc.rust-lang.org/cargo/reference/build-scripts.html
This change separates linkage of regular dependencies and build
dependencies.
Tested with
buildRustCrateTests
and some personal crates.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)