Skip to content

feat: add Docker volume cache mounting for reproducible builds#385

Open
Copilot wants to merge 6 commits intomainfrom
copilot/add-external-cache-support
Open

feat: add Docker volume cache mounting for reproducible builds#385
Copilot wants to merge 6 commits intomainfrom
copilot/add-external-cache-support

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Adds opt-in cache mounting to speed up sequential reproducible builds in workspaces and CI/CD by reusing compiled dependencies and downloaded crates across Docker container invocations.

Changes

  • CLI flags: Added --mount-target-cache and --mount-cargo-cache to cargo near build reproducible-wasm

    • Both default to false for backward compatibility
    • Also available in cargo near deploy reproducible-wasm via flag flattening
  • Volume mounting: Extended additional_docker_args() to construct volume mounts when flags are enabled

    • ./target/target_cache with CARGO_TARGET_DIR=/target_cache
    • ~/.cargo/usr/local/cargo (standard CARGO_HOME in Rust images)
    • Handles CARGO_HOME env var and cross-platform home directory detection
  • Documentation: Added README section explaining cache flags and reproducibility trade-offs

Usage

# Sequential workspace builds with shared cache
cd omni-bridge
cargo near build reproducible-wasm --mount-target-cache --mount-cargo-cache
cd ../another-contract
cargo near build reproducible-wasm --mount-target-cache --mount-cargo-cache

Cache reuse pattern: EC → 1EC, EC → 2EC, EC → 3EC where EC is external cache, enabling significant build time reduction when building multiple contracts or rebuilding the same contract.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • docs.rs
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • s3-us-west-1.amazonaws.com
    • Triggering command: /home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build /home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build -static -I 64-REDACTED-linux-gnu/bin/rust-lld -I ./vendor/dbus/ -Wall -Wextra -UDBUS_DISABLE_CHECKS -UWORDS_BIGENDIAN -UHAVE_GETPEERUCRED -UHAVE_CMSGCRED --64�� /rust/working/target/debug/build--gdwarf-4 22-dbus-file-unix.o (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>feat: supply external cache to build reproducible-wasm with cargo-near</issue_title>
<issue_description>relates to #301

this should at first try to pass external ./target dir to the right place into container, and then, if that can be made to work, ~/.cargo folder too

    /Users/runner/.cargo/bin
    /Users/runner/.cargo/.crates2.json
    /Users/runner/.cargo/.crates.toml
    /Users/runner/.cargo/git
    /Users/runner/.cargo/registry/cache
    /Users/runner/.cargo/registry/index
    ./target

NOTE: original discussion of docker volumes somewhere in tg only mentioned rebuilding the same crate after initial
build for reduced build times, the task has had an obvious scope extension, where a sequence of builds of crates in the same workspace have to be passed initial cache, and then all built sequentially, while sharing the same cache.
Original description:
1i -> 1C
(C stands for Cache, 1i is non-cached build of crate 1, 1C is cached build of crate 1 with cache obtained during 1i )
Extended description:
sequential build of multiple crates or workspace: EC -> 1EC , EC -> 2EC, EC -> 3EC ...
(EC stands for External Cache, 1EC is cached build of crate 1 with cache supplied externally)</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 14, 2026 00:22
…ache

Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Copilot AI changed the title [WIP] Add external cache support for reproducible-wasm builds feat: add Docker volume cache mounting for reproducible builds Jan 14, 2026
Copilot AI requested a review from r-near January 14, 2026 00:32
@r-near r-near marked this pull request as ready for review January 16, 2026 18:10
@r-near r-near requested a review from a team as a code owner January 16, 2026 18:10
Copilot AI review requested due to automatic review settings January 16, 2026 18:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds optional Docker volume cache mounting to speed up sequential reproducible builds in workspaces and CI/CD environments by reusing compiled dependencies and downloaded crates across container invocations.

Changes:

  • Added --mount-target-cache and --mount-cargo-cache CLI flags with default false for backward compatibility
  • Extended Docker volume mounting logic to map local ./target and ~/.cargo directories into containers
  • Added README documentation explaining cache flags and reproducibility trade-offs

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
cargo-near/src/commands/build/actions/reproducible_wasm/mod.rs Added mount_target_cache and mount_cargo_cache boolean fields to BuildOpts and propagated them through conversion functions
cargo-near-build/src/types/near/docker_build/mod.rs Added mount_target_cache and mount_cargo_cache fields to DockerBuildOpts struct
cargo-near-build/src/near/docker_build/mod.rs Implemented additional_docker_args function to construct volume mounts and environment variables when cache flags are enabled
README.md Added "Caching for faster builds" section documenting the new flags and reproducibility caveats

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +171 to +182
let cargo_home = std::env::var("CARGO_HOME")
.or_else(|_| {
std::env::var("HOME")
.or_else(|_| std::env::var("USERPROFILE"))
.map(|home| format!("{}/.cargo", home))
})
.map_err(|_| eyre::eyre!("Failed to determine CARGO_HOME or ~/.cargo directory"))?;

let cargo_home_str = dunce::canonicalize(&cargo_home)
.map_err(|e| eyre::eyre!("Failed to canonicalize cargo home {:?}: {}", cargo_home, e))?
.to_string_lossy()
.to_string();
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cargo home directory is not created before calling dunce::canonicalize, unlike the target directory (lines 141-143). If the directory doesn't exist (e.g., on a fresh system), canonicalize will fail. Add std::fs::create_dir_all(&cargo_home) before the canonicalize call, similar to the target directory handling.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: supply external cache to build reproducible-wasm with cargo-near

3 participants