-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Expose build.target .cargo/config setting as packages.target in Cargo.toml #9030
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
As this PR currently appears to work (for my test repository), I'd like to ask for a first round of review before polishing up all the details that are sure to be problematic. What do you think about this? As this is my first cargo contribution, maybe there is some obvious place I forgot changing, and I should be doing this before even thinking of adding tests and polishing things up? Also, should I (and if yes is there an example somewhere in the code of how) hide this new option behind an unstable gate? If things look good enough, I'll be glad to poke around the cargo test framework and try adding tests, and to look for what documentation might need updating. (BTW, there are already failing CI tests that appear to be unrelated to my changes, like this one, I'm not sure whether I'm expected to drive-by fix them or not) |
With the holidays in the US we are not paying as much attention as we normally do. For example the unrelated CI failing are something to do with Nightly, and normally there would be a preity prompt PR fixing it (or turning off Nightly testing) that you could rebase onto. Thank you for your contribution and patients. Tests and documentation would be appreciated. I for one find it a good place to start finding out "what are you trying to do" as a start of a code review. |
Thank you for your feedback! I have just fixed an issue I noticed while using a patched cargo, and rebased to a master that hopefully has CI fixed. I also added the documentation, that hopefully should help understanding what this diff is about. I haven't added tests yet, though, as I'd like to confirm that at least the idea of the change is legit. The irlo thread listed in the top post, AFAIU, says that this setting should be made available, but I'm not sure that eg. Does this sound reasonable enough? And what do you think about the documented changes, that I hopefully implemented not too awfully here? Cheers! |
Another thought I just came up with: should |
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.
Thanks for the PR! I think it may make sense to land a few of the refactorings in the backend (e.g. storing a list of kinds in the BuildContext
) ahead of time before this PR if you'd like.
Otherwise I think it'd be good too add some tests here. Additionally I'm not entirely sure what the final design will be for target
and how it interacts with --target
, but I added some comments below on that.
let all_kinds = requested_kinds | ||
.iter() | ||
.copied() | ||
.chain(ws.members().flat_map(|p| p.manifest().kind().into_iter())); |
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 think that this will need to iterate over the entire crate graph instead of just ws.members()
to find requested targets?
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've tried thinking about this, but it looks to me like RustcTargetData
does not already have information enough to actually list the entire crate graph, and this only happens in BuildContext
which gets called after that? And as RustcTargetData
also gets used from eg. cargo fetch
, which AFAIU does itself not have enough information to iterate over the entire crate graph — and it is indeed using the kind data in RustcTargetData
.
Now, seeing as the structures filled here are AFAIU just caches, it'd be very possible to just fill them in on-demand instead, which should solve the issue. Would that sound good to you?
I think I have noticed another issue of this PR as is, though I still have to actually check it: feature resolution happens only once, and so if a crate is depended on with a different set of features by Fixing this would require changing the feature resolution algorithm, which I expect would be quite a bit more invasive. How do you think we should go? First land the “basic” stuff and then work towards fixing feature resolution while keeping the flag gated? Or finish work on getting the feature resolution first, and only then land it all at once, at the expense of this ending up being a (much?) bigger PR? |
Uh well, I posted that message faster than I wanted to, sorry for the notification noise. So I also wanted to say, I've addressed a few of the comments, and replied to a few other comments. Split the refactoring towards #9046, and merged that branch here so it still works (hope git won't merge conflict me at the end, it's the first time I work in a “please don't rebase” scenario, usually I'd have just squash-rebased on top of that other branch) Note to self about things still remaining:
|
Small refactor, adding a list of all kinds to BuildContext Involved in #9030 cc `@alexcrichton`
(Note: I've just rebased on top of master now that #9046 landed) |
Ok, so with this latest commit I have I think solved all the issues that have been raised, except:
|
@alexcrichton Could you give another look at this PR? I think I handled your last comments, so hopefully it should be ready to go :) (and sorry for myself taking so long to fix the last comments!) |
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.
Oops sorry this fell under my radar! I've lost a bit of context since I last looked at this, but as-is this looks good to me. I suspect there's at least one or two things that will need to be handled later on, but for now this seems fine. Want to go ahead and file a tracking issue and fill that in in the unstable documentation? With some small updates below I think this should be good to merge.
src/cargo/util/toml/mod.rs
Outdated
.default_target | ||
.as_ref() | ||
.map(|t| CompileTarget::new(&*t)) | ||
.transpose()? // TODO: anyhow::Context isn't imported yet so I guess .context() isn't the right way to do it? |
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 think it's safe to remove this TODO
?
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.
Hmm, it's true that I had totally forgotten about this TODO, sorry! It was there because I was thinking that there may be a want to add details to the error message, but I have basically no knowledge of the cargo error handling story yet.
I've removed this TODO for now, feel free to let me know if you think there should be an equivalent to .context()
here to give a hint to the user that the issue comes from a mis-spelled default_target
(if I understood correctly the error conditions of CompileTarget::new
) :)
Thank you for your feedback! And no problem about this falling under your radar, it fell under mine for a long time before that 😅 The review comments should have been handled, I rebased and fixed a compile error that appeared since the previous rebase, CI passed, and I opened #9406 for the tracking issue. I'm just not clear about the unstable documentation, as AFAIU the rust unstable book is only for rustc and this PR already has changes to something that may be the unstable documentation? |
Ok thanks! This looks good to me so I'll approve @bors: r+ For the tracking issue I'll fill in some details. |
📌 Commit fcd7617 has been approved by |
☀️ Test successful - checks-actions |
Update cargo 5 commits in 0ed318d182e465cd66071b91ac3d265af63ef8a1..4369396ce7d270972955d876eaa4954bea56bcd9 2021-04-23 20:54:54 +0000 to 2021-04-27 14:35:53 +0000 - Fix rebuild issues with rustdoc. (rust-lang/cargo#9419) - Always use full metadata hash for -C metadata. (rust-lang/cargo#9418) - Expose build.target .cargo/config setting as packages.target in Cargo.toml (rust-lang/cargo#9030) - Some changes to rustdoc fingerprint checking. (rust-lang/cargo#9404) - Document that CARGO_PKG_ are availble to build.rs (rust-lang/cargo#9405)
Looks like this landed without issues. Awesome, thank you! ❤️ |
How can I use this? |
Can someone please explain how to use this feature? I can't find any documentation |
Normally you can find the documentation of an unstable feature from "Unstable Features" chapter in The Cargo Book. The usage is documented there as well. For more usages, you may also want to take a look at how cargo tests this feature, or keep an eye on the tracking issue to see how people use it. |
Hey!
I'm trying to do my first cargo contribution by implementing per-crate target settings as per the irlo thread ; and I think I have a draft that looks good-ish (the root units returned by
generate_targets
have the right kinds set).Closes #7004
Edit: the below problem description is now solved in the latest version of this PR, please ignore
But for some reason running on a test project now blocks on
Blocking waiting for file lock on build directory
and I have literally no idea how my changes could trigger this… would anyone have an idea of how the changes could lead to infinitely blocking there? (I already tried cargo clean just in case and it didn't appear to help)FWIW, the output that looks hopeful to me is, on my testbed workspace:
(where both
yuubind-config
andyuubind-config-example
are being configured to bewasm32-unknown-unknown
and the other ones stay as host).Interestingly enough, if I remove the
target
setting fromyuubind-config
(and leave it onyuubind-config-example
) then it does no longer block on waiting for file lock on build directory, even though it does not actually compile withwasm32-unknown-unknown
. And it does appear to correctly build yuubind-config-example as wasm32.My investigation shows that it appears to happen iff there is a package with
package.target
being set that has dependencies.This most likely is a bug in my code (eg. I build only the root units and not the whole unit graph maybe?), and am going to keep investigating it as such, but maybe someone would already know how dependency resolution could interact with build lock acquisition and give me hints?
Anyway, thank you all for all you do cargo!