@@ -9,15 +9,12 @@ use crate::cargo::{cargo_metadata_with_args, CargoMetadata};
99use  crate :: config:: { bool_from_envvar,  Config } ; 
1010use  crate :: errors:: * ; 
1111use  crate :: extensions:: { CommandExt ,  SafeCommand } ; 
12- use  crate :: file:: { self ,  write_file,  ToUtf8 } ; 
12+ use  crate :: file:: { self ,  write_file,  PathExt ,   ToUtf8 } ; 
1313use  crate :: id; 
1414use  crate :: rustc:: { self ,  VersionMetaExt } ; 
1515use  crate :: shell:: { MessageInfo ,  Verbosity } ; 
1616use  crate :: Target ; 
1717
18- #[ cfg( target_os = "windows" ) ]  
19- use  crate :: file:: PathExt ; 
20- 
2118pub  use  super :: custom:: CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX ; 
2219
2320pub  const  CROSS_IMAGE :  & str  = "ghcr.io/cross-rs" ; 
@@ -37,15 +34,23 @@ pub struct DockerOptions {
3734    pub  target :  Target , 
3835    pub  config :  Config , 
3936    pub  uses_xargo :  bool , 
37+     pub  ignore_cargo_config :  bool , 
4038} 
4139
4240impl  DockerOptions  { 
43-     pub  fn  new ( engine :  Engine ,  target :  Target ,  config :  Config ,  uses_xargo :  bool )  -> DockerOptions  { 
41+     pub  fn  new ( 
42+         engine :  Engine , 
43+         target :  Target , 
44+         config :  Config , 
45+         uses_xargo :  bool , 
46+         ignore_cargo_config :  bool , 
47+     )  -> DockerOptions  { 
4448        DockerOptions  { 
4549            engine, 
4650            target, 
4751            config, 
4852            uses_xargo, 
53+             ignore_cargo_config, 
4954        } 
5055    } 
5156
@@ -220,10 +225,18 @@ impl DockerPaths {
220225        self . workspace_from_cwd ( ) . is_ok ( ) 
221226    } 
222227
228+     pub  fn  cargo_home ( & self )  -> & Path  { 
229+         & self . directories . cargo 
230+     } 
231+ 
223232    pub  fn  mount_cwd ( & self )  -> & str  { 
224233        & self . directories . mount_cwd 
225234    } 
226235
236+     pub  fn  mount_root ( & self )  -> & str  { 
237+         & self . directories . mount_root 
238+     } 
239+ 
227240    pub  fn  host_root ( & self )  -> & Path  { 
228241        & self . directories . host_root 
229242    } 
@@ -499,8 +512,44 @@ pub(crate) fn docker_envvars(
499512    Ok ( ( ) ) 
500513} 
501514
502- pub ( crate )  fn  docker_cwd ( docker :  & mut  Command ,  paths :  & DockerPaths )  -> Result < ( ) >  { 
515+ fn  mount_to_ignore_cargo_config ( 
516+     docker :  & mut  Command , 
517+     paths :  & DockerPaths , 
518+     ignore_cargo_config :  bool , 
519+ )  -> Result < ( ) >  { 
520+     let  check_mount =
521+         |cmd :  & mut  Command ,  host :  & Path ,  mount :  & Path ,  relpath :  & Path | -> Result < ( ) >  { 
522+             let  cargo_dir = relpath. join ( ".cargo" ) ; 
523+             if  host. join ( & cargo_dir) . exists ( )  { 
524+                 // this is fine, since it has to be a POSIX path on the mount. 
525+                 cmd. args ( & [ "-v" ,  & mount. join ( & cargo_dir) . as_posix ( ) ?] ) ; 
526+             } 
527+ 
528+             Ok ( ( ) ) 
529+         } ; 
530+     if  ignore_cargo_config { 
531+         let  mount_root = Path :: new ( paths. mount_root ( ) ) ; 
532+         let  mount_cwd = Path :: new ( paths. mount_cwd ( ) ) ; 
533+         check_mount ( docker,  & paths. cwd ,  mount_cwd,  Path :: new ( "" ) ) ?; 
534+         // CWD isn't guaranteed to be a subdirectory of the mount root. 
535+         if  let  Ok ( mut  relpath)  = mount_cwd. strip_prefix ( mount_root)  { 
536+             while  let  Some ( parent)  = relpath. parent ( )  { 
537+                 check_mount ( docker,  paths. host_root ( ) ,  mount_root,  parent) ?; 
538+                 relpath = parent; 
539+             } 
540+         } 
541+     } 
542+ 
543+     Ok ( ( ) ) 
544+ } 
545+ 
546+ pub ( crate )  fn  docker_cwd ( 
547+     docker :  & mut  Command , 
548+     paths :  & DockerPaths , 
549+     ignore_cargo_config :  bool , 
550+ )  -> Result < ( ) >  { 
503551    docker. args ( & [ "-w" ,  paths. mount_cwd ( ) ] ) ; 
552+     mount_to_ignore_cargo_config ( docker,  paths,  ignore_cargo_config) ?; 
504553
505554    Ok ( ( ) ) 
506555} 
@@ -788,9 +837,6 @@ mod tests {
788837    use  super :: * ; 
789838    use  crate :: id; 
790839
791-     #[ cfg( not( target_os = "windows" ) ) ]  
792-     use  crate :: file:: PathExt ; 
793- 
794840    #[ test]  
795841    fn  test_docker_user_id ( )  { 
796842        let  var = "CROSS_ROOTLESS_CONTAINER_ENGINE" ; 
0 commit comments