@@ -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,126 @@ 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+ #[ cargo_test]
1560+ #[ ignore = "broken, needs download_accessible fix" ]
1561+ fn proc_macro_in_artifact_dep ( ) {
1562+ // Forcing FeatureResolver to check a proc-macro for a dependency behind a
1563+ // target dependency.
1564+ if cross_compile:: disabled ( ) {
1565+ return ;
1566+ }
1567+ Package :: new ( "pm" , "1.0.0" )
1568+ . file ( "src/lib.rs" , "" )
1569+ . file (
1570+ "Cargo.toml" ,
1571+ r#"
1572+ [package]
1573+ name = "pm"
1574+ version = "1.0.0"
1575+
1576+ [lib]
1577+ proc-macro = true
1578+
1579+ "# ,
1580+ )
1581+ . publish ( ) ;
1582+ let alternate = cross_compile:: alternate ( ) ;
1583+ Package :: new ( "bin-uses-pm" , "1.0.0" )
1584+ . target_dep ( "pm" , "1.0" , alternate)
1585+ . file ( "src/main.rs" , "fn main() {}" )
1586+ . publish ( ) ;
1587+ // Simulate a network error downloading the proc-macro.
1588+ std:: fs:: remove_file ( cargo_test_support:: paths:: root ( ) . join ( "dl/pm/1.0.0/download" ) ) . unwrap ( ) ;
1589+ let p = project ( )
1590+ . file (
1591+ "Cargo.toml" ,
1592+ & format ! (
1593+ r#"
1594+ [package]
1595+ name = "foo"
1596+ version = "0.1.0"
1597+ edition = "2021"
1598+
1599+ [dependencies]
1600+ bin-uses-pm = {{ version = "1.0", artifact = "bin", target = "{alternate}"}}
1601+ "#
1602+ ) ,
1603+ )
1604+ . file ( "src/lib.rs" , "" )
1605+ . build ( ) ;
1606+
1607+ p. cargo ( "check -Z bindeps" )
1608+ . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
1609+ . with_stderr ( "" )
1610+ . run ( ) ;
1611+ }
1612+
14921613#[ cargo_test]
14931614fn allow_dep_renames_with_multiple_versions ( ) {
14941615 Package :: new ( "bar" , "1.0.0" )
@@ -2896,7 +3017,8 @@ fn check_transitive_artifact_dependency_with_different_target() {
28963017 p. cargo ( "check -Z bindeps" )
28973018 . masquerade_as_nightly_cargo ( & [ "bindeps" ] )
28983019 . with_stderr_contains (
2899- "error: failed to run `rustc` to learn about target-specific information" ,
3020+ "error: failed to determine target information for target `custom-target`.\n \
3021+ Artifact dependency `baz` in package `bar v0.0.0 [..]` requires building for `custom-target`",
29003022 )
29013023 . with_status ( 101 )
29023024 . run ( ) ;
0 commit comments