@@ -549,7 +549,7 @@ fn build_script_with_conflicting_out_dirs() {
549
549
build = ["build1.rs", "build2.rs"]
550
550
"# ,
551
551
)
552
- // OUT_DIR is set to the lexicographically largest build script's OUT_DIR by default
552
+ // By default, OUT_DIR is set to that of the last build script in the array
553
553
. file (
554
554
"src/main.rs" ,
555
555
r#"
@@ -628,7 +628,7 @@ fn build_script_with_conflicts_reverse_sorted() {
628
628
build = ["build2.rs", "build1.rs"]
629
629
"# ,
630
630
)
631
- // OUT_DIR is set to the lexicographically largest build script's OUT_DIR by default
631
+ // By default, OUT_DIR is set to that of the last build script in the array
632
632
. file (
633
633
"src/main.rs" ,
634
634
r#"
@@ -785,9 +785,11 @@ fn multiple_out_dirs() {
785
785
. file (
786
786
"src/main.rs" ,
787
787
r#"
788
- include!(concat!(env!("OUT_DIR"), "/foo.rs"));
788
+ include!(concat!(env!("build1_OUT_DIR"), "/foo.rs"));
789
+ include!(concat!(env!("build2_OUT_DIR"), "/foo.rs"));
789
790
fn main() {
790
- println!("{}", message());
791
+ println!("{}", message1());
792
+ println!("{}", message2());
791
793
}
792
794
"# ,
793
795
)
@@ -803,7 +805,7 @@ fn multiple_out_dirs() {
803
805
let dest_path = Path::new(&out_dir).join("foo.rs");
804
806
fs::write(
805
807
&dest_path,
806
- "pub fn message () -> &'static str {
808
+ "pub fn message1 () -> &'static str {
807
809
\"Hello, from Build Script 1!\"
808
810
}
809
811
"
@@ -822,7 +824,7 @@ fn multiple_out_dirs() {
822
824
let dest_path = Path::new(&out_dir).join("foo.rs");
823
825
fs::write(
824
826
&dest_path,
825
- "pub fn message () -> &'static str {
827
+ "pub fn message2 () -> &'static str {
826
828
\"Hello, from Build Script 2!\"
827
829
}
828
830
"
@@ -835,8 +837,105 @@ fn multiple_out_dirs() {
835
837
. masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
836
838
. with_status ( 0 )
837
839
. with_stdout_data ( str![ [ r#"
840
+ Hello, from Build Script 1!
838
841
Hello, from Build Script 2!
839
842
840
843
"# ] ] )
841
844
. run ( ) ;
842
845
}
846
+
847
+ #[ cargo_test]
848
+ fn build_script_with_fn_conflicts ( ) {
849
+ // In this, multiple scripts have duplicated/conflicting declarations of same function
850
+
851
+ let p = project ( )
852
+ . file (
853
+ "Cargo.toml" ,
854
+ r#"
855
+ cargo-features = ["multiple-build-scripts"]
856
+
857
+ [package]
858
+ name = "foo"
859
+ version = "0.1.0"
860
+ edition = "2024"
861
+
862
+ build = ["build1.rs", "build2.rs"]
863
+ "# ,
864
+ )
865
+ . file (
866
+ "src/main.rs" ,
867
+ r#"
868
+ include!(concat!(env!("build1_OUT_DIR"), "/foo.rs"));
869
+ include!(concat!(env!("build2_OUT_DIR"), "/foo.rs"));
870
+ fn main() {
871
+ println!("{}", message());
872
+ }
873
+ "# ,
874
+ )
875
+ . file (
876
+ "build1.rs" ,
877
+ r#"
878
+ use std::env;
879
+ use std::fs;
880
+ use std::path::Path;
881
+
882
+ fn main() {
883
+ let out_dir = env::var_os("OUT_DIR").unwrap();
884
+ let dest_path = Path::new(&out_dir).join("foo.rs");
885
+ fs::write(
886
+ &dest_path,
887
+ "pub fn message() -> &'static str {
888
+ \"Hello, from Build Script 1!\"
889
+ }
890
+ "
891
+ ).unwrap();
892
+ }"# ,
893
+ )
894
+ . file (
895
+ "build2.rs" ,
896
+ r#"
897
+ use std::env;
898
+ use std::fs;
899
+ use std::path::Path;
900
+
901
+ fn main() {
902
+ let out_dir = env::var_os("OUT_DIR").unwrap();
903
+ let dest_path = Path::new(&out_dir).join("foo.rs");
904
+ fs::write(
905
+ &dest_path,
906
+ "pub fn message() -> &'static str {
907
+ \"Hello, from Build Script 2!\"
908
+ }
909
+ "
910
+ ).unwrap();
911
+ }"# ,
912
+ )
913
+ . build ( ) ;
914
+
915
+ p. cargo ( "check -v" )
916
+ . masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
917
+ . with_status ( 101 )
918
+ . with_stderr_data ( str![ [ r#"
919
+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
920
+ ...
921
+ --> [ROOT]/foo/target/debug/build/foo-[HASH]/out/foo.rs:1:1
922
+ |
923
+ 1 | pub fn message() -> &'static str {
924
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `message` redefined here
925
+ |
926
+ ::: [ROOT]/foo/target/debug/build/foo-[HASH]/out/foo.rs:1:1
927
+ |
928
+ 1 | pub fn message() -> &'static str {
929
+ | -------------------------------- previous definition of the value `message` here
930
+ |
931
+ = [NOTE] `message` must be defined only once in the value namespace of this module
932
+
933
+ For more information about this error, try `rustc --explain E0428`.
934
+ [ERROR] could not compile `foo` (bin "foo") due to 1 previous error
935
+
936
+ Caused by:
937
+ process didn't exit successfully: `rustc --crate-name foo --edition=2024 src/main.rs [..] ([EXIT_STATUS]: 1)
938
+
939
+ "# ] ] )
940
+ . run ( ) ;
941
+ }
0 commit comments