@@ -7,6 +7,7 @@ use std::sync::Arc;
77use std:: task:: Poll ;
88
99use crate :: core:: compiler:: { BuildConfig , CompileMode , DefaultExecutor , Executor } ;
10+ use crate :: core:: manifest:: Target ;
1011use crate :: core:: resolver:: CliFeatures ;
1112use crate :: core:: { registry:: PackageRegistry , resolver:: HasDevUnits } ;
1213use crate :: core:: { Feature , Shell , Verbosity , Workspace } ;
@@ -331,6 +332,29 @@ fn build_ar_list(
331332 warn_on_nonexistent_file ( & pkg, & readme_path, "readme" , & ws) ?;
332333 }
333334 }
335+
336+ for t in pkg
337+ . manifest ( )
338+ . targets ( )
339+ . iter ( )
340+ . filter ( |t| t. is_custom_build ( ) )
341+ {
342+ if let Some ( custome_build_path) = t. src_path ( ) . path ( ) {
343+ let abs_custome_build_path =
344+ paths:: normalize_path ( & pkg. root ( ) . join ( custome_build_path) ) ;
345+ if abs_custome_build_path. is_file ( ) {
346+ if !abs_custome_build_path
347+ . ancestors ( )
348+ . any ( |ancestor| ancestor == pkg. root ( ) )
349+ {
350+ warn_custom_build_file_not_in_package ( pkg, & abs_custome_build_path, t, & ws) ?
351+ }
352+ } else {
353+ warn_on_nonexistent_file ( & pkg, & custome_build_path, "build" , & ws) ?
354+ }
355+ }
356+ }
357+
334358 result. sort_unstable_by ( |a, b| a. rel_path . cmp ( & b. rel_path ) ) ;
335359
336360 Ok ( result)
@@ -405,6 +429,23 @@ fn warn_on_nonexistent_file(
405429 ) )
406430}
407431
432+ fn warn_custom_build_file_not_in_package (
433+ pkg : & Package ,
434+ path : & Path ,
435+ target : & Target ,
436+ ws : & Workspace < ' _ > ,
437+ ) -> CargoResult < ( ) > {
438+ let msg = format ! (
439+ "the source file of {:?} target `{}` doesn't appear to be a path inside of the package.\n \
440+ It is at {}, whereas the root the package is {}.\n \
441+ This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files.\n \
442+ Please update the `build` setting in the manifest at `{}` and point to a path inside the root of the package.\n ",
443+ target. kind( ) , target. name( ) , path. display( ) , pkg. root( ) . display( ) , pkg. manifest_path( ) . display( )
444+ ) ;
445+
446+ ws. config ( ) . shell ( ) . warn ( & msg)
447+ }
448+
408449/// Construct `Cargo.lock` for the package to be published.
409450fn build_lock ( ws : & Workspace < ' _ > , orig_pkg : & Package ) -> CargoResult < String > {
410451 let config = ws. config ( ) ;
0 commit comments