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

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

Open
dj8yfo opened this issue Feb 17, 2025 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@dj8yfo
Copy link
Collaborator

dj8yfo commented Feb 17, 2025

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)

@dj8yfo dj8yfo added duplicate This issue or pull request already exists enhancement New feature or request and removed duplicate This issue or pull request already exists labels Feb 17, 2025
@dj8yfo dj8yfo changed the title feat: supply external cache to reproducible-build with cargo-near feat: supply external cache to build reproducible-wasm with cargo-near Feb 17, 2025
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Feb 17, 2025

did some tests of sketch implementation in dj8yfo@f70a32c on https://github.com/dj8yfo/factory-rust/tree/stable_0.4.4

This leaves EC modified after run:

doing

cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target' --manifest-path product-donation/Cargo.toml

This saves around 12-13s on builds themselves (can be seen in the log, that dev + release stages 2nd time rerun are < 0.5s), but takes anywhere in the range of
23-35sec total on rebuilding ~/.cargo/registry and the like in the container, likely depends on network speed at the time of run.

Doing

(
cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target'
  --pass-docker-volume /home/jerrick/.cargo/.crates2.json:/home/near/.cargo/.crates2.json
  --pass-docker-volume /home/jerrick/.cargo/.crates.toml:/home/near/.cargo/.crates.toml
  --pass-docker-volume /home/jerrick/.cargo/git:/home/near/.cargo/git
  --pass-docker-volume /home/jerrick/.cargo/registry/cache:/home/near/.cargo/registry/cache
  --pass-docker-volume /home/jerrick/.cargo/registry/index:/home/near/.cargo/registry/index
  --manifest-path product-donation/Cargo.toml
  )

doesn't really budge quickly, it fails with some unclear permission errors.

Also i ran

cargo near build reproducible-wasm --manifest-path factory/Cargo.toml
vs
cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target' --manifest-path factory/Cargo.toml

after the initial cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target' --manifest-path product-donation/Cargo.tom. Didn't see any cut on saving a ton of resources by recompiling the same packages by compiling 2 crates in a single workspace with shared target, the first was 3m 15s, the second one - 3m 25s.

Also, if sccache gh action does anything else beyond what Swatinem/rust-cache does, it'll probably will have to be built into containers and export RUSTC_WRAPPER=/path/to/sccache added to their dockerfiles.

And, of course, this command by itself cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target' --manifest-path product-donation/Cargo.toml fails after docker build due to the target dir being expected to be at a different location than actual, which can be adjusted for/fixed

Image

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Feb 17, 2025

ok , this one

(
cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target'
# .cargo/bin has to be skipped
  --pass-docker-volume /home/jerrick/.cargo/.crates2.json:/home/near/.cargo/.crates2.json
  --pass-docker-volume /home/jerrick/.cargo/.crates.toml:/home/near/.cargo/.crates.toml
  --pass-docker-volume /home/jerrick/.cargo/git:/home/near/.cargo/git
  --pass-docker-volume /home/jerrick/.cargo/registry:/home/near/.cargo/registry
  --manifest-path product-donation/Cargo.toml
  )

doesn't result in permission errors and it takes 1s on rerun.

doing the following after product-donation/Cargo.toml has been built

(
cargo near build reproducible-wasm --pass-docker-volume './target:/home/near/code/target'
  --pass-docker-volume /home/jerrick/.cargo/.crates2.json:/home/near/.cargo/.crates2.json
  --pass-docker-volume /home/jerrick/.cargo/.crates.toml:/home/near/.cargo/.crates.toml
  --pass-docker-volume /home/jerrick/.cargo/git:/home/near/.cargo/git
  --pass-docker-volume /home/jerrick/.cargo/registry:/home/near/.cargo/registry
  --manifest-path factory/Cargo.toml
  )

takes 2m 50 s ,
and running it once more takes 8s .

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Feb 17, 2025

this depends on running mkdir ./target/ first, otherwise there's a permission error, likely it will also require mkdir ~/.cargo/registry/src in a CI setting to avoid permission errors

@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Feb 17, 2025

preliminary check shows this doesn't affect wasm hashes in an edge case

# with --pass-docker-volume: sha256sum target/near/donation/donation.wasm
e5b564bb863171a8e87df0ebb8f3f1f56ef60d0172c47a284b25ab6668d96d04  target/near/donation/donation.wasm
                                                                                                                                                                        
❯ : sha256sum target/near/factory/factory.wasm
fbd1c304d3bd2d1be4aa852e1a7dd4b4aceefc3a7d8de759c65a182c011ad22b  target/near/factory/factory.wasm
# without --pass-docker-volume: sha256sum target/near/donation/donation.wasm
e5b564bb863171a8e87df0ebb8f3f1f56ef60d0172c47a284b25ab6668d96d04  target/near/donation/donation.wasm
                                                                                                                                                                        
❯ : sha256sum target/near/factory/factory.wasm
fbd1c304d3bd2d1be4aa852e1a7dd4b4aceefc3a7d8de759c65a182c011ad22b  target/near/factory/factory.wasm

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

No branches or pull requests

1 participant