-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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: add support for renaming crates #68296
Conversation
Added @gilligan as I had a conversation about this feature with him during the week. |
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.
After a first glance it looks okay. Could you add a testcase to the buildRustCrateTests
attribute?
The tests currently pass and are even cached meaning you are really not causing any changes to "old" expressions 👍.
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.
The changes per se look good to me! It's in line with what I was also mentioning on the crates2nix repo. Thank you so much for taking the time and initiative to fix it :)
I agree with @andir that there should be some tests with this change. Maybe you can just use the same minimal example that I put in https://github.com/gilligan/rs-nix-test to verify that things are working.
With tests added i'd be happy to see this merged. Oh, and I think we should also get this into 18.09, right?
ebef37b
to
3623a41
Compare
Thanks for the comments! I have added a test case. |
3623a41
to
f056553
Compare
f056553
to
709d16e
Compare
The last two pushes were just replacing occurrences of |
Before this change, buildRustCrate always called rustc with --extern libName=[...]libName[...] However, Cargo permits using a different name under which a dependency is known to a crate. For example, rand 0.7.0 uses: [dependencies] getrandom_package = { version = "0.1.1", package = "getrandom", optional = true } Which introduces the getrandom dependency such that it is known as getrandom_package to the rand crate. In this case, the correct extern flag is of the form --extern getrandom_package=[...]getrandom[...] which is currently not supported. In order to support such cases, this change introduces a crateRenames argument to buildRustCrate. This argument is an attribute set of dependencies that should be renamed. In this case, crateRenames would be: { "getrandom" = "getrandom_package"; } The extern options are then built such that if the libName occurs as an attribute in this set, it value will be used as the local name. Otherwise libName will be used as before.
709d16e
to
85c6d72
Compare
Found and fixed a bug while preparing a PR for |
Awesome work! |
I found it do renaming only over crate names, without considering crate version. This seems to cause problem when a crate depends on multiple versions of the same named crate. a = { version = "0.1", package = "libc" }
b = { version = "0.2", package = "libc" } We cannot even provide a proper |
Good find!
So, I guess
|
Motivation for this change
Before this change,
buildRustCrate
always calledrustc
withHowever, Cargo permits using a different name under which a dependency
is known to a crate. For example, rand 0.7.0 uses:
Which introduces the
getrandom
dependency such that it is known asgetrandom_package
to the rand crate. In this case, the correctextern
flag is of the form
which is currently not supported. In order to support such cases, this
change introduces a
crateRenames
argument tobuildRustCrate
. Thisargument is an attribute set of dependencies that should be
renamed. In this case,
crateRenames
would be:The
extern
options are then built such that if thelibName
occurs asan attribute in this set, it value will be used as the local
name. Otherwise
libName
will be used as before.This change should not affect existing derivations that use
buildRustCrate
--an empty attrset is used for crateRenames when this argument is not provided,
applying the old behavior.
Please review very carefully, I have never looked at the
buildRustCrate
code before ;).
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
ping @P-E-Meunier @kolloch
cc @