-
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
Support dependencies from registries for artifact dependencies, take 2 #12421
Conversation
0c0e79c
to
5be6864
Compare
☔ The latest upstream changes (presumably #12426) made this pull request unmergeable. Please resolve the merge conflicts. |
5be6864
to
f55f4c5
Compare
@fee1-dead Just wanted to check in and acknowledge that I have seen this PR, but I haven't had the time to look at it. I will try to get to it soon. |
src/cargo/sources/registry/index.rs
Outdated
@@ -178,7 +178,7 @@ struct Summaries { | |||
/// A lazily parsed [`IndexSummary`]. | |||
enum MaybeIndexSummary { | |||
/// A summary which has not been parsed, The `start` and `end` are pointers | |||
/// into [`Summaries::raw_data`] which this is an entry of. | |||
/// into [`Summaries::raw_data`] which this isRegistryDependency an entry of. |
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 like a stray edit?
/// into [`Summaries::raw_data`] which this isRegistryDependency an entry of. | |
/// into [`Summaries::raw_data`] which this is an entry of. |
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.
fixed
#[cargo_test] | ||
#[ignore = "broken, need artifact info in index"] |
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.
In targets_are_picked_up_from_non_workspace_artifact_deps
, in the part that says Package::new("uses-artifact", "1.0.0")
, can you add .schema_version(3)
to make sure the index filtering is working correctly?
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
// and per-pkg-targets are not immediately known. | ||
let mut activate_target = |target| { | ||
self.target_data | ||
.merge_compile_kind(CompileKind::Target(target)) |
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.
If this fails, it seems to generate a confusing error. See check_transitive_artifact_dependency_with_different_target
. I think what would help is to add .with_context(|| format!("..."))
with a message that says something like "failed to determine target information for target {target} for artifact dependency {name} in package {pkg_id}".
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.
Done.
tests/testsuite/artifact_dep.rs
Outdated
@@ -2894,8 +2896,7 @@ fn check_transitive_artifact_dependency_with_different_target() { | |||
p.cargo("check -Z bindeps") | |||
.masquerade_as_nightly_cargo(&["bindeps"]) | |||
.with_stderr_contains( | |||
"error: could not find specification for target `custom-target`.\n \ | |||
Dependency `baz v0.0.0 [..]` requires to build for target `custom-target`.", | |||
"error: failed to run `rustc` to learn about target-specific information", |
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 error message seems pretty vague. I added a comment above to enhance in activate_target
.
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.
Fixed
src/cargo/sources/registry/index.rs
Outdated
@@ -807,7 +815,7 @@ impl<'a> SummariesCache<'a> { | |||
.get(..4) | |||
.ok_or_else(|| anyhow::anyhow!("cache expected 4 bytes for index schema version"))?; | |||
let index_v = u32::from_le_bytes(index_v_bytes.try_into().unwrap()); | |||
if index_v != INDEX_V_MAX { | |||
if index_v != INDEX_V_MAX && index_v != 3 { |
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.
Can you say more about why this check was added? It doesn't look like v3 is being written in SummariesCache::serialize
anyway, so it is always 2.
I'm thinking this isn't necessary (yet), because older cargos don't fail to parse the new entries. The key part of this index check is IndexSummary::parse
. If we make a change that causes that to fail, then older cargos will ignore those entries, and not place them in the cache (it assumes they are from a future format it does not understand). However, since bindeps is just adding new fields to the JSON, that doesn't cause a problem (new fields are ignored).
When we stabilize, I think we'll need to set INDEX_V_MAX to 3, but I'm not sure it is necessary to make any changes at this time.
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 this was simply carried over from the last PR. I don't remember my reasoning for this and I have removed this condition.
Thanks, this looks great! Can you add a test to make sure the Package::new("bar", "1.0.0").publish();
Package::new("bar", "1.0.1")
.schema_version(3)
.add_dep(dep.artifact("bin", Some(target.to_string())))
.publish();
// Verify that without `-Zbindeps` that it does not use 1.0.1.
let p = project()
.file("Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependency]
bar = "1.0"
"#)
.file("src/lib.rs", "")
.build();
p.cargo("tree").with_stdout("...").run();
// And with -Zbindeps it can use 1.0.1.
p.cargo("update -Zbindeps").with_stderr("...").run();
// And without -Zbindeps, now that 1.0.1 is in Cargo.lock, it should fail.
p.cargo("check").with_status(101).with_stderr("...").run(); I think that should roughly cover it, but if you have other ideas on how to try to break it, I think it would be good to make sure that has plenty of coverage. I noticed that this doesn't update Related to #[cargo_test]
fn proc_macro_in_artifact_dep() {
// Forcing FeatureResolver to check a proc-macro for a dependency behind a
// target dependency.
if cross_compile::disabled() {
return;
}
Package::new("pm", "1.0.0")
.file("src/lib.rs", "")
.file(
"Cargo.toml",
r#"
[package]
name = "pm"
version = "1.0.0"
[lib]
proc-macro = true
"#,
)
.publish();
let alternate = cross_compile::alternate();
Package::new("bin-uses-pm", "1.0.0")
.target_dep("pm", "1.0", alternate)
.file("src/main.rs", "fn main() {}")
.publish();
// Simulate a network error downloading the proc-macro.
std::fs::remove_file(cargo_test_support::paths::root().join("dl/pm/1.0.0/download")).unwrap();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
bin-uses-pm = {{ version = "1.0", artifact = "bin", target = "{alternate}"}}
"#
),
)
.file("src/lib.rs", "")
.build();
p.cargo("check -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr("")
.run();
} Can you make sure to document |
df276af
to
17b106b
Compare
added
Yeah, let's iterate on this later, I specifically did not look into updating
Yep, done. |
not sure why check-version-bump is failing for |
17b106b
to
b90af3d
Compare
☔ The latest upstream changes (presumably #12381) made this pull request unmergeable. Please resolve the merge conflicts. |
I think there was an issue that was since fixed (#12508). |
Thanks, looks good! I appreciate you working on this. I filed #12554 for the download_accessible issue, and #12555 to track updating crates.io (though I'm not sure when we should actually do that). Can you resolve the merge conflict? Unfortunately it looks like I don't have permission to push to your branch. |
b90af3d
to
43dccc7
Compare
Thanks! @bors r+ |
☀️ Test successful - checks-actions |
Update cargo 13 commits in 2cc50bc0b63ad20da193e002ba11d391af0104b7..925280f028db3a322935e040719a0754703947cf 2023-08-22 22:43:08 +0000 to 2023-08-25 21:16:44 +0000 - string leek is stable (rust-lang/cargo#12559) - refactor: Pull out cargo-add MSRV code for reuse (rust-lang/cargo#12553) - Contrib: Add process for security responses. (rust-lang/cargo#12487) - Support dependencies from registries for artifact dependencies, take 2 (rust-lang/cargo#12421) - fix(toml): Improve parse errors (rust-lang/cargo#12556) - Create dedicated unstable flag for asymmetric-token (rust-lang/cargo#12551) - chore(deps): update latest msrv to v1.72.0 (rust-lang/cargo#12549) - changelog: add link to CVE-2023-40030 (rust-lang/cargo#12550) - refactor(install): Move value parsing to clap (rust-lang/cargo#12547) - fix: Set MSRV for internal packages (rust-lang/cargo#12381) - doc: fix two links to tracing docs (rust-lang/cargo#12537) - use AND search when having multiple terms (rust-lang/cargo#12548) - fix(log): Use a more compact relative-time format (rust-lang/cargo#12542) r? ghost
@ehuss Working on a fix for this test right now. Is this an example of a spurious network error, for which the desired behaviour that it retries? |
@elchukc Sorry, I'm not quite understanding your question. There is a test (already checked in) called |
This is a continuation of #12062, and closes #10405.
r? @ehuss
Here are things this PR changes:
RustcTargetData
mutable for the feature resolver. This is so that we can query rustc for target info as late as resolving features, as that is when we really know if a package is really going to be used.