Skip to content

Commit 47df5c7

Browse files
Merge #994
994: fix path issue r=Alexhuszagh a=Emilgardis fixes #993 ``` + /usr/local/bin/docker buildx build --label 'org.cross-rs.for-cross-target=aarch64-unknown-linux-gnu' --label 'org.cross-rs.runs-with=x86_64-unknown-linux-gnu' --label 'org.cross-rs.workspace_root=/tmp/tmp.cmePkb/workspace' --tag localhost/cross-rs/cross-custom-workspace:aarch64-unknown-linux-gnu-e570c-pre-build --build-arg 'CROSS_CMD=exit' --build-arg 'CROSS_DEB_ARCH=arm64' --file /tmp/tmp.cmePkb/workspace/target/aarch64-unknown-linux-gnu/Dockerfile.aarch64-unknown-linux-gnu-custom --output 'type=docker' /var/lib/docker/overlay2/5b7e7f3b1f39b622d2a665281973f5c1bdc2dce21f33c0bc105ceee253cfbe42/merged/tmp/tmp.cmePkb error: unable to prepare context: path "/var/lib/docker/overlay2/5b7e7f3b1f39b622d2a665281973f5c1bdc2dce21f33c0bc105ceee253cfbe42/merged/tmp/tmp.cmePkb" not found Error: 0: could not run container 1: when building custom image 2: when pre-building 3: `/usr/local/bin/docker buildx build --label 'org.cross-rs.for-cross-target=aarch64-unknown-linux-gnu' --label 'org.cross-rs.runs-with=x86_64-unknown-linux-gnu' --label 'org.cross-rs.workspace_root=/tmp/tmp.cmePkb/workspace' --tag localhost/cross-rs/cross-custom-workspace:aarch64-unknown-linux-gnu-e570c-pre-build --build-arg 'CROSS_CMD=exit' --build-arg 'CROSS_DEB_ARCH=arm64' --file /tmp/tmp.cmePkb/workspace/target/aarch64-unknown-linux-gnu/Dockerfile.aarch64-unknown-linux-gnu-custom --output 'type=docker' /var/lib/docker/overlay2/5b7e7f3b1f39b622d2a665281973f5c1bdc2dce21f33c0bc105ceee253cfbe42/merged/tmp/tmp.cmePkb` failed with exit status: 1 ``` this issue presents because the `--file` arg is wrong Co-authored-by: Emil Gardström <[email protected]>
2 parents 63926ad + 143e366 commit 47df5c7

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

.changes/994.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "fixed",
3+
"description": "fixed wrong path used for target when pre-building in container in container mode",
4+
"issues": [993]
5+
}

ci/test-cross-image.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
3535
cd "${td}"
3636
cross run --target "${TARGET}"
3737
'
38+
td="$(mkcargotemp -d)"
39+
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
40+
cd "${td}"
41+
echo '# Cross.toml
42+
[target.'${TARGET}']
43+
pre-build = ["exit 0"]
44+
' > Cross.toml
45+
docker run --rm -e TARGET -e CROSS_CONTAINER_IN_CONTAINER=1 -e "CROSS_TARGET_${TARGET_UPPER//-/_}_IMAGE" \
46+
-v /var/run/docker.sock:/var/run/docker.sock \
47+
-v $PWD:/mount -w /mount \
48+
"${CROSS_TARGET_CROSS_IMAGE}" cross build --target "${TARGET}"
3849
}
3950

4051
main "${@}"

ci/test-docker-in-docker.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ ci_dir=$(realpath "${ci_dir}")
2323
. "${ci_dir}"/shared.sh
2424

2525
main() {
26-
docker run -v "${PROJECT_HOME}":"${PROJECT_HOME}" -w "${PROJECT_HOME}" \
27-
--rm -e TARGET -e RUSTFLAGS -e RUST_TEST_THREADS \
26+
docker run --platform linux/amd64 -v "${PROJECT_HOME}":"${PROJECT_HOME}" -w "${PROJECT_HOME}" \
27+
--rm -e TARGET -e TARGET_UPPER -e RUSTFLAGS -e RUST_TEST_THREADS \
2828
-e LLVM_PROFILE_FILE -e CARGO_INCREMENTAL \
2929
-e "CROSS_TARGET_${TARGET_UPPER//-/_}_IMAGE" \
3030
-v /var/run/docker.sock:/var/run/docker.sock \
@@ -55,10 +55,14 @@ git clone --depth 1 https://github.com/cross-rs/test-workspace "${td}"
5555
cd "${td}"
5656
cross build --target "${TARGET}" --workspace \
5757
--manifest-path="./workspace/Cargo.toml" --verbose
58+
eval CROSS_TARGET_${TARGET_UPPER//-/_}_PRE_BUILD="exit" cross build --target "${TARGET}" --workspace \
59+
--manifest-path="./workspace/Cargo.toml" --verbose
5860
cd workspace
5961
cross build --target "${TARGET}" --workspace --verbose
62+
eval CROSS_TARGET_${TARGET_UPPER//-/_}_PRE_BUILD="exit" cross build --target "${TARGET}" --workspace --verbose
6063
cd binary
6164
cross run --target "${TARGET}" --verbose
65+
eval CROSS_TARGET_${TARGET_UPPER//-/_}_PRE_BUILD="exit" cross run --target "${TARGET}" --verbose
6266
'
6367
}
6468

src/bin/commands/containers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ pub fn create_persistent_volume(
401401
if let Some(channel) = channel {
402402
toolchain = toolchain.with_picked(&config, channel.clone(), msg_info)?;
403403
};
404-
let (metadata, dirs) = docker::get_package_info(engine, toolchain.clone(), msg_info)?;
404+
let (dirs, metadata) = docker::get_package_info(engine, toolchain.clone(), msg_info)?;
405405
let container = docker::remote::unique_container_identifier(&toolchain_host, &metadata, &dirs)?;
406406
let volume = dirs.toolchain.unique_toolchain_identifier()?;
407407

@@ -490,7 +490,7 @@ pub fn remove_persistent_volume(
490490
if let Some(channel) = channel {
491491
toolchain = toolchain.with_picked(&config, channel.clone(), msg_info)?;
492492
};
493-
let (_, dirs) = docker::get_package_info(engine, toolchain.clone(), msg_info)?;
493+
let (dirs, _) = docker::get_package_info(engine, toolchain.clone(), msg_info)?;
494494
let volume = dirs.toolchain.unique_toolchain_identifier()?;
495495

496496
if !docker::remote::volume_exists(engine, &volume, msg_info)? {

src/docker/shared.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ impl DockerPaths {
201201
toolchain: QualifiedToolchain,
202202
) -> Result<Self> {
203203
let mount_finder = MountFinder::create(engine)?;
204-
let directories = Directories::create(&mount_finder, &metadata, &cwd, toolchain)?;
204+
let (directories, metadata) =
205+
Directories::assemble(&mount_finder, metadata, &cwd, toolchain)?;
205206
Ok(Self {
206207
mount_finder,
207208
metadata,
@@ -259,12 +260,12 @@ pub struct Directories {
259260
}
260261

261262
impl Directories {
262-
pub fn create(
263+
pub fn assemble(
263264
mount_finder: &MountFinder,
264-
metadata: &CargoMetadata,
265+
mut metadata: CargoMetadata,
265266
cwd: &Path,
266267
mut toolchain: QualifiedToolchain,
267-
) -> Result<Self> {
268+
) -> Result<(Self, CargoMetadata)> {
268269
let home_dir =
269270
home::home_dir().ok_or_else(|| eyre::eyre!("could not find home directory"))?;
270271
let cargo = home::cargo_home()?;
@@ -313,7 +314,7 @@ impl Directories {
313314

314315
let cargo = mount_finder.find_mount_path(cargo);
315316
let xargo = mount_finder.find_mount_path(xargo);
316-
let target = mount_finder.find_mount_path(target);
317+
metadata.target_directory = mount_finder.find_mount_path(target);
317318

318319
// root is either workspace_root, or, if we're outside the workspace root, the current directory
319320
let host_root = mount_finder.find_mount_path(if metadata.workspace_root.starts_with(cwd) {
@@ -332,19 +333,22 @@ impl Directories {
332333
// canonicalize these once to avoid syscalls
333334
let sysroot_mount_path = toolchain.get_sysroot().as_posix_absolute()?;
334335

335-
Ok(Directories {
336-
cargo,
337-
xargo,
338-
target,
339-
nix_store,
340-
host_root,
341-
mount_root,
342-
mount_cwd,
343-
toolchain,
344-
cargo_mount_path,
345-
xargo_mount_path,
346-
sysroot_mount_path,
347-
})
336+
Ok((
337+
Directories {
338+
cargo,
339+
xargo,
340+
target: metadata.target_directory.clone(),
341+
nix_store,
342+
host_root,
343+
mount_root,
344+
mount_cwd,
345+
toolchain,
346+
cargo_mount_path,
347+
xargo_mount_path,
348+
sysroot_mount_path,
349+
},
350+
metadata,
351+
))
348352
}
349353

350354
pub fn get_sysroot(&self) -> &Path {
@@ -422,14 +426,12 @@ pub fn get_package_info(
422426
engine: &Engine,
423427
toolchain: QualifiedToolchain,
424428
msg_info: &mut MessageInfo,
425-
) -> Result<(CargoMetadata, Directories)> {
429+
) -> Result<(Directories, CargoMetadata)> {
426430
let metadata = cargo_metadata_with_args(None, None, msg_info)?
427431
.ok_or(eyre::eyre!("unable to get project metadata"))?;
428432
let mount_finder = MountFinder::create(engine)?;
429433
let cwd = std::env::current_dir()?;
430-
let dirs = Directories::create(&mount_finder, &metadata, &cwd, toolchain)?;
431-
432-
Ok((metadata, dirs))
434+
Directories::assemble(&mount_finder, metadata, &cwd, toolchain)
433435
}
434436

435437
/// Register binfmt interpreters
@@ -1114,12 +1116,12 @@ mod tests {
11141116
}
11151117

11161118
fn get_directories(
1117-
metadata: &CargoMetadata,
1119+
metadata: CargoMetadata,
11181120
mount_finder: &MountFinder,
1119-
) -> Result<Directories> {
1121+
) -> Result<(Directories, CargoMetadata)> {
11201122
let cwd = get_cwd()?;
11211123
let toolchain = get_toolchain()?;
1122-
Directories::create(mount_finder, metadata, &cwd, toolchain)
1124+
Directories::assemble(mount_finder, metadata, &cwd, toolchain)
11231125
}
11241126

11251127
#[track_caller]
@@ -1134,7 +1136,7 @@ mod tests {
11341136
let vars = unset_env();
11351137
let mount_finder = MountFinder::new(vec![]);
11361138
let metadata = cargo_metadata(false, &mut MessageInfo::default())?;
1137-
let directories = get_directories(&metadata, &mount_finder)?;
1139+
let (directories, metadata) = get_directories(metadata, &mount_finder)?;
11381140
paths_equal(&directories.cargo, &home()?.join(".cargo"))?;
11391141
paths_equal(&directories.xargo, &home()?.join(".xargo"))?;
11401142
paths_equal(&directories.host_root, &metadata.workspace_root)?;
@@ -1179,7 +1181,7 @@ mod tests {
11791181

11801182
let mount_finder = MountFinder::create(&engine)?;
11811183
let metadata = cargo_metadata(true, &mut msg_info)?;
1182-
let directories = get_directories(&metadata, &mount_finder)?;
1184+
let (directories, _) = get_directories(metadata, &mount_finder)?;
11831185
let mount_finder = MountFinder::new(docker_read_mount_paths(&engine)?);
11841186
let mount_path = |p| mount_finder.find_mount_path(p);
11851187

0 commit comments

Comments
 (0)