Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CACHEDIR.TAG is not written when using custom docker image #1324

Closed
4 of 11 tasks
vaffeine opened this issue Aug 30, 2023 · 1 comment · Fixed by #1325
Closed
4 of 11 tasks

CACHEDIR.TAG is not written when using custom docker image #1324

vaffeine opened this issue Aug 30, 2023 · 1 comment · Fixed by #1325
Labels

Comments

@vaffeine
Copy link
Contributor

vaffeine commented Aug 30, 2023

Checklist

Describe your issue

Cross doesn't write CACHEDIR.TAG file when using a custom docker image, e.g. having a pre-build step in Cross.toml. The file is created if no custom image is used.

Steps to reproduce:

  1. Create an empty cargo project
  2. Create a Cross.toml with the following content
[target.x86_64-unknown-linux-gnu]
pre-build = ["echo"]
  1. Run cross build --target x86_64-unknown-linux-gnu
  2. There is no CACHEDIR.TAG in target/x86_64-unknown-linux-gnu/

I have encountered this issue while investigating why https://github.com/Swatinem/rust-cache was not caching cross-compilation targets during CI builds. rust-cache uses CACHEDIR.TAG to detect sub-target directories that need to be cached and stopped doing that after we have switched from cargo to cross.

I had a brief look into it and it looks like the code that writes CACHETAG.DIR (added in #836) doesn't write it if the target directory already exists (assumption is that it was created by cargo). However, from my debugging it looks like this directory is created before this check by Dockerfile::build. Which causes the target directory to only have Dockerfile.*-custom file.

I can submit a PR that changes the check in fn create_target_dir from if !path.exists() to if !cachedir_file.exists(), but wanted to check if there is a better way to fix it since I only did a very shallow analysis of the issue.

Relates to #835.

What target(s) are you cross-compiling for?

aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.5

Example

No response

Additional information / notes

No response

@Emilgardis
Copy link
Member

Well spotted! This should probably be solved by writing the tag when writing the Dockerfile, feel free to create a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants