rules/c/toolchain.js

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

shellQuote()

shellQuote(value)

Undocumented.

clangOptFlags()

clangOptFlags(opt)

Undocumented.

sonameArgs()

sonameArgs(outPath, isShared)

Undocumented.

rpathOriginArgs()

rpathOriginArgs(bundled)

Undocumented.

ccToolchainForPlatform()

ccToolchainForPlatform(byOs)

Wrap one provider per OS into a single selectable union — "the same logical target keeps one toolchain shape while selecting GCC on Linux and MSVC on Windows" per the PR #165 review. Pass to cmakeProject()/ ccLibrary()/ccBinary()'s toolchain option in place of a bare provider. Each byOs branch may be an already-constructed provider or a zero-arg thunk — pass whichever reads more clearly at the call site; it makes little practical difference. Calling msvcToolchain() itself is still inert (a plain object literal, no I/O) — its one graph node (the shared "discover MSVC host toolchain" task, see //rules/c/msvc's own msvcHostGraphOutput()) is only registered once some consumer's taskInputs() call actually reaches it, same as any other lazily-declared task node. gccGraphToolchain()/zigGraphToolchain() do register a real download/ install task() graph node when called, for whichever platform is executing right now — but merely declaring that node costs nothing unless something downstream actually requests its output (imp only executes reachable task nodes), and both modules already declare their own pinned-default install node unconditionally as a side effect of being imported at all (see gcc's/zig's own bottom-of-file gccToolchain(..., {default: true})/zigToolchain(..., {default: true})) — before this union or any thunk here ever runs. So a thunk only avoids one additional, redundant such node on a branch that never gets selected; it's not the difference between "downloads gcc" and "doesn't." Selection is by targetPlatform.os only (no arch axis): every provider today hardcodes x86_64 support, so there is nothing downstream yet that would act on an arch key. per platform os string (e.g. "linux", "windows", "darwin").

ParameterTypeDescription
byOs{[os: string]: object(() => object)}

Returns: {kind: string, byOs: object, select: (targetPlatform?: {os: string, arch: string}) => object}

isCcToolchainUnion()

isCcToolchainUnion(toolchain)

Undocumented.

selectCcToolchain()

selectCcToolchain(toolchain, targetPlatform)

Resolve toolchain to a bare provider: a union is passed through .select(), a bare provider (or nullish) is returned unchanged. Lets cmakeProject()/ccLibrary()/ccBinary() accept either transparently.

ParameterTypeDescription
[toolchain]object
[targetPlatform]{os: string, arch: string}

Returns: object|undefined