@@ -263,14 +263,14 @@ fn resolve_toml(
263
263
manifest_file : & Path ,
264
264
gctx : & GlobalContext ,
265
265
warnings : & mut Vec < String > ,
266
- _errors : & mut Vec < String > ,
266
+ errors : & mut Vec < String > ,
267
267
) -> CargoResult < manifest:: TomlManifest > {
268
268
let mut resolved_toml = manifest:: TomlManifest {
269
269
cargo_features : original_toml. cargo_features . clone ( ) ,
270
270
package : None ,
271
271
project : None ,
272
272
profile : original_toml. profile . clone ( ) ,
273
- lib : original_toml . lib . clone ( ) ,
273
+ lib : None ,
274
274
bin : original_toml. bin . clone ( ) ,
275
275
example : original_toml. example . clone ( ) ,
276
276
test : original_toml. test . clone ( ) ,
@@ -301,6 +301,62 @@ fn resolve_toml(
301
301
if let Some ( original_package) = original_toml. package ( ) {
302
302
let resolved_package = resolve_package_toml ( original_package, package_root, & inherit) ?;
303
303
resolved_toml. package = Some ( resolved_package) ;
304
+ let edition = if let Some ( edition) = resolved_toml
305
+ . package
306
+ . as_ref ( )
307
+ . expect ( "in `package` branch" )
308
+ . resolved_edition ( )
309
+ . expect ( "previously resolved" )
310
+ {
311
+ let edition: Edition = edition
312
+ . parse ( )
313
+ . with_context ( || "failed to parse the `edition` key" ) ?;
314
+ edition
315
+ } else {
316
+ let default_edition = Edition :: default ( ) ;
317
+ default_edition
318
+ } ;
319
+
320
+ resolved_toml. lib = targets:: resolve_lib (
321
+ original_toml. lib . as_ref ( ) ,
322
+ package_root,
323
+ & original_package. name ,
324
+ edition,
325
+ warnings,
326
+ ) ?;
327
+ resolved_toml. bin = Some ( targets:: resolve_bins (
328
+ original_toml. bin . as_ref ( ) ,
329
+ package_root,
330
+ & original_package. name ,
331
+ edition,
332
+ original_package. autobins ,
333
+ warnings,
334
+ resolved_toml. lib . is_some ( ) ,
335
+ ) ?) ;
336
+ resolved_toml. example = Some ( targets:: resolve_examples (
337
+ original_toml. example . as_ref ( ) ,
338
+ package_root,
339
+ edition,
340
+ original_package. autoexamples ,
341
+ warnings,
342
+ errors,
343
+ ) ?) ;
344
+ resolved_toml. test = Some ( targets:: resolve_tests (
345
+ original_toml. test . as_ref ( ) ,
346
+ package_root,
347
+ edition,
348
+ original_package. autotests ,
349
+ warnings,
350
+ errors,
351
+ ) ?) ;
352
+ resolved_toml. bench = Some ( targets:: resolve_benches (
353
+ original_toml. bench . as_ref ( ) ,
354
+ package_root,
355
+ edition,
356
+ original_package. autobenches ,
357
+ warnings,
358
+ errors,
359
+ ) ?) ;
304
360
305
361
resolved_toml. dependencies = resolve_dependencies (
306
362
gctx,
@@ -453,10 +509,10 @@ fn resolve_package_toml<'a>(
453
509
. map ( manifest:: InheritableField :: Value ) ,
454
510
workspace : original_package. workspace . clone ( ) ,
455
511
im_a_teapot : original_package. im_a_teapot . clone ( ) ,
456
- autobins : original_package . autobins . clone ( ) ,
457
- autoexamples : original_package . autoexamples . clone ( ) ,
458
- autotests : original_package . autotests . clone ( ) ,
459
- autobenches : original_package . autobenches . clone ( ) ,
512
+ autobins : Some ( false ) ,
513
+ autoexamples : Some ( false ) ,
514
+ autotests : Some ( false ) ,
515
+ autobenches : Some ( false ) ,
460
516
default_run : original_package. default_run . clone ( ) ,
461
517
description : original_package
462
518
. description
@@ -1093,8 +1149,8 @@ fn to_real_manifest(
1093
1149
// If we have a lib with no path, use the inferred lib or else the package name.
1094
1150
let targets = to_targets (
1095
1151
& features,
1152
+ & original_toml,
1096
1153
& resolved_toml,
1097
- package_name,
1098
1154
package_root,
1099
1155
edition,
1100
1156
& resolved_package. metabuild ,
@@ -2471,14 +2527,14 @@ fn prepare_toml_for_publish(
2471
2527
}
2472
2528
2473
2529
let lib = if let Some ( target) = & me. lib {
2474
- Some ( prepare_target_for_publish ( target, "library" ) ? )
2530
+ prepare_target_for_publish ( target, included , "library" , ws . gctx ( ) ) ?
2475
2531
} else {
2476
2532
None
2477
2533
} ;
2478
- let bin = prepare_targets_for_publish ( me. bin . as_ref ( ) , "binary" ) ?;
2479
- let example = prepare_targets_for_publish ( me. example . as_ref ( ) , "example" ) ?;
2480
- let test = prepare_targets_for_publish ( me. test . as_ref ( ) , "test" ) ?;
2481
- let bench = prepare_targets_for_publish ( me. bench . as_ref ( ) , "benchmark" ) ?;
2534
+ let bin = prepare_targets_for_publish ( me. bin . as_ref ( ) , included , "binary" , ws . gctx ( ) ) ?;
2535
+ let example = prepare_targets_for_publish ( me. example . as_ref ( ) , included , "example" , ws . gctx ( ) ) ?;
2536
+ let test = prepare_targets_for_publish ( me. test . as_ref ( ) , included , "test" , ws . gctx ( ) ) ?;
2537
+ let bench = prepare_targets_for_publish ( me. bench . as_ref ( ) , included , "benchmark" , ws . gctx ( ) ) ?;
2482
2538
2483
2539
let all = |_d : & manifest:: TomlDependency | true ;
2484
2540
let mut manifest = manifest:: TomlManifest {
@@ -2636,40 +2692,53 @@ fn prepare_toml_for_publish(
2636
2692
2637
2693
fn prepare_targets_for_publish (
2638
2694
targets : Option < & Vec < manifest:: TomlTarget > > ,
2695
+ included : & [ String ] ,
2639
2696
context : & str ,
2697
+ gctx : & GlobalContext ,
2640
2698
) -> CargoResult < Option < Vec < manifest:: TomlTarget > > > {
2641
2699
let Some ( targets) = targets else {
2642
2700
return Ok ( None ) ;
2643
2701
} ;
2644
2702
2645
2703
let mut prepared = Vec :: with_capacity ( targets. len ( ) ) ;
2646
2704
for target in targets {
2647
- let target = prepare_target_for_publish ( target, context) ?;
2705
+ let Some ( target) = prepare_target_for_publish ( target, included, context, gctx) ? else {
2706
+ continue ;
2707
+ } ;
2648
2708
prepared. push ( target) ;
2649
2709
}
2650
2710
2651
- Ok ( Some ( prepared) )
2711
+ if prepared. is_empty ( ) {
2712
+ Ok ( None )
2713
+ } else {
2714
+ Ok ( Some ( prepared) )
2715
+ }
2652
2716
}
2653
2717
2654
2718
fn prepare_target_for_publish (
2655
2719
target : & manifest:: TomlTarget ,
2720
+ included : & [ String ] ,
2656
2721
context : & str ,
2657
- ) -> CargoResult < manifest:: TomlTarget > {
2658
- let mut target = target. clone ( ) ;
2659
- if let Some ( path) = target. path {
2660
- let path = normalize_path ( & path. 0 ) ;
2661
- target. path = Some ( manifest:: PathValue ( normalize_path_sep ( path, context) ?) ) ;
2662
- }
2663
- Ok ( target)
2664
- }
2665
-
2666
- fn normalize_path_sep ( path : PathBuf , context : & str ) -> CargoResult < PathBuf > {
2722
+ gctx : & GlobalContext ,
2723
+ ) -> CargoResult < Option < manifest:: TomlTarget > > {
2724
+ let path = target. path . as_ref ( ) . expect ( "previously resolved" ) ;
2725
+ let path = normalize_path ( & path. 0 ) ;
2667
2726
let path = path
2668
2727
. into_os_string ( )
2669
2728
. into_string ( )
2670
2729
. map_err ( |_err| anyhow:: format_err!( "non-UTF8 path for {context}" ) ) ?;
2671
- let path = normalize_path_string_sep ( path) ;
2672
- Ok ( path. into ( ) )
2730
+ if !included. contains ( & path) {
2731
+ let name = target. name . as_ref ( ) . expect ( "previously resolved" ) ;
2732
+ gctx. shell ( ) . warn ( format ! (
2733
+ "ignoring {context} `{name}` as `{path}` is not included in the published package" ,
2734
+ ) ) ?;
2735
+ return Ok ( None ) ;
2736
+ }
2737
+
2738
+ let mut target = target. clone ( ) ;
2739
+ target. path = Some ( manifest:: PathValue ( normalize_path_string_sep ( path) . into ( ) ) ) ;
2740
+
2741
+ Ok ( Some ( target) )
2673
2742
}
2674
2743
2675
2744
fn normalize_path_string_sep ( path : String ) -> String {
0 commit comments