1
1
use cargo:: core:: compiler:: Lto ;
2
2
use cargo_test_support:: registry:: Package ;
3
- use cargo_test_support:: { project, Project } ;
3
+ use cargo_test_support:: { basic_manifest , project, Project } ;
4
4
use std:: process:: Output ;
5
5
6
6
#[ cargo_test]
@@ -25,7 +25,7 @@ fn with_deps() {
25
25
. file ( "src/main.rs" , "extern crate bar; fn main() {}" )
26
26
. build ( ) ;
27
27
p. cargo ( "build -v --release" )
28
- . with_stderr_contains ( "[..]`rustc[..]--crate-name bar[..]-Clinker -plugin-lto[..]`" )
28
+ . with_stderr_contains ( "[..]`rustc[..]--crate-name bar[..]-C linker -plugin-lto[..]`" )
29
29
. with_stderr_contains ( "[..]`rustc[..]--crate-name test[..]-C lto[..]`" )
30
30
. run ( ) ;
31
31
}
@@ -83,7 +83,7 @@ fn build_dep_not_ltod() {
83
83
. file ( "src/main.rs" , "fn main() {}" )
84
84
. build ( ) ;
85
85
p. cargo ( "build -v --release" )
86
- . with_stderr_contains ( "[..]`rustc[..]--crate-name bar[..]-Cembed -bitcode=no[..]`" )
86
+ . with_stderr_contains ( "[..]`rustc[..]--crate-name bar[..]-C embed -bitcode=no[..]`" )
87
87
. with_stderr_contains ( "[..]`rustc[..]--crate-name test[..]-C lto[..]`" )
88
88
. run ( ) ;
89
89
}
@@ -188,30 +188,32 @@ fn complicated() {
188
188
p. cargo ( "build -v --release" )
189
189
// normal deps and their transitive dependencies do not need object
190
190
// code, so they should have linker-plugin-lto specified
191
- . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_normal2 [..]-Clinker-plugin-lto[..]`" )
192
- . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_normal [..]-Clinker-plugin-lto[..]`" )
191
+ . with_stderr_contains (
192
+ "[..]`rustc[..]--crate-name dep_normal2 [..]-C linker-plugin-lto[..]`" ,
193
+ )
194
+ . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_normal [..]-C linker-plugin-lto[..]`" )
193
195
// build dependencies and their transitive deps don't need any bitcode,
194
196
// so embedding should be turned off
195
- . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_build2 [..]-Cembed -bitcode=no[..]`" )
196
- . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_build [..]-Cembed -bitcode=no[..]`" )
197
+ . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_build2 [..]-C embed -bitcode=no[..]`" )
198
+ . with_stderr_contains ( "[..]`rustc[..]--crate-name dep_build [..]-C embed -bitcode=no[..]`" )
197
199
. with_stderr_contains (
198
- "[..]`rustc[..]--crate-name build_script_build [..]-Cembed -bitcode=no[..]`" ,
200
+ "[..]`rustc[..]--crate-name build_script_build [..]-C embed -bitcode=no[..]`" ,
199
201
)
200
202
// proc macro deps are the same as build deps here
201
203
. with_stderr_contains (
202
- "[..]`rustc[..]--crate-name dep_proc_macro2 [..]-Cembed -bitcode=no[..]`" ,
204
+ "[..]`rustc[..]--crate-name dep_proc_macro2 [..]-C embed -bitcode=no[..]`" ,
203
205
)
204
206
. with_stderr_contains (
205
- "[..]`rustc[..]--crate-name dep_proc_macro [..]-Cembed -bitcode=no[..]`" ,
207
+ "[..]`rustc[..]--crate-name dep_proc_macro [..]-C embed -bitcode=no[..]`" ,
206
208
)
207
209
. with_stderr_contains ( "[..]`rustc[..]--crate-name test [..]--crate-type bin[..]-C lto[..]`" )
208
210
. with_stderr_contains (
209
211
"[..]`rustc[..]--crate-name test [..]--crate-type cdylib[..]-C lto[..]`" ,
210
212
)
211
213
. with_stderr_contains ( "[..]`rustc[..]--crate-name dep_shared [..]`" )
212
214
. with_stderr_does_not_contain ( "[..]--crate-name dep_shared[..]-C lto[..]" )
213
- . with_stderr_does_not_contain ( "[..]--crate-name dep_shared[..]-Clinker -plugin-lto[..]" )
214
- . with_stderr_does_not_contain ( "[..]--crate-name dep_shared[..]-Cembed -bitcode[..]" )
215
+ . with_stderr_does_not_contain ( "[..]--crate-name dep_shared[..]-C linker -plugin-lto[..]" )
216
+ . with_stderr_does_not_contain ( "[..]--crate-name dep_shared[..]-C embed -bitcode[..]" )
215
217
. run ( ) ;
216
218
}
217
219
@@ -252,9 +254,9 @@ fn off_in_manifest_works() {
252
254
[DOWNLOADING] [..]
253
255
[DOWNLOADED] [..]
254
256
[COMPILING] bar v0.0.1
255
- [RUNNING] `rustc --crate-name bar [..]--crate-type lib [..]-Cembed -bitcode=no[..]
257
+ [RUNNING] `rustc --crate-name bar [..]--crate-type lib [..]-C embed -bitcode=no[..]
256
258
[COMPILING] test [..]
257
- [RUNNING] `rustc --crate-name test [..]--crate-type lib [..]-Cembed -bitcode=no[..]
259
+ [RUNNING] `rustc --crate-name test [..]--crate-type lib [..]-C embed -bitcode=no[..]
258
260
[RUNNING] `rustc --crate-name test src/main.rs [..]--crate-type bin [..]-C lto=off[..]
259
261
[FINISHED] [..]
260
262
" ,
@@ -283,7 +285,7 @@ fn between_builds() {
283
285
. with_stderr (
284
286
"\
285
287
[COMPILING] test [..]
286
- [RUNNING] `rustc [..]--crate-type lib[..]-Clinker -plugin-lto[..]
288
+ [RUNNING] `rustc [..]--crate-type lib[..]-C linker -plugin-lto[..]
287
289
[FINISHED] [..]
288
290
" ,
289
291
)
@@ -447,9 +449,9 @@ fn verify_lto(output: &Output, krate: &str, krate_info: &str, expected_lto: Lto)
447
449
}
448
450
} else if line. contains ( "-C lto" ) {
449
451
Lto :: Run ( None )
450
- } else if line. contains ( "-Clinker -plugin-lto" ) {
452
+ } else if line. contains ( "-C linker -plugin-lto" ) {
451
453
Lto :: OnlyBitcode
452
- } else if line. contains ( "-Cembed -bitcode=no" ) {
454
+ } else if line. contains ( "-C embed -bitcode=no" ) {
453
455
Lto :: OnlyObject
454
456
} else {
455
457
Lto :: ObjectAndBitcode
@@ -491,8 +493,8 @@ fn cdylib_and_rlib() {
491
493
[FRESH] registry-shared v0.0.1
492
494
[FRESH] bar v0.0.0 [..]
493
495
[COMPILING] foo [..]
494
- [RUNNING] `rustc --crate-name foo [..]-Cembed -bitcode=no --test[..]
495
- [RUNNING] `rustc --crate-name a [..]-Cembed -bitcode=no --test[..]
496
+ [RUNNING] `rustc --crate-name foo [..]-C embed -bitcode=no --test[..]
497
+ [RUNNING] `rustc --crate-name a [..]-C embed -bitcode=no --test[..]
496
498
[FINISHED] [..]
497
499
[RUNNING] [..]
498
500
[RUNNING] [..]
@@ -512,16 +514,19 @@ fn cdylib_and_rlib() {
512
514
p. cargo ( "test --release -v --manifest-path bar/Cargo.toml" )
513
515
. with_stderr_unordered (
514
516
"\
515
- [FRESH] registry v0.0.1
516
- [FRESH] registry-shared v0.0.1
517
+ [COMPILING] registry v0.0.1
518
+ [COMPILING] registry-shared v0.0.1
519
+ [RUNNING] `rustc --crate-name registry [..]-C embed-bitcode=no[..]
520
+ [RUNNING] `rustc --crate-name registry_shared [..]-C embed-bitcode=no[..]
517
521
[COMPILING] bar [..]
518
- [RUNNING] `rustc --crate-name bar [..]-Cembed-bitcode=no --test[..]
519
- [RUNNING] `rustc --crate-name b [..]-Cembed-bitcode=no --test[..]
522
+ [RUNNING] `rustc --crate-name bar [..]--crate-type cdylib --crate-type rlib [..]-C embed-bitcode=no[..]
523
+ [RUNNING] `rustc --crate-name bar [..]-C embed-bitcode=no --test[..]
524
+ [RUNNING] `rustc --crate-name b [..]-C embed-bitcode=no --test[..]
520
525
[FINISHED] [..]
521
- [RUNNING] [..]
522
- [RUNNING] [..]
526
+ [RUNNING] [..]target/release/deps/bar-[..]
527
+ [RUNNING] [..]target/release/deps/b-[..]
523
528
[DOCTEST] bar
524
- [RUNNING] `rustdoc --crate-type cdylib --crate-type rlib --test [..]
529
+ [RUNNING] `rustdoc --crate-type cdylib --crate-type rlib --test [..]-C embed-bitcode=no[..]
525
530
" ,
526
531
)
527
532
. run ( ) ;
@@ -547,8 +552,8 @@ fn dylib() {
547
552
[FRESH] registry-shared v0.0.1
548
553
[FRESH] bar v0.0.0 [..]
549
554
[COMPILING] foo [..]
550
- [RUNNING] `rustc --crate-name foo [..]-Cembed -bitcode=no --test[..]
551
- [RUNNING] `rustc --crate-name a [..]-Cembed -bitcode=no --test[..]
555
+ [RUNNING] `rustc --crate-name foo [..]-C embed -bitcode=no --test[..]
556
+ [RUNNING] `rustc --crate-name a [..]-C embed -bitcode=no --test[..]
552
557
[FINISHED] [..]
553
558
[RUNNING] [..]
554
559
[RUNNING] [..]
@@ -560,9 +565,9 @@ fn dylib() {
560
565
"\
561
566
[COMPILING] registry-shared v0.0.1
562
567
[FRESH] registry v0.0.1
563
- [RUNNING] `rustc --crate-name registry_shared [..]-Cembed -bitcode=no[..]
568
+ [RUNNING] `rustc --crate-name registry_shared [..]-C embed -bitcode=no[..]
564
569
[COMPILING] bar [..]
565
- [RUNNING] `rustc --crate-name bar [..]--crate-type dylib [..]-Cembed -bitcode=no[..]
570
+ [RUNNING] `rustc --crate-name bar [..]--crate-type dylib [..]-C embed -bitcode=no[..]
566
571
[FINISHED] [..]
567
572
" ,
568
573
)
@@ -573,8 +578,8 @@ fn dylib() {
573
578
[FRESH] registry-shared v0.0.1
574
579
[FRESH] registry v0.0.1
575
580
[COMPILING] bar [..]
576
- [RUNNING] `rustc --crate-name bar [..]-Cembed -bitcode=no --test[..]
577
- [RUNNING] `rustc --crate-name b [..]-Cembed -bitcode=no --test[..]
581
+ [RUNNING] `rustc --crate-name bar [..]-C embed -bitcode=no --test[..]
582
+ [RUNNING] `rustc --crate-name b [..]-C embed -bitcode=no --test[..]
578
583
[FINISHED] [..]
579
584
[RUNNING] [..]
580
585
[RUNNING] [..]
@@ -625,7 +630,7 @@ fn test_profile() {
625
630
[COMPILING] bar v0.0.1
626
631
[RUNNING] `rustc --crate-name bar [..]crate-type lib[..]
627
632
[COMPILING] foo [..]
628
- [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -Cembed-bitcode=no [..]
633
+ [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C linker-plugin-lto [..]
629
634
[RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -C lto=thin [..]--test[..]
630
635
[FINISHED] [..]
631
636
[RUNNING] [..]
@@ -678,12 +683,66 @@ fn dev_profile() {
678
683
[COMPILING] bar v0.0.1
679
684
[RUNNING] `rustc --crate-name bar [..]crate-type lib[..]
680
685
[COMPILING] foo [..]
681
- [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -Clinker-plugin-lto [..]
682
- [RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -Cembed -bitcode=no [..]--test[..]
686
+ [RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no [..]
687
+ [RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -C embed -bitcode=no [..]--test[..]
683
688
[FINISHED] [..]
684
689
[RUNNING] [..]
685
690
[DOCTEST] foo
686
691
[RUNNING] `rustdoc [..]
687
692
" )
688
693
. run ( ) ;
689
694
}
695
+
696
+ #[ cargo_test]
697
+ fn doctest ( ) {
698
+ let p = project ( )
699
+ . file (
700
+ "Cargo.toml" ,
701
+ r#"
702
+ [package]
703
+ name = "foo"
704
+ version = "0.1.0"
705
+ edition = "2018"
706
+
707
+ [profile.release]
708
+ lto = true
709
+
710
+ [dependencies]
711
+ bar = { path = "bar" }
712
+ "# ,
713
+ )
714
+ . file (
715
+ "src/lib.rs" ,
716
+ r#"
717
+ /// Foo!
718
+ ///
719
+ /// ```
720
+ /// foo::foo();
721
+ /// ```
722
+ pub fn foo() { bar::bar(); }
723
+ "# ,
724
+ )
725
+ . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
726
+ . file (
727
+ "bar/src/lib.rs" ,
728
+ r#"
729
+ pub fn bar() { println!("hi!"); }
730
+ "# ,
731
+ )
732
+ . build ( ) ;
733
+
734
+ p. cargo ( "test --doc --release -v" )
735
+ . with_stderr_contains ( "[..]`rustc --crate-name bar[..]-C embed-bitcode=no[..]" )
736
+ . with_stderr_contains ( "[..]`rustc --crate-name foo[..]-C embed-bitcode=no[..]" )
737
+ // embed-bitcode should be harmless here
738
+ . with_stderr_contains ( "[..]`rustdoc [..]-C embed-bitcode=no[..]" )
739
+ . run ( ) ;
740
+
741
+ // Try with bench profile.
742
+ p. cargo ( "test --doc --release -v" )
743
+ . env ( "CARGO_PROFILE_BENCH_LTO" , "true" )
744
+ . with_stderr_contains ( "[..]`rustc --crate-name bar[..]-C linker-plugin-lto[..]" )
745
+ . with_stderr_contains ( "[..]`rustc --crate-name foo[..]-C linker-plugin-lto[..]" )
746
+ . with_stderr_contains ( "[..]`rustdoc [..]-C lto[..]" )
747
+ . run ( ) ;
748
+ }
0 commit comments