@@ -1458,6 +1458,7 @@ fn targets_are_picked_up_from_non_workspace_artifact_deps() {
14581458
14591459 let mut dep = registry:: Dependency :: new ( "artifact" , "1.0.0" ) ;
14601460 Package :: new ( "uses-artifact" , "1.0.0" )
1461+ . schema_version ( 3 )
14611462 . file (
14621463 "src/lib.rs" ,
14631464 r#"pub fn uses_artifact() { let _b = include_bytes!(env!("CARGO_BIN_FILE_ARTIFACT")); }"# ,
@@ -1489,6 +1490,127 @@ fn targets_are_picked_up_from_non_workspace_artifact_deps() {
14891490 . run ( ) ;
14901491}
14911492
1493+ #[ cargo_test]
1494+ fn index_version_filtering ( ) {
1495+ if cross_compile:: disabled ( ) {
1496+ return ;
1497+ }
1498+ let target = cross_compile:: alternate ( ) ;
1499+
1500+ Package :: new ( "artifact" , "1.0.0" )
1501+ . file ( "src/main.rs" , r#"fn main() {}"# )
1502+ . file ( "src/lib.rs" , r#"pub fn lib() {}"# )
1503+ . publish ( ) ;
1504+
1505+ let mut dep = registry:: Dependency :: new ( "artifact" , "1.0.0" ) ;
1506+
1507+ Package :: new ( "bar" , "1.0.0" ) . publish ( ) ;
1508+ Package :: new ( "bar" , "1.0.1" )
1509+ . schema_version ( 3 )
1510+ . add_dep ( dep. artifact ( "bin" , Some ( target. to_string ( ) ) ) )
1511+ . publish ( ) ;
1512+
1513+ // Verify that without `-Zbindeps` that it does not use 1.0.1.
1514+ let p = project ( )
1515+ . file (
1516+ "Cargo.toml" ,
1517+ r#"
1518+ [package]
1519+ name = "foo"
1520+ version = "0.1.0"
1521+
1522+ [dependencies]
1523+ bar = "1.0"
1524+ "# ,
1525+ )
1526+ . file ( "src/lib.rs" , "" )
1527+ . build ( ) ;
1528+
1529+ p. cargo ( "tree" )
1530+ . with_stdout ( "foo v0.1.0 [..]\n └── bar v1.0.0" )
1531+ . run ( ) ;
1532+
1533+ // And with -Zbindeps it can use 1.0.1.
1534+ p. cargo ( "update -Zbindeps" )
1535+ . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
1536+ . with_stderr (
1537+ "\
1538+ [UPDATING] [..]
1539+ [ADDING] artifact v1.0.0
1540+ [UPDATING] bar v1.0.0 -> v1.0.1" ,
1541+ )
1542+ . run ( ) ;
1543+
1544+ // And without -Zbindeps, now that 1.0.1 is in Cargo.lock, it should fail.
1545+ p. cargo ( "check" )
1546+ . with_status ( 101 )
1547+ . with_stderr (
1548+ "\
1549+ [UPDATING] [..]
1550+ error: failed to select a version for the requirement `bar = \" ^1.0\" ` (locked to 1.0.1)
1551+ candidate versions found which didn't match: 1.0.0
1552+ location searched: [..]
1553+ required by package `foo v0.1.0 [..]`
1554+ perhaps a crate was updated and forgotten to be re-vendored?" ,
1555+ )
1556+ . run ( ) ;
1557+ }
1558+
1559+ // FIXME: `download_accessible` should work properly for artifact dependencies
1560+ #[ cargo_test]
1561+ #[ ignore = "broken, needs download_accessible fix" ]
1562+ fn proc_macro_in_artifact_dep ( ) {
1563+ // Forcing FeatureResolver to check a proc-macro for a dependency behind a
1564+ // target dependency.
1565+ if cross_compile:: disabled ( ) {
1566+ return ;
1567+ }
1568+ Package :: new ( "pm" , "1.0.0" )
1569+ . file ( "src/lib.rs" , "" )
1570+ . file (
1571+ "Cargo.toml" ,
1572+ r#"
1573+ [package]
1574+ name = "pm"
1575+ version = "1.0.0"
1576+
1577+ [lib]
1578+ proc-macro = true
1579+
1580+ "# ,
1581+ )
1582+ . publish ( ) ;
1583+ let alternate = cross_compile:: alternate ( ) ;
1584+ Package :: new ( "bin-uses-pm" , "1.0.0" )
1585+ . target_dep ( "pm" , "1.0" , alternate)
1586+ . file ( "src/main.rs" , "fn main() {}" )
1587+ . publish ( ) ;
1588+ // Simulate a network error downloading the proc-macro.
1589+ std:: fs:: remove_file ( cargo_test_support:: paths:: root ( ) . join ( "dl/pm/1.0.0/download" ) ) . unwrap ( ) ;
1590+ let p = project ( )
1591+ . file (
1592+ "Cargo.toml" ,
1593+ & format ! (
1594+ r#"
1595+ [package]
1596+ name = "foo"
1597+ version = "0.1.0"
1598+ edition = "2021"
1599+
1600+ [dependencies]
1601+ bin-uses-pm = {{ version = "1.0", artifact = "bin", target = "{alternate}"}}
1602+ "#
1603+ ) ,
1604+ )
1605+ . file ( "src/lib.rs" , "" )
1606+ . build ( ) ;
1607+
1608+ p. cargo ( "check -Z bindeps" )
1609+ . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
1610+ . with_stderr ( "" )
1611+ . run ( ) ;
1612+ }
1613+
14921614#[ cargo_test]
14931615fn allow_dep_renames_with_multiple_versions ( ) {
14941616 Package :: new ( "bar" , "1.0.0" )
@@ -2896,7 +3018,8 @@ fn check_transitive_artifact_dependency_with_different_target() {
28963018 p. cargo ( "check -Z bindeps" )
28973019 . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
28983020 . with_stderr_contains (
2899- "error: failed to run `rustc` to learn about target-specific information" ,
3021+ "error: failed to determine target information for target `custom-target`.\n \
3022+ Artifact dependency `baz` in package `bar v0.0.0 [..]` requires building for `custom-target`",
29003023 )
29013024 . with_status ( 101 )
29023025 . run ( ) ;
0 commit comments