Skip to main content

ic_testkit/artifacts/
mod.rs

1//! Host-side artifact discovery, freshness, and Wasm build helpers.
2//!
3//! These functions keep integration-test artifacts in caller-selected target
4//! directories and contain no application-specific package or profile policy.
5//! Independent Wasm batches remain sequential; [`WasmBuildSession`] adds
6//! explicit cross-call resolution reuse, while [`WasmBuildInputSnapshot`]
7//! prepares a fixed specification set for concurrent readers. Both require a
8//! caller-held source lease.
9//!
10//! Successful Wasm and generic artifact records retain their read-only exact
11//! paths against cache replacement and pruning. Retain the record (or a clone)
12//! through consumption; paths and artifact descriptors alone carry no ownership.
13//! Batch reports own their successful records even when later entries fail.
14//!
15//! ```no_run
16//! use ic_testkit::artifacts::{
17//!     ArtifactCacheOutcome, ArtifactCachePreparation, ArtifactCacheSpec,
18//!     WasmBuildSpec, build_wasm_canisters_cached, prepare_artifact_cache,
19//! };
20//! use std::path::Path;
21//!
22//! fn build_deployable(spec: &WasmBuildSpec, post_cache: &Path, destination: &Path)
23//!     -> Result<Vec<u8>, Box<dyn std::error::Error>>
24//! {
25//!     let wasm = build_wasm_canisters_cached(spec)?;
26//!     let input = &wasm.record().artifacts()[0];
27//!     let post_spec = ArtifactCacheSpec::new(post_cache, "deploy", "copy/v1")
28//!         .with_input("wasm", input)
29//!         .with_output("deploy", destination);
30//!     let deploy = match prepare_artifact_cache(&post_spec)? {
31//!         ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
32//!         ArtifactCachePreparation::Build(transaction) => {
33//!             // A real post-link recipe can write transformed bytes to
34//!             // transaction.output_path("deploy") instead of copying.
35//!             transaction.import_output("deploy", input)?;
36//!             transaction.commit()?
37//!         }
38//!     };
39//!     drop(wasm); // The post-link transaction has finished consuming the input.
40//!     let bytes = std::fs::read(deploy.record().artifacts()[0].path())?;
41//!     drop(deploy); // Reading is complete; maintenance may now reclaim it.
42//!     Ok(bytes)
43//! }
44//! ```
45
46mod cache_fs;
47mod digest;
48mod icp;
49mod tool;
50mod transaction;
51mod transaction_batch;
52mod wasm;
53mod wasm_batch;
54mod wasm_cache;
55mod workspace;
56
57#[cfg(test)]
58mod test_support;
59
60pub use cache_fs::{ArtifactCacheMaintenance, ArtifactCachePrunePolicy, ArtifactCachePruneReport};
61pub use digest::InputDigest;
62pub use icp::{
63    WatchedInputSnapshot, icp_artifact_ready_for_build, icp_artifact_ready_with_snapshot,
64};
65pub use tool::resolve_executable;
66pub use transaction::{
67    ArtifactBuildTransaction, ArtifactCacheArtifact, ArtifactCacheError, ArtifactCacheOutcome,
68    ArtifactCachePreparation, ArtifactCacheRecord, ArtifactCacheSpec, ArtifactCacheTimings,
69    ArtifactOutputValidation, prepare_artifact_cache, prune_artifact_cache,
70};
71pub use transaction_batch::{
72    ArtifactCacheBatchContractError, ArtifactCacheBatchEntry, ArtifactCacheBatchFailedEntry,
73    ArtifactCacheBatchFailure, ArtifactCacheBatchFailurePhase, ArtifactCacheBatchFailureTimings,
74    ArtifactCacheBatchMetrics, ArtifactCacheBatchOutcomeEntry, ArtifactCacheBatchReport,
75    LabeledArtifactCacheSpec, build_artifact_caches_batch,
76};
77pub use wasm::{read_wasm, wasm_artifacts_ready, wasm_path};
78pub use wasm_batch::{
79    LabeledWasmBuildSpec, WasmBuildBatchConfig, WasmBuildBatchContractError, WasmBuildBatchEntry,
80    WasmBuildBatchFailure, WasmBuildBatchMaintenanceEntry, WasmBuildBatchMetrics,
81    WasmBuildBatchOutcomeEntry, WasmBuildBatchProgressEvent, WasmBuildBatchReport,
82    WasmBuildInputSnapshot, WasmBuildInputSnapshotMetrics, WasmBuildSession,
83    WasmBuildSessionMetrics, build_wasm_canisters_cached_batch,
84    build_wasm_canisters_cached_batch_with_config,
85    build_wasm_canisters_cached_batch_with_config_and_progress,
86    build_wasm_canisters_cached_batch_with_progress,
87};
88pub use wasm_cache::{
89    CargoBuildInput, ResolvedCargoBuildInputs, SharedIncrementalTargetInspection,
90    SharedIncrementalTargetMaintenance, SharedIncrementalTargetMaintenanceConfig,
91    SharedIncrementalTargetMaintenanceFailureMode, SharedIncrementalTargetMaintenanceOutcome,
92    SharedIncrementalTargetPrunePolicy, WasmBuildCacheMode, WasmBuildError,
93    WasmBuildFailureDetails, WasmBuildFailurePhase, WasmBuildFailureTimings, WasmBuildOutcome,
94    WasmBuildOutputStream, WasmBuildPhase, WasmBuildProgressConfig, WasmBuildProgressEvent,
95    WasmBuildProgressOutcome, WasmBuildProgressPhase, WasmBuildRecord, WasmBuildSpec,
96    WasmBuildTimings, WasmInputResolutionTimings, build_wasm_canisters_cached,
97    build_wasm_canisters_cached_with_progress, inspect_shared_incremental_target,
98    maintain_shared_incremental_target, maintain_shared_incremental_target_at_most_every,
99    prune_wasm_build_cache, resolve_cargo_build_inputs,
100};
101pub use workspace::{test_target_dir, workspace_root_for};