File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,15 @@ fn clean_lib(
215215    // A plugin requires exporting plugin_registrar so a crate cannot be 
216216    // both at once. 
217217    let  crate_types = match  ( lib. crate_types ( ) ,  lib. plugin ,  lib. proc_macro ( ) )  { 
218+         ( Some ( kinds) ,  _,  _) 
219+             if  kinds. contains ( & CrateType :: Dylib . as_str ( ) . to_owned ( ) ) 
220+                 && kinds. contains ( & CrateType :: Cdylib . as_str ( ) . to_owned ( ) )  =>
221+         { 
222+             anyhow:: bail!( format!( 
223+                 "library `{}` cannot set the crate type of both `dylib` and `cdylib`" , 
224+                 lib. name( ) 
225+             ) ) ; 
226+         } 
218227        ( Some ( kinds) ,  _,  _)  if  kinds. contains ( & "proc-macro" . to_string ( ) )  => { 
219228            if  let  Some ( true )  = lib. plugin  { 
220229                // This is a warning to retain backwards compatibility. 
Original file line number Diff line number Diff line change @@ -1633,6 +1633,39 @@ fn many_crate_types_correct() {
16331633    assert ! ( p. root( ) . join( "target/debug" ) . join( & fname) . is_file( ) ) ; 
16341634} 
16351635
1636+ #[ cargo_test]  
1637+ fn  set_both_dylib_and_cdylib_crate_types ( )  { 
1638+     let  p = project ( ) 
1639+         . file ( 
1640+             "Cargo.toml" , 
1641+             r#" 
1642+                 [project] 
1643+ 
1644+                 name = "foo" 
1645+                 version = "0.5.0" 
1646+ 1647+ 
1648+                 [lib] 
1649+ 
1650+                 name = "foo" 
1651+                 crate_type = ["cdylib", "dylib"] 
1652+             "# , 
1653+         ) 
1654+         . file ( "src/lib.rs" ,  "pub fn foo() {}" ) 
1655+         . build ( ) ; 
1656+     p. cargo ( "build" ) 
1657+         . with_status ( 101 ) 
1658+         . with_stderr ( 
1659+             "\  
1660+  error: failed to parse manifest at `[..]`
1661+ 
1662+ Caused by: 
1663+   library `foo` cannot set the crate type of both `dylib` and `cdylib` 
1664+ " , 
1665+         ) 
1666+         . run ( ) ; 
1667+ } 
1668+ 
16361669#[ cargo_test]  
16371670fn  self_dependency ( )  { 
16381671    let  p = project ( ) 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments