Skip to content

Commit

Permalink
Merge #836
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and Alexhuszagh authored Jun 22, 2022
2 parents 426d135 + f046ff5 commit cc61dc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- #836 - write a `CACHEDIR.TAG` when creating the target directory, similar to `cargo`.
- #804 - allow usage of env `CARGO_BUILD_TARGET` as an alias for `CROSS_BUILD_TARGET`
- #792 - fixed container-in-container support when using podman.
- #781 - ensure `target.$(...)` config options override `build` ones.
Expand Down
20 changes: 19 additions & 1 deletion src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Directories {
// otherwise `docker` will create them but they will be owned by `root`
fs::create_dir(&cargo).ok();
fs::create_dir(&xargo).ok();
fs::create_dir(&target).ok();
create_target_dir(target)?;

let cargo = mount_finder.find_mount_path(cargo);
let xargo = mount_finder.find_mount_path(xargo);
Expand Down Expand Up @@ -111,6 +111,24 @@ impl Directories {
}
}

const CACHEDIR_TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cross.
# For information about cache directory tags see https://bford.info/cachedir/";

fn create_target_dir(path: &Path) -> Result<()> {
// cargo creates all paths to the target directory, and writes
// a cache dir tag only if the path doesn't previously exist.
if !path.exists() {
fs::create_dir_all(&path)?;
fs::OpenOptions::new()
.write(true)
.create_new(true)
.open(&path.join("CACHEDIR.TAG"))?
.write_all(CACHEDIR_TAG.as_bytes())?;
}
Ok(())
}

pub fn command(engine: &Engine) -> Command {
Command::new(&engine.path)
}
Expand Down

0 comments on commit cc61dc8

Please sign in to comment.