Skip to content

Commit 1b331db

Browse files
committed
Resolve symlinks for cargo and xargo home.
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.
1 parent a82b90b commit 1b331db

File tree

6 files changed

+171
-105
lines changed

6 files changed

+171
-105
lines changed

.changes/947.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"type": "internal",
4+
"description": "resolve symlinks to cargo and xargo home before mounting",
5+
"issues": [373]
6+
},
7+
{
8+
"type": "fixed",
9+
"description": "mount cargo, xargo, and the sysroot at the same path as on the host to avoid unnecessary recompilation.",
10+
"issues": [551]
11+
}
12+
]

src/bin/commands/containers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,23 +451,22 @@ pub fn create_persistent_volume(
451451
docker::remote::copy_volume_container_xargo(
452452
engine,
453453
&container,
454-
&dirs.xargo,
455-
&toolchain_host,
454+
&dirs,
456455
mount_prefix.as_ref(),
457456
msg_info,
458457
)?;
459458
docker::remote::copy_volume_container_cargo(
460459
engine,
461460
&container,
462-
&dirs.cargo,
461+
&dirs,
463462
mount_prefix.as_ref(),
464463
copy_registry,
465464
msg_info,
466465
)?;
467466
docker::remote::copy_volume_container_rust(
468467
engine,
469468
&container,
470-
&toolchain,
469+
&dirs,
471470
None,
472471
mount_prefix.as_ref(),
473472
msg_info,

src/docker/local.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ pub(crate) fn run(
2727
.image
2828
.platform
2929
.specify_platform(&options.engine, &mut docker);
30-
docker_envvars(&mut docker, &options.config, &options.target, msg_info)?;
30+
docker_envvars(
31+
&mut docker,
32+
&options.config,
33+
dirs,
34+
&options.target,
35+
msg_info,
36+
)?;
3137

3238
docker_mount(
3339
&mut docker,
@@ -44,18 +50,28 @@ pub(crate) fn run(
4450
docker_user_id(&mut docker, engine.kind);
4551

4652
docker
47-
.args(&["-v", &format!("{}:/xargo:Z", dirs.xargo.to_utf8()?)])
48-
.args(&["-v", &format!("{}:/cargo:Z", dirs.cargo.to_utf8()?)])
53+
.args(&[
54+
"-v",
55+
&format!("{}:{}:Z", dirs.xargo.to_utf8()?, dirs.xargo_mount_path()),
56+
])
57+
.args(&[
58+
"-v",
59+
&format!("{}:{}:Z", dirs.cargo.to_utf8()?, dirs.cargo_mount_path()),
60+
])
4961
// Prevent `bin` from being mounted inside the Docker container.
50-
.args(&["-v", "/cargo/bin"]);
62+
.args(&["-v", &format!("{}/bin", dirs.cargo_mount_path())]);
5163
docker.args(&[
5264
"-v",
5365
&format!("{}:{}:Z", dirs.host_root.to_utf8()?, dirs.mount_root),
5466
]);
5567
docker
5668
.args(&[
5769
"-v",
58-
&format!("{}:/rust:Z,ro", paths.get_sysroot().to_utf8()?),
70+
&format!(
71+
"{}:{}:Z,ro",
72+
dirs.get_sysroot().to_utf8()?,
73+
dirs.sysroot_mount_path()
74+
),
5975
])
6076
.args(&["-v", &format!("{}:/target:Z", dirs.target.to_utf8()?)]);
6177
docker_cwd(&mut docker, &paths)?;
@@ -84,7 +100,7 @@ pub(crate) fn run(
84100

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

0 commit comments

Comments
 (0)