rules/rust/kache/toolchain.js

Developer reference: this page includes exported implementation details. BUILD authors should prefer the User API reference.

KACHE_TOOL

const KACHE_TOOL

Undocumented.

kacheConfigSchema

const kacheConfigSchema

Undocumented.

kacheArtifactName()

kacheArtifactName(_version, plat)

Return the kache release artifact filename for a version and platform. Unlike sccache/zola, kache's release assets don't embed the version in the filename — only the release tag in the URL path distinguishes versions. artifactName(version, plat) signature.

ParameterTypeDescription
_versionstringUnused; kept for parity with other toolchains'
plat{ os: string, arch: string }

Returns: string

kacheDownloadUrl()

kacheDownloadUrl(version, plat)

Return the kache release download URL for a version and platform.

ParameterTypeDescription
versionstring
plat{ os: string, arch: string }

Returns: string

kacheCacheKey()

kacheCacheKey(version, plat)

Return the named-cache key for a kache toolchain version and platform.

ParameterTypeDescription
versionstring
plat{ os: string, arch: string }

Returns: string

kacheDataCacheKey()

kacheDataCacheKey(plat)

Return the named-cache key for the kache data (object cache) directory. Deliberately independent of the kache binary version — the on-disk cache format is stable across kache releases in practice, and there's no reason to throw away accumulated cache hits on a routine kache bump.

ParameterTypeDescription
plat{ os: string, arch: string }

Returns: string

kacheSupportedPlatforms()

kacheSupportedPlatforms()

Return the platforms kache publishes release archives for.

Returns: Array<{ os: string, arch: string }>

KacheToolchain (implementation class)

class KacheToolchain

Implementation class. BUILD files should use kacheToolchain().

Undocumented.

kacheToolchain()

kacheToolchain(version, opts = {})

Declare a kache toolchain version and optionally set it as the default. matching lockfile entry (warns instead of failing). to use instead of the shipped one. KACHE_CACHE_DIR's on-disk size (kache's own default is 50 GiB; imp's GC can't prune inside it, only delete it wholesale — see kacheBuildCacheEnv()'s doc comment).

ParameterTypeDescription
versionstring
[opts]object
[opts.default=false]boolean
[opts.unverified=false]booleanAllow downloading without a
[opts.lockfile]stringAddress of a workspace-owned lockfile
[opts.cacheSize="4GiB"]stringKACHE_MAX_SIZE — caps

Returns: object Target handle for this kache toolchain.

installKacheToolchain()

installKacheToolchain(version, source)

Install a local kache toolchain directory into the named cache.

ParameterTypeDescription
versionstring
sourcestringPath to the toolchain root.

Returns: string|null Local path to the cached toolchain root.

kacheGraphTool()

kacheGraphTool(version)

Acquire the kache binary as a graph-native tool: a straightforward downloadToolArtifact()+extractArchive() port, mirroring rules/odin/toolchain.js's odinGraphTool() — kache's release archives are flat, so no stripComponents is needed here either. The RUSTC_WRAPPER env/daemon-lifecycle wiring (workerStart(), see kacheBuildCacheEnv() below) has no task()-based graph-native form to port to: it stays a plain async helper, called directly from inside whichever cargo action task body needs it (rules/rust's graph-native build/test/lint passes) rather than being wrapped in its own task() here. Only its dispatch (once reached dynamically via productFor(), #148) is now a plain, statically-imported function call.

ParameterTypeDescription
[version]string

Returns: object A tool handle accepted by exec.tool()/exec.action().

resolveKacheToolchainVersion()

resolveKacheToolchainVersion(version)

Resolve an explicit or default kache toolchain version.

ParameterTypeDescription
[version]string

Returns: string|null

defaultKacheToolchainVersion()

defaultKacheToolchainVersion()

Return the currently configured default kache toolchain version.

Returns: string|null

defaultKacheToolchain()

defaultKacheToolchain()

Return the currently configured default kache toolchain target handle.

Returns: object|null

kacheScriptPreamble()

kacheScriptPreamble()

Shell text to run before invoking cargo, once the caller has captured imp_sandbox_root="$(pwd)" as the first statement of its own script (same idiom as rules/c/cmake/index.js's zigEnvExportStmts — see its doc comment for why this can't just be one more entry in kacheBuildCacheEnv()'s array). KACHE_BASE_DIR can't be a literal path handed through run()'s env:, because the sandbox root doesn't exist yet when env: is hashed into the task key (crates/imp-execution/src/exec.rs computes the key before creating the sandbox) — only the symbolic shell reference $imp_sandbox_root, resolved by the shell at actual run time, is safe to bake into the hashed script text. Without KACHE_BASE_DIR at all, kache keys compiles partly off the absolute paths rustc is invoked with, which differ on every sandbox — so cache entries almost never hit and the cache just grows. KACHE_BASE_DIR tells kache which prefix is "the sandbox" so it can normalize those paths away before hashing.

Returns: string