Repository navigation
feat(builtin-dep): Add Builtin Source - #17567
adamgemmell wants to merge 3 commits into
Conversation
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| /// The unique identifier for this source | ||
| source_id: SourceId, | ||
| /// The underlying path source which discovers packages | ||
| path_source: RecursivePathSource<'gctx>, |
There was a problem hiding this comment.
The decision to discover real packages here is an interesting one. I'm not sure it's technically necessary, but it certainly feels safer than creating synthetic Packages and Summarys especially for some unstable features like depending on crates other than core, alloc and std.
The build-std RFC intends to make the rust-src component mandatory, allowing us to do this, but this is an unresolved question.
| Ok(Box::new(PathSource::new(&path, self, gctx))) | ||
| } | ||
| SourceKind::Builtin => todo!("builtin source"), | ||
| SourceKind::Builtin => Ok(Box::new(BuiltinSource::new(self, gctx)?)), |
There was a problem hiding this comment.
Existing comment from @epage regarding which source to use: #16675 (comment)
Since that comment I've moved to using a separate Builtin source which wraps a RecursivePathSouce.
4f5ae38 to
bd71c32
Compare
| impl<'gctx> BuiltinSource<'gctx> { | ||
| pub fn new(source_id: SourceId, gctx: &'gctx GlobalContext) -> CargoResult<Self> { | ||
| let target_data = RustcTargetData::new(gctx, None, &[CompileKind::Host])?; | ||
| let path = detect_sysroot_src_path(&target_data)?; |
There was a problem hiding this comment.
This seems overkill for users of builtin-deps without build-std and not needed for this patch series until we get to the build-std part.
There was a problem hiding this comment.
It's not technically needed even with build-std, though I suspect it will improve error messages when doing some things intended to be unstable like depending on unstable crates or enabling features.
The main reason I went down this route is that there's several fields which don't have sensible values and which could cause issues in the future or for users of Cargo as a library. For example, there's no valid value for the path to the manifest, and emitting an empty feature map would cause the resolver to fail on enabling features unless we hardcode it to work around that.
This design performs worse, but I feel it's significantly simpler to work with.
There was a problem hiding this comment.
To be clear, I'm happy going either way if you think returning synthetic packages is worth the complexity tradeoff. If we have to lie about anything significant, like the manifest path, I can rework Package and Summary fields make it an Option, and direct users to look at the unit graph instead when the value is None.
We would also have to be comfortable with crate metadata (authors etc) possibly being different to the real package.
Another thing to be aware of with this patch in it's current state is that resolving builtin dependencies would rely on rust-src which would cause disruption for users who aren't using rustup and wouldn't have that component installed by default when we make it so.
There was a problem hiding this comment.
Small bump on this. Would you be ok with going this approach for now? I'll add a note to the tracking issue to revisit this when more features are implemented so we have more of an idea of what may break.
There was a problem hiding this comment.
I would recommend we start with synthetic and then adapt as needed.
There was a problem hiding this comment.
I had missed that it would be a default component. I think there is a minimal profile that it wouldn't then be a part of? I think CI tends to run with minimal. Personally, I don't think it should be in minimal nor required for cargo operation.
There was a problem hiding this comment.
Yeah, looks like the github runners install the minimal profile. Lets try to avoid it until necessary then.
There was a problem hiding this comment.
Discussed in #t-cargo > built-in deps and `cargo metadata` @ 💬.
Should we go synthetic for now?
There was a problem hiding this comment.
I've mostly got a synthetic in-memory version of the patch working but it might need some refactoring. An alternative I've explored but also not got quite working yet is to have the source create dummy packages on demand in the .cargo/ directory in the shape that we want. It should mean a lot less internal changes to Cargo and we wouldn't need to change anything for cargo metadata either. At the moment I'm exploring both so we can compare them.
There was a problem hiding this comment.
I've pushed a WIP solution to in-memory-only packages to this branch, handled in cb9cef2. There's a lot of expect()s when Cargo needs a package to exist on the filesystem. Usually this happens when creating a Unit, but some pathways need a path earlier. Going forward I think I'd use an alternative type to Package to model the optional manifest path, and then convert that into a real Package when needed which would throw a hard error. I'm not sure how messy that would be given how much shared functionality the types would have.
I also opened adamgemmell#2 which caches builtin stubs on the filesystem that manifest_path (and cargo manifest) can refer to. Under this model, all packages with a "builtin" source_id() would be stub packages not intended to be built. I'd expect the performance cost to this to be small given that the cache doesn't need to be read to generate Summaries, and usually specifying a dependency results in a package being parsed from the filesystem anyway. There'd be a lot less churn
Could you please let me know which of these routes you think you'd prefer?
bd71c32 to
7b77571
Compare
7b77571 to
26eeb65
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
What does this PR try to resolve?
As part of #16960 this PR adds the Builtin source which is capable of satisfying dependencies on builtin packages. It does this by reading the
rust-srccomponent with aRecursivePathSource, returning any packages found with theSourceIdit is constructed with.This PR does not implement opaque dependencies, and as such trying to resolve builtin dependencies other than
corewill fail as they will depend onrustc-std-workspace-*crates which will not be patched according to the patches in the library workspace's manifest. Not attempting to resolve the transitive dependencies of builtin dependencies is what I intend to be the immediate follow up to this.This PR depends on #17566.
How to test and review this PR?
The visible changes are shown by updating tests.