rules/c/cmake/toolchain.js

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

CMAKE_TOOL

const CMAKE_TOOL

Undocumented.

cmakeArtifactName()

cmakeArtifactName(version, plat)

Return the CMake release artifact filename for a version and platform.

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

Returns: string

cmakeDownloadUrl()

cmakeDownloadUrl(version, plat)

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

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

Returns: string

cmakeSupportedPlatforms()

cmakeSupportedPlatforms()

Return the platforms CMake publishes release archives for, derived from the os/arch matrix this module already supports.

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

cmakeCacheKey()

cmakeCacheKey(version, plat)

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

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

Returns: string

CmakeToolchain (implementation class)

class CmakeToolchain

Implementation class. BUILD files should use cmakeToolchain().

Undocumented.

cmakeToolchain()

cmakeToolchain(version, opts = {})

Declare a CMake toolchain version and optionally set it as the default. matching lockfile entry (warns instead of failing). to use instead of the shipped one.

ParameterTypeDescription
versionstring
[opts]object
[opts.default=false]boolean
[opts.unverified=false]booleanAllow downloading without a
[opts.lockfile]stringAddress of a workspace-owned lockfile

Returns: object Target handle for this CMake toolchain.

installCmakeToolchain()

installCmakeToolchain(version, source)

Install a local CMake toolchain directory into the named cache.

ParameterTypeDescription
versionstring
sourcestringPath to the toolchain root.

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

resolveCmakeToolchainVersion()

resolveCmakeToolchainVersion(version)

Resolve an explicit or default CMake toolchain version.

ParameterTypeDescription
[version]string

Returns: string|null

cmakeGraphTool()

cmakeGraphTool(version)

Build the managed CMake distribution as a graph-native tool (issue #31/#62, PR D). Mirrors rules/c/gcc's gccGraphTool() — downloadToolArtifact()'s graph form plus extractArchive() (no wrapper scripts needed for a plain cmake binary, unlike gcc/zig's compiler-alias wrappers, so this is simpler) — writing its result into CMAKE_TOOLCHAIN_CACHE so cmakeGraphToolSpec() can address the same install by cache key.

ParameterTypeDescription
[version]string

Returns: object A graph-native tool() handle.

cmakeGraphToolchain()

cmakeGraphToolchain(version)

Graph-native CMake toolchain: cmakeGraphTool() wrapped with version metadata, mirroring gccGraphToolchain()'s one-directory shape.

ParameterTypeDescription
[version]string

Returns: { tool: object, version: string }

defaultCmakeGraphToolchain()

defaultCmakeGraphToolchain()

Return the currently configured default CMake toolchain as graph-native handles, or null if none is declared.

Returns: object|null

cmakeGraphToolchainDir()

cmakeGraphToolchainDir(exec, resolvedCmakeTool, version)

The real, absolute host directory (bin/ inside it) a resolved CMake graph toolchain installed into, via the same named-cache cacheGet() real host path cmakeGraphToolSpec() addresses — mirrors gcc's own gccGraphToolchainDir() (//rules/c/gcc). Must be used (not exec.tool()'s sandbox-mount-relative path) for CMake's own configure invocation: its result gets baked as literal CMAKE_COMMAND text into build.ninja custom commands (e.g. a POST_BUILD ${CMAKE_COMMAND} -E copy), read back by a later, separate replay sandbox — confirmed by a real replay failure ("../../../../../directory/bin/cmake: not found") when this used exec.tool()'s relative alias instead: rebasePath() only recognizes a real absolute host path or a genuine sandboxRoot-absolute mount, not an unresolved sandbox-relative one.

ParameterTypeDescription
execobjectTask's exec (see task()'s run(exec, resolved) body).
resolvedCmakeToolobjectResolved cmakeGraphToolchain().tool input.
versionstringcmakeGraphToolchain().version.

Returns: string

cmakeGraphToolSpec()

cmakeGraphToolSpec(version)

A freshly-constructible, named-cache-backed legacy tool spec for a pinned CMake install — the graph-native counterpart of gcc's gccGraphToolSpec(), used to resolve a bare "cmake" name rewriteToolInvocations() recovers from a replayed ninja edge's baked-in CMAKE_COMMAND path (see cmakeGraphTool()'s own docstring). Unlike a resolved tool() binding, this can be constructed at any time, including inside a running task() body.

ParameterTypeDescription
[version]string

Returns: object {kind:"tool", name:"cmake", cache, key, binDirs}.

defaultCmakeToolchainVersion()

defaultCmakeToolchainVersion()

Return the currently configured default CMake toolchain version.

Returns: string|null