pub struct ArtifactCacheSpec { /* private fields */ }Expand description
Complete caller-owned description of one transactional artifact set.
Declared inputs and tools must not be located inside cache_root. Output
destinations must remain outside it, resolve to distinct non-nested paths,
and not overlap a declared input or tool. Cargo-derived cache/output paths must
likewise remain outside resolved inputs unless covered by their exact
generated-state exclusions.
Implementations§
Source§impl ArtifactCacheSpec
impl ArtifactCacheSpec
Sourcepub fn new(cache_root: &Path, namespace: &str, recipe_id: &str) -> Self
pub fn new(cache_root: &Path, namespace: &str, recipe_id: &str) -> Self
Describe one external artifact recipe using non-secret stable identifiers.
The namespace selects an independent content store. recipe_id must be
bumped whenever undeclared pipeline semantics change. The default
coordination scope is the namespace.
Examples found in repository?
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub fn with_coordination_scope(self, coordination_scope: &str) -> Self
pub fn with_coordination_scope(self, coordination_scope: &str) -> Self
Serialize recipes that share caller-owned mutable external build state.
Sourcepub fn with_input(self, label: &str, path: &Path) -> Self
pub fn with_input(self, label: &str, path: &Path) -> Self
Add one exact input file or directory outside the cache root under a stable label.
Examples found in repository?
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub fn with_tool(self, label: &str, path: &Path) -> Self
pub fn with_tool(self, label: &str, path: &Path) -> Self
Add one exact executable or tool path outside the cache root under a stable label.
Examples found in repository?
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub fn with_arguments<I, S>(self, arguments: I) -> Self
pub fn with_arguments<I, S>(self, arguments: I) -> Self
Set OS-native ordered command arguments that contribute to the content key.
Examples found in repository?
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub fn with_environment<I, K, V>(self, environment: I) -> Self
pub fn with_environment<I, K, V>(self, environment: I) -> Self
Set OS-native environment values that contribute to the content key.
This records identity only. The caller must apply these values to the external command executed on a cache miss.
Sourcepub fn with_unset_environment<I, S>(self, names: I) -> Self
pub fn with_unset_environment<I, S>(self, names: I) -> Self
Record OS-native environment names whose unset state contributes to the content key.
The caller must also remove these names from the external command’s environment on a cache miss.
Sourcepub fn with_identity_bytes(self, label: &str, value: &[u8]) -> Self
pub fn with_identity_bytes(self, label: &str, value: &[u8]) -> Self
Add opaque non-secret identity bytes under a stable logical label.
Labels are stored in canonical order; declaration order does not affect identity.
Sourcepub fn with_cargo_build_inputs(
self,
label: &str,
build_spec: &WasmBuildSpec,
resolved: &ResolvedCargoBuildInputs,
) -> Self
pub fn with_cargo_build_inputs( self, label: &str, build_spec: &WasmBuildSpec, resolved: &ResolvedCargoBuildInputs, ) -> Self
Add one exact Cargo input snapshot as transactional cache identity and guard.
The semantic resolved fingerprint keys toolchain, arguments, environment and the selected dependency closure. Its conservative Cargo-aware validation paths and exclusions are rehashed automatically during preparation, cache-hit materialization and transaction commit. Labels are stored in canonical order; declaration order does not affect identity.
Sourcepub fn with_output(self, name: &str, destination: &Path) -> Self
pub fn with_output(self, name: &str, destination: &Path) -> Self
Declare one nonempty regular-file output and its nonoverlapping public destination.
Examples found in repository?
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub fn with_output_validation(
self,
name: &str,
destination: &Path,
validation: ArtifactOutputValidation,
) -> Self
pub fn with_output_validation( self, name: &str, destination: &Path, validation: ArtifactOutputValidation, ) -> Self
Declare one output, nonoverlapping public destination, and validation policy.
Sourcepub const fn with_prune_policy(self, policy: ArtifactCachePrunePolicy) -> Self
pub const fn with_prune_policy(self, policy: ArtifactCachePrunePolicy) -> Self
Apply best-effort retention while protecting the acquired entry.
Examples found in repository?
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
17 let [tool, sha256, version, input, output, cache_root] = arguments.as_slice() else {
18 eprintln!(
19 "usage: transactional_artifact_cache <tool-path> <sha256> <exact-version-stdout> <input> <public-output> <cache-root>"
20 );
21 return Ok(());
22 };
23 let current_dir = std::env::current_dir()?;
24 let tool = resolve_executable(¤t_dir.join(tool), ¤t_dir, &[])?;
25 let context = ExecutionContext {
26 current_dir: ¤t_dir,
27 environment: &[],
28 };
29 let limits = OutputLimits {
30 stdout: OutputLimit::Terminate(64 * 1024),
31 stderr: OutputLimit::Terminate(64 * 1024),
32 timeout: Some(Duration::from_secs(60)),
33 };
34 // Admission uses caller authority, never a digest computed from untrusted
35 // selected bytes. Transform tools must work with this empty environment.
36 let admitted = AdmittedTool::admit(
37 &ToolSpec {
38 executable: &tool,
39 sha256: sha256
40 .to_str()
41 .ok_or("SHA-256 must be UTF-8")?
42 .parse::<Sha256Digest>()?,
43 executable_bytes: 256 * 1024 * 1024,
44 version_arguments: &["--version".into()],
45 version_identity: version.to_str().ok_or("version must be UTF-8")?,
46 },
47 &context,
48 limits,
49 )?;
50 let input = current_dir.join(input);
51 let output = current_dir.join(output);
52 let cache_root = current_dir.join(cache_root);
53 let spec = ArtifactCacheSpec::new(
54 &cache_root,
55 "example-transform",
56 "example/admitted-transform/v1",
57 )
58 .with_input("source", &input)
59 .with_tool("transformer", &tool)
60 .with_arguments(["<input>", "<output>"])
61 .with_output("result", &output)
62 .with_prune_policy(
63 ArtifactCachePrunePolicy::new()
64 .with_max_age(Duration::from_secs(7 * 24 * 60 * 60))
65 .with_max_size_bytes(2 * 1024 * 1024 * 1024),
66 );
67
68 let outcome = match prepare_artifact_cache(&spec)? {
69 ArtifactCachePreparation::Reused(record) => ArtifactCacheOutcome::Reused(record),
70 ArtifactCachePreparation::Build(transaction) => {
71 let staged_output = transaction.output_path("result")?;
72 admitted
73 .run(
74 &[input.into_os_string(), staged_output.into_os_string()],
75 &context,
76 limits,
77 )?
78 .require_success()?;
79 transaction.commit()?
80 }
81 };
82
83 let disposition = if outcome.is_reused() {
84 "reused"
85 } else {
86 "built"
87 };
88 println!("{disposition} artifact set {}", outcome.record().key());
89 Ok(())
90}Sourcepub const fn with_prune_policy_at_most_every(
self,
policy: ArtifactCachePrunePolicy,
minimum_interval: Duration,
) -> Self
pub const fn with_prune_policy_at_most_every( self, policy: ArtifactCachePrunePolicy, minimum_interval: Duration, ) -> Self
Apply retention at most once per minimum_interval for this namespace.
The small due-marker check still occurs under the namespace lock.
Successful acquisitions skip the directory scan until the interval has
elapsed. The interval applies to attempted maintenance, including a
nonfatal failed attempt. A zero interval is equivalent to
Self::with_prune_policy.
Sourcepub fn cache_root(&self) -> &Path
pub fn cache_root(&self) -> &Path
Caller-selected root containing cache data and coordination locks.