cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.79k stars 379 forks source link

How to avoid repeated "downloading component 'rust-std' " #1579

Open dmikushin opened 3 weeks ago

dmikushin commented 3 weeks ago

When running cross-rs from within another Docker container, please provide a clear instruction how to avoid repeated download of rust-std:

info: downloading component 'rust-std' for 'aarch64-unknown-linux-gnu'
info: installing component 'rust-std' for 'aarch64-unknown-linux-gnu'
Emilgardis commented 3 weeks ago

Please provide more detail, what does repeated download of rust-std mean? Does it mean that it keeps downloading it many times in the same invocation, or does it mean that it always downloads the component on new invocation in a new container?

Are you using CROSS_CONTAINER_IN_CONTAINER=1 ?

dmikushin commented 3 weeks ago

@Emilgardis , yes, in my outer Docker I do:

# Set CROSS_CONTAINER_IN_CONTAINER to inform `cross` that it is executed from within a container
ENV CROSS_CONTAINER_IN_CONTAINER=true

Then, I use this container to do:

COMMAND ${DOCKER_EXECUTABLE} run --rm -v "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/${PROJECT_NAME}:/${PROJECT_NAME}" -v "${CMAKE_CURRENT_BINARY_DIR}/target:/${PROJECT_NAME}/target" -w "/${PROJECT_NAME}" -v /var/run/docker.sock:/var/run/docker.sock ${PROJECT_NAME} cross build --release --target=aarch64-unknown-linux-gnu

Important note: I execute docker run again and again to rebuild the Rust project during my development. And each time I rebuild, I see that:

info: downloading component 'rust-std' for 'aarch64-unknown-linux-gnu'
info: installing component 'rust-std' for 'aarch64-unknown-linux-gnu'

My connection is rather fast, but I still experience additional delay from this "rust-std" every time, and I think it could be removed. I think it could be done by mounting the host folder into the outer docker, and then by mounting the same folder down into the cross container. Please tell me what commands and paths I should use.

Emilgardis commented 3 weeks ago

im a bit confused, is this in a docker build? what does COMMAND ${DOCKER_EXECUTABLE} mean?

Are you using cross from the main branch?

dmikushin commented 3 weeks ago

This is CMake, here. I build CMake rules to automate the build process, so that it could fit anywhere that could run CMake, for example into VSCode. It is not relevant to this question.

I kindly ask you to return back to the plot: the cross container is not able to avoid repeated download of rust-std package. There must be an instruction from your side to cache rust-std when cross is launched in CROSS_CONTAINER_IN_CONTAINER mode.

dmikushin commented 3 weeks ago

Are you using cross from the main branch?

I install cross here, this way:

RUN cargo install cross --git https://github.com/cross-rs/cross
Emilgardis commented 3 weeks ago

Ok thank you, I think i have the full context now. Try making RUSTUP_HOME persistant with a volume. /usr/local/rustup