Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/cargo-util-schemas/src/core/source_kind.rs
Comment thread
weihanglo marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum SourceKind {
LocalRegistry,
/// A directory-based registry.
Directory,
/// Package sources distributed with the rust toolchain
Builtin,

@adamgemmell adamgemmell Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Existing comment regarding updating package_id_spec: #16675 (comment)

I'll leave that for a future PR.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Got it. I would expect it being an immediate follow-up though as it is also related to how we encode this in lockfile, in cargo metadata output, etc. All of those may affect how we snapshot our tests. I don't mind if we have a simple encode logic first.

}

// The hash here is important for what folder packages get downloaded into.
Expand All @@ -40,6 +42,7 @@ impl SourceKind {
SourceKind::SparseRegistry => None,
SourceKind::LocalRegistry => Some("local-registry"),
SourceKind::Directory => Some("directory"),
SourceKind::Builtin => Some("builtin"),
}
}
}
Expand Down Expand Up @@ -71,6 +74,10 @@ impl Ord for SourceKind {
(_, SourceKind::Directory) => Ordering::Greater,

(SourceKind::Git(a), SourceKind::Git(b)) => a.cmp(b),
(SourceKind::Git(_), _) => Ordering::Less,
(_, SourceKind::Git(_)) => Ordering::Greater,

(SourceKind::Builtin, SourceKind::Builtin) => Ordering::Equal,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/workspace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ fn to_dependency_source_id<P: ResolveToPath + Clone>(
if kind == Some(DepKind::Build) {
bail!("builtin dependency `{name_in_toml}` cannot be used as a build dependency")
}
todo!("SourceKind::Builtin");
return SourceId::for_builtin();
}

match (
Expand Down
13 changes: 13 additions & 0 deletions src/workspace/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl SourceId {
let url = url.into_url()?;
SourceId::new(SourceKind::Path, url, None)
}
"builtin" => SourceId::for_builtin(),
kind => Err(anyhow::format_err!("unsupported source protocol: {}", kind)),
}
}
Expand Down Expand Up @@ -204,6 +205,12 @@ impl SourceId {
SourceId::new(SourceKind::Path, url, None)
}

/// Creates a `SourceId` for the builtin packages in the configured toolchain.
pub fn for_builtin() -> CargoResult<SourceId> {
let url = "builtin://".into_url()?;

@weihanglo weihanglo Sep 25, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is probably good to move on. Just note that this affects other serialized output (lockfile and cargo metadata and probably others) and we might want to revisit this. For example,

  • Should we encode version?
    • Doing it might make lockfile less portable.
    • Not doing it mean we can not know for sure which std a lockfile use at creation time (or does it matter?)
  • Do we care about libcargo user that may have two different of builtin source?

View changes since the review

SourceId::new(SourceKind::Builtin, url, None)
}

/// Creates a `SourceId` from a filesystem path.
///
/// `path`: an absolute path.
Expand Down Expand Up @@ -404,6 +411,7 @@ impl SourceId {
}
Ok(Box::new(PathSource::new(&path, self, gctx)))
}
SourceKind::Builtin => todo!("builtin source"),
SourceKind::Registry | SourceKind::SparseRegistry => {
Ok(Box::new(RegistrySource::remote(self, gctx)?))
}
Expand Down Expand Up @@ -664,6 +672,7 @@ impl fmt::Display for SourceId {
Ok(())
}
SourceKind::Path => write!(f, "{}", url_display(&self.inner.url)),
SourceKind::Builtin => write!(f, "builtin {}", url_display(&self.inner.url)),
SourceKind::Registry | SourceKind::SparseRegistry => {
write!(f, "registry `{}`", self.display_registry_name())
}
Expand Down Expand Up @@ -846,6 +855,10 @@ mod tests {
assert_data_eq!(gen_hash(source_id), str!["473480029881867801"].raw());
assert_data_eq!(short_hash(&source_id), str!["199e591d94239206"].raw());

let source_id = SourceId::for_builtin().unwrap();
assert_data_eq!(gen_hash(source_id), str!["8471877086995577839"].raw());
assert_data_eq!(short_hash(&source_id), str!["ef7b241f53279275"].raw());

let path = &ws_root.join("crate");
let source_id = SourceId::for_local_registry(path).unwrap();
#[cfg(not(windows))]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/builtin_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn builtin_dep_accepted() {
.with_stderr_data(str![[r#"

thread [..] panicked at [..]
not yet implemented: SourceKind::Builtin
not yet implemented: builtin source
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace

"#]])
Expand Down
Loading