@@ -8,6 +8,7 @@ use std::process::Command;
88static DOCKER_IMAGE_TAG : & str = "ghcr.io/rust-lang/crates-build-env/linux-micro" ;
99static DOCKER_SOCKET : & str = "/var/run/docker.sock" ;
1010static CONTAINER_PREFIX : & str = "/outside" ;
11+ static TARGET_PREFIX : & str = "/target" ;
1112
1213#[ test]
1314#[ cfg( unix) ]
@@ -26,20 +27,28 @@ fn execute(test: &str) -> Result<(), Error> {
2627 // The binary to execute is remapped to be prefixed by /outside instead of the current
2728 // directory.
2829 let current_dir = std:: fs:: canonicalize ( "." ) ?;
30+ let target_parent_dir = match option_env ! ( "CARGO_TARGET_DIR" ) {
31+ Some ( t) => Path :: new ( t) . parent ( ) . unwrap ( ) ,
32+ None => & current_dir,
33+ } ;
2934 let current_exe = std:: env:: current_exe ( ) . unwrap ( ) ;
3035 let container_prefix = Path :: new ( CONTAINER_PREFIX ) ;
31- let container_exe = container_prefix. join (
36+ let target_prefix = Path :: new ( TARGET_PREFIX ) ;
37+ let container_exe = target_prefix. join (
3238 current_exe
33- . strip_prefix ( & current_dir )
34- . with_context ( |_| "the working directory is not a parent of the test binary " ) ?,
39+ . strip_prefix ( & target_parent_dir )
40+ . with_context ( |_| "could not determine cargo target dir " ) ?,
3541 ) ;
36- let mount = os_string ! ( & current_dir, ":" , & container_prefix) ;
42+ let src_mount = os_string ! ( & current_dir, ":" , & container_prefix) ;
43+ let target_mount = os_string ! ( & target_parent_dir, ":" , & target_prefix) ;
3744 let docker_sock = os_string ! ( DOCKER_SOCKET , ":" , DOCKER_SOCKET ) ;
3845
3946 Command :: new ( "docker" )
4047 . arg ( "run" )
4148 . arg ( "-v" )
42- . arg ( mount)
49+ . arg ( src_mount)
50+ . arg ( "-v" )
51+ . arg ( target_mount)
4352 . arg ( "-v" )
4453 . arg ( docker_sock)
4554 . arg ( "-w" )
0 commit comments