Skip to content

Commit

Permalink
Resolve symlinks for cargo and xargo home.
Browse files Browse the repository at this point in the history
Resolve symlinks for the xargo and cargo home (as well as the Nix store) prior to mounting, since they are mounted at a fixed location anyway. This is because podman mounts symlinks as root by default. We always canonicalize the paths on the host, after creating them, to ensure that any symlinks are resolved.

Say we have `/path/to/home`, and `/path/to` is a symlink but `/path/to/home` doesn't exist yet. Trying to canonicalize `/path/to/home/.xargo` will fail, and will still be a symlink if we maybe canonicalize before. First creating the directories and canonicalizing them on the host should always work.

Change the mount points from `/cargo`, `/xargo`, and `/rust` to the same paths as on the host, which avoids unnecessary recompilation when `cargo` and `cross` are intermittently used.
  • Loading branch information
Alexhuszagh committed Jul 16, 2022
1 parent a82b90b commit 63829b5
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 107 deletions.
12 changes: 12 additions & 0 deletions .changes/947.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"type": "internal",
"description": "resolve symlinks to cargo and xargo home before mounting",
"issues": [373]
},
{
"type": "fixed",
"description": "mount cargo, xargo, and the sysroot at the same path as on the host to avoid unnecessary recompilation.",
"issues": [551]
}
]
7 changes: 3 additions & 4 deletions src/bin/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,23 +451,22 @@ pub fn create_persistent_volume(
docker::remote::copy_volume_container_xargo(
engine,
&container,
&dirs.xargo,
&toolchain_host,
&dirs,
mount_prefix.as_ref(),
msg_info,
)?;
docker::remote::copy_volume_container_cargo(
engine,
&container,
&dirs.cargo,
&dirs,
mount_prefix.as_ref(),
copy_registry,
msg_info,
)?;
docker::remote::copy_volume_container_rust(
engine,
&container,
&toolchain,
&dirs,
None,
mount_prefix.as_ref(),
msg_info,
Expand Down
6 changes: 6 additions & 0 deletions src/docker/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ impl ImagePlatform {
}
}

impl Default for ImagePlatform {
fn default() -> ImagePlatform {
ImagePlatform::DEFAULT
}
}

impl TryFrom<&str> for ImagePlatform {
type Error = <Self as std::str::FromStr>::Err;

Expand Down
28 changes: 22 additions & 6 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ pub(crate) fn run(
.image
.platform
.specify_platform(&options.engine, &mut docker);
docker_envvars(&mut docker, &options.config, &options.target, msg_info)?;
docker_envvars(
&mut docker,
&options.config,
dirs,
&options.target,
msg_info,
)?;

docker_mount(
&mut docker,
Expand All @@ -44,18 +50,28 @@ pub(crate) fn run(
docker_user_id(&mut docker, engine.kind);

docker
.args(&["-v", &format!("{}:/xargo:Z", dirs.xargo.to_utf8()?)])
.args(&["-v", &format!("{}:/cargo:Z", dirs.cargo.to_utf8()?)])
.args(&[
"-v",
&format!("{}:{}:Z", dirs.xargo.to_utf8()?, dirs.xargo_mount_path()),
])
.args(&[
"-v",
&format!("{}:{}:Z", dirs.cargo.to_utf8()?, dirs.cargo_mount_path()),
])
// Prevent `bin` from being mounted inside the Docker container.
.args(&["-v", "/cargo/bin"]);
.args(&["-v", &format!("{}/bin", dirs.cargo_mount_path())]);
docker.args(&[
"-v",
&format!("{}:{}:Z", dirs.host_root.to_utf8()?, dirs.mount_root),
]);
docker
.args(&[
"-v",
&format!("{}:/rust:Z,ro", paths.get_sysroot().to_utf8()?),
&format!(
"{}:{}:Z,ro",
dirs.get_sysroot().to_utf8()?,
dirs.sysroot_mount_path()
),
])
.args(&["-v", &format!("{}:/target:Z", dirs.target.to_utf8()?)]);
docker_cwd(&mut docker, &paths)?;
Expand Down Expand Up @@ -84,7 +100,7 @@ pub(crate) fn run(

docker
.arg(&image_name)
.args(&["sh", "-c", &format!("PATH=$PATH:/rust/bin {:?}", cmd)])
.args(&["sh", "-c", &build_command(dirs, &cmd)])
.run_and_get_status(msg_info, false)
.map_err(Into::into)
}
Loading

0 comments on commit 63829b5

Please sign in to comment.