@@ -608,6 +608,85 @@ Hello, from Build Script 2!
608608 . run ( ) ;
609609}
610610
611+ #[ cargo_test]
612+ fn build_script_with_conflicts_reverse_sorted ( ) {
613+ // In this, multiple scripts create file with same name in their respective OUT_DIR.
614+ // It is different from above because `package.build` is not sorted in this.
615+
616+ let p = project ( )
617+ . file (
618+ "Cargo.toml" ,
619+ r#"
620+ cargo-features = ["multiple-build-scripts"]
621+
622+ [package]
623+ name = "foo"
624+ version = "0.1.0"
625+ edition = "2024"
626+
627+ build = ["build2.rs", "build1.rs"]
628+ "# ,
629+ )
630+ // OUT_DIR is set to the lexicographically largest build script's OUT_DIR by default
631+ . file (
632+ "src/main.rs" ,
633+ r#"
634+ include!(concat!(env!("OUT_DIR"), "/foo.rs"));
635+ fn main() {
636+ println!("{}", message());
637+ }
638+ "# ,
639+ )
640+ . file (
641+ "build1.rs" ,
642+ r#"
643+ use std::env;
644+ use std::fs;
645+ use std::path::Path;
646+
647+ fn main() {
648+ let out_dir = env::var_os("OUT_DIR").unwrap();
649+ let dest_path = Path::new(&out_dir).join("foo.rs");
650+ fs::write(
651+ &dest_path,
652+ "pub fn message() -> &'static str {
653+ \"Hello, from Build Script 1!\"
654+ }
655+ "
656+ ).unwrap();
657+ }"# ,
658+ )
659+ . file (
660+ "build2.rs" ,
661+ r#"
662+ use std::env;
663+ use std::fs;
664+ use std::path::Path;
665+
666+ fn main() {
667+ let out_dir = env::var_os("OUT_DIR").unwrap();
668+ let dest_path = Path::new(&out_dir).join("foo.rs");
669+ fs::write(
670+ &dest_path,
671+ "pub fn message() -> &'static str {
672+ \"Hello, from Build Script 2!\"
673+ }
674+ "
675+ ).unwrap();
676+ }"# ,
677+ )
678+ . build ( ) ;
679+
680+ p. cargo ( "run -v" )
681+ . masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
682+ . with_status ( 0 )
683+ . with_stdout_data ( str![ [ r#"
684+ Hello, from Build Script 2!
685+
686+ "# ] ] )
687+ . run ( ) ;
688+ }
689+
611690#[ cargo_test]
612691fn rerun_untracks_other_files ( ) {
613692 let p = project ( )
0 commit comments