Skip to content

Commit cc61dc8

Browse files
Merge #836
836: Add a cache dir tag when creating a target directory. r=Emilgardis a=Alexhuszagh Ensure `cross` is similar in functionality to `cargo`, and this minimizes network traffic by applications that may copy the project but do not wish to copy compiled code. Closes #835. Co-authored-by: Alex Huszagh <[email protected]>
2 parents 426d135 + f046ff5 commit cc61dc8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4848

4949
### Fixed
5050

51+
- #836 - write a `CACHEDIR.TAG` when creating the target directory, similar to `cargo`.
5152
- #804 - allow usage of env `CARGO_BUILD_TARGET` as an alias for `CROSS_BUILD_TARGET`
5253
- #792 - fixed container-in-container support when using podman.
5354
- #781 - ensure `target.$(...)` config options override `build` ones.

src/docker/shared.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Directories {
6262
// otherwise `docker` will create them but they will be owned by `root`
6363
fs::create_dir(&cargo).ok();
6464
fs::create_dir(&xargo).ok();
65-
fs::create_dir(&target).ok();
65+
create_target_dir(target)?;
6666

6767
let cargo = mount_finder.find_mount_path(cargo);
6868
let xargo = mount_finder.find_mount_path(xargo);
@@ -111,6 +111,24 @@ impl Directories {
111111
}
112112
}
113113

114+
const CACHEDIR_TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55
115+
# This file is a cache directory tag created by cross.
116+
# For information about cache directory tags see https://bford.info/cachedir/";
117+
118+
fn create_target_dir(path: &Path) -> Result<()> {
119+
// cargo creates all paths to the target directory, and writes
120+
// a cache dir tag only if the path doesn't previously exist.
121+
if !path.exists() {
122+
fs::create_dir_all(&path)?;
123+
fs::OpenOptions::new()
124+
.write(true)
125+
.create_new(true)
126+
.open(&path.join("CACHEDIR.TAG"))?
127+
.write_all(CACHEDIR_TAG.as_bytes())?;
128+
}
129+
Ok(())
130+
}
131+
114132
pub fn command(engine: &Engine) -> Command {
115133
Command::new(&engine.path)
116134
}

0 commit comments

Comments
 (0)