@@ -7,6 +7,7 @@ use std::sync::Arc;
7
7
use std:: task:: Poll ;
8
8
9
9
use crate :: core:: compiler:: { BuildConfig , CompileMode , DefaultExecutor , Executor } ;
10
+ use crate :: core:: manifest:: Target ;
10
11
use crate :: core:: resolver:: CliFeatures ;
11
12
use crate :: core:: { registry:: PackageRegistry , resolver:: HasDevUnits } ;
12
13
use crate :: core:: { Feature , Shell , Verbosity , Workspace } ;
@@ -331,6 +332,29 @@ fn build_ar_list(
331
332
warn_on_nonexistent_file ( & pkg, & readme_path, "readme" , & ws) ?;
332
333
}
333
334
}
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
+
334
358
result. sort_unstable_by ( |a, b| a. rel_path . cmp ( & b. rel_path ) ) ;
335
359
336
360
Ok ( result)
@@ -405,6 +429,23 @@ fn warn_on_nonexistent_file(
405
429
) )
406
430
}
407
431
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
+
408
449
/// Construct `Cargo.lock` for the package to be published.
409
450
fn build_lock ( ws : & Workspace < ' _ > , orig_pkg : & Package ) -> CargoResult < String > {
410
451
let config = ws. config ( ) ;
0 commit comments