Mold

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

MOLD_TOOL

const MOLD_TOOL

Undocumented.

moldArtifactName()

moldArtifactName(version, plat)

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

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

Returns: string

moldDownloadUrl()

moldDownloadUrl(version, plat)

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

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

Returns: string

moldSupportedPlatforms()

moldSupportedPlatforms()

Return the platforms mold publishes release archives for.

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

moldCacheKey()

moldCacheKey(version, plat)

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

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

Returns: string

MoldToolchain (implementation class)

class MoldToolchain

Implementation class. BUILD files should use moldToolchain().

Undocumented.

moldToolchain()

moldToolchain(version, opts = {})

Declare a mold 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 mold toolchain.

installMoldToolchain()

installMoldToolchain(version, source)

Install a local mold toolchain directory into the named cache.

ParameterTypeDescription
versionstring
sourcestringPath to the toolchain root.

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

moldGraphTool()

moldGraphTool(version)

Build the managed mold distribution as a graph-native tool. A custom task() (rather than extractArchive()'s shared graph helper) so the extracted directory can also populate MOLD_TOOLCHAIN_CACHE via output.directory()'s namedCache option — extractArchive()'s graph form explicitly rejects namedCache (it "owns its tools"), but moldRustLinkerEnv() (below) needs that named-cache's real, absolute, stable path: a relative -fuse-ld=<path> breaks in practice, the same way a relative -C linker=<path> does — see gccRustLinkDriverEnv()'s docstring in //rules/c/gcc for the confirmed failure and reasoning.

moldGraphToolchain()

moldGraphToolchain(version)

Graph-native mold toolchain: moldGraphTool() wrapped with version metadata, mirroring gccGraphToolchain()'s shape (//rules/c/gcc).

ParameterTypeDescription
[version]string

Returns: { tool: object, version: string }

defaultMoldGraphToolchain()

defaultMoldGraphToolchain()

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

Returns: object|null

resolveMoldToolchainVersion()

resolveMoldToolchainVersion(version)

Resolve an explicit or default mold toolchain version.

ParameterTypeDescription
[version]string

Returns: string|null

defaultMoldToolchainVersion()

defaultMoldToolchainVersion()

Return the currently configured default mold toolchain version.

Returns: string|null

defaultMoldToolchain()

defaultMoldToolchain()

Return the currently configured default mold toolchain target handle.

Returns: object|null

moldRustLinkerEnv()

moldRustLinkerEnv(exec, resolvedMoldTool, version)

Resolve the rustflags/pathDirs rustLinkerTools() (//rules/rust) needs to enable mold as rustc's backend linker. Unlike gcc's own -C linker=<path> (which does accept an absolute path), this Bootlin-built gcc's -fuse-ld= rejects an absolute path outright — confirmed by a real imp lint //crates/imp:imp failure: "x86_64-linux- gcc.br_real: error: unrecognized command-line option '-fuse-ld='" (see #60/#31). So this keeps a bare -fuse-ld=mold PATH-search form, and instead returns mold's real, absolute, stable bin directory as pathDirs for the caller to fold into PATH — mirroring how rustGraphToolEnv()'s kache-active branch already builds PATH from named-cache directories (//rules/rust/toolchain).

ParameterTypeDescription
execobjectTask's exec (see task()'s run(exec, resolved) body).
resolvedMoldToolobjectResolved moldGraphToolchain().tool input.
versionstringmoldGraphToolchain().version.

Returns: { rustflags: string[], pathDirs: string[] }

moldOdinLinkerEnv()

moldOdinLinkerEnv(exec, resolvedMoldTool, version)

Resolve the flags/pathDirs Odin's build task (//rules/odin) needs to select mold as its linker via -linker:mold. Odin execs its linker directly by name (unlike rustc, which shells through a -C linker=/ -fuse-ld= flag pointed at a link driver) — the flag alone selects mold, but mold's own binary still has to be reachable on PATH, same as gcc's bin[-unsafe-paths]/ dir already is for Odin's default linker.

ParameterTypeDescription
execobjectTask's exec (see task()'s run(exec, resolved) body).
resolvedMoldToolobjectResolved moldGraphToolchain().tool input.
versionstringmoldGraphToolchain().version.

Returns: { flags: string[], pathDirs: string[] }