@@ -8,6 +8,7 @@ use std::process::Command;
8
8
static DOCKER_IMAGE_TAG : & str = "ghcr.io/rust-lang/crates-build-env/linux-micro" ;
9
9
static DOCKER_SOCKET : & str = "/var/run/docker.sock" ;
10
10
static CONTAINER_PREFIX : & str = "/outside" ;
11
+ static TARGET_PREFIX : & str = "/target" ;
11
12
12
13
#[ test]
13
14
#[ cfg( unix) ]
@@ -26,20 +27,28 @@ fn execute(test: &str) -> Result<(), Error> {
26
27
// The binary to execute is remapped to be prefixed by /outside instead of the current
27
28
// directory.
28
29
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
+ } ;
29
34
let current_exe = std:: env:: current_exe ( ) . unwrap ( ) ;
30
35
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 (
32
38
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 " ) ?,
35
41
) ;
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) ;
37
44
let docker_sock = os_string ! ( DOCKER_SOCKET , ":" , DOCKER_SOCKET ) ;
38
45
39
46
Command :: new ( "docker" )
40
47
. arg ( "run" )
41
48
. arg ( "-v" )
42
- . arg ( mount)
49
+ . arg ( src_mount)
50
+ . arg ( "-v" )
51
+ . arg ( target_mount)
43
52
. arg ( "-v" )
44
53
. arg ( docker_sock)
45
54
. arg ( "-w" )
0 commit comments