@@ -838,12 +838,12 @@ pub fn run_cargo(
838838 let mut deps = Vec :: new ( ) ;
839839 let mut toplevel = Vec :: new ( ) ;
840840 let ok = stream_cargo ( builder, cargo, tail_args, & mut |msg| {
841- let ( filenames, crate_types) = match msg {
841+ let ( filenames, crate_types, kind , name ) = match msg {
842842 CargoMessage :: CompilerArtifact {
843843 filenames,
844- target : CargoTarget { crate_types } ,
844+ target : CargoTarget { crate_types, kind , name } ,
845845 ..
846- } => ( filenames, crate_types) ,
846+ } => ( filenames, crate_types, kind , name ) ,
847847 _ => return ,
848848 } ;
849849 for filename in filenames {
@@ -859,13 +859,25 @@ pub fn run_cargo(
859859
860860 let filename = Path :: new ( & * filename) ;
861861
862- // If this was an output file in the "host dir" we don't actually
863- // worry about it, it's not relevant for us
862+ // If this was an output file in the "host dir", we want
863+ // to ignore it if it's a build script.
864864 if filename. starts_with ( & host_root_dir) {
865- // Unless it's a proc macro used in the compiler
866865 if crate_types. iter ( ) . any ( |t| t == "proc-macro" ) {
867866 deps. push ( ( filename. to_path_buf ( ) , true ) ) ;
868867 }
868+
869+ let is_build_script = kind == & [ "custom_build" ]
870+ && crate_types == & [ "bin" ]
871+ && name == "build-script-build" ;
872+ // We don't care about build scripts, but we *do* care about proc-macro
873+ // dependencies - the compiler needs their metadata when loading proc-macro
874+ // crates. Anything that's not a build script should be a proc-macro dependency.
875+ //
876+ // FIXME: Have Cargo explicitly indicate build-script vs proc-macro dependencies,
877+ // instead of relying on this check.
878+ if !is_build_script {
879+ deps. push ( ( filename. to_path_buf ( ) , false ) ) ;
880+ }
869881 continue ;
870882 }
871883
@@ -1003,6 +1015,8 @@ pub fn stream_cargo(
10031015#[ derive( Deserialize ) ]
10041016pub struct CargoTarget < ' a > {
10051017 crate_types : Vec < Cow < ' a , str > > ,
1018+ kind : Vec < Cow < ' a , str > > ,
1019+ name : Cow < ' a , str > ,
10061020}
10071021
10081022#[ derive( Deserialize ) ]
0 commit comments