@@ -764,3 +764,71 @@ fn bar() {
764764"# ] ] )
765765 . run ( ) ;
766766}
767+
768+ #[ cargo_test]
769+ fn multiple_out_dirs ( ) {
770+ // Test for accessing the OUT_DIR of build scripts
771+ let p = project ( )
772+ . file (
773+ "Cargo.toml" ,
774+ r#"
775+ cargo-features = ["multiple-build-scripts"]
776+
777+ [package]
778+ name = "foo"
779+ version = "0.1.0"
780+ edition = "2024"
781+ build = ["build1.rs", "build2.rs"]
782+ "# ,
783+ )
784+ . file (
785+ "src/main.rs" ,
786+ r#"
787+ const OUT_DIR: &'static str = env!("OUT_DIR");
788+ const BUILD1_OUT_DIR: &'static str = env!("BUILD1_OUT_DIR");
789+ const BUILD2_OUT_DIR: &'static str = env!("BUILD2_OUT_DIR");
790+
791+ fn main() {
792+ println!("{}", OUT_DIR);
793+ println!("{}", BUILD1_OUT_DIR);
794+ println!("{}", BUILD2_OUT_DIR);
795+ }
796+ "# ,
797+ )
798+ . file ( "build1.rs" , "fn main() {}" )
799+ . file ( "build2.rs" , "fn main() {}" )
800+ . build ( ) ;
801+ p. cargo ( "run -v" )
802+ . masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
803+ . with_status ( 101 )
804+ . with_stderr_data ( str![ [ r#"
805+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
806+ [RUNNING] `rustc --crate-name build_script_build[..]`
807+ [RUNNING] `rustc --crate-name build_script_build[..]`
808+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build[..]`
809+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build[..]`
810+ [RUNNING] `rustc --crate-name foo --edition=2024 src/main.rs[..]`
811+ [ERROR] environment variable `BUILD1_OUT_DIR` not defined at compile time
812+ --> src/main.rs:3:54
813+ |
814+ 3 | const BUILD1_OUT_DIR: &'static str = env!("BUILD1_OUT_DIR");
815+ | ^^^^^^^^^^^^^^^^^^^^^^
816+ |
817+ = [HELP] use `std::env::var("BUILD1_OUT_DIR")` to read the variable at run time
818+
819+ [ERROR] environment variable `BUILD2_OUT_DIR` not defined at compile time
820+ --> src/main.rs:4:54
821+ |
822+ 4 | const BUILD2_OUT_DIR: &'static str = env!("BUILD2_OUT_DIR");
823+ | ^^^^^^^^^^^^^^^^^^^^^^
824+ |
825+ = [HELP] use `std::env::var("BUILD2_OUT_DIR")` to read the variable at run time
826+
827+ [ERROR] could not compile `foo` (bin "foo") due to 2 previous errors
828+
829+ Caused by:
830+ process didn't exit successfully: `rustc --crate-name foo --edition=2024 src/main.rs [..]` ([EXIT_STATUS]: 1)
831+
832+ "# ] ] )
833+ . run ( ) ;
834+ }
0 commit comments