@imp/rules/c/cmake/expansion

Module: @imp/rules/c/cmake/expansion.

build_target_deps(target_name, named, cross_deps, built_by_name)

The target_deps argument of the replay of target_name: { [dep name] = { outputs, task, file_indices } }.

file_indices has the 1-based index of each output of the dependency that this target references, not only the first output. On Windows the link needs the .dll.a import library, and the executable needs the .dll at run time. Replay builds each target in its own directory, so each referenced output must be mounted.

Source: rules/c/cmake/expansion.luau:145.

cmake_library_dep(project, name, options)

Adapt a discovered CMake target as a deps entry of cc_library or cc_binary. Options:

include_dirs Include directories that consumers need, for example the public header directory of the project. linkopts Link options that consumers need to resolve the shared library dependencies of this target, for example pkg-config -L and -l flags. shared True for an add_library(... SHARED ...) target. The artifact then goes in transitive_shared_libs, not in transitive_archives, as for cc_library({ shared = true }).

Source: rules/c/cmake/expansion.luau:303.

cmake_project(options)

Declare a CMake project. Options:

path Workspace-relative CMakeLists.txt directory. The default is the directory of the calling BUILD module. build_dir Build directory. The default is build/<path>. srcs Source globs that configure and replay read. The default has the C and C++ sources and headers. dirs Extra directories to mount, for example vendored includes. extra_globs Extra project-relative files for compiler edges, for inputs without a standard header suffix. deps Artifact handles for configure and replay. The CMake arguments state how the project uses them. cmake_args Extra cmake -S -B arguments. opt_cmake_args Extra cmake -S -B arguments for each value of the opt mode axis: { debug = {...}, release = {...} }. They follow cmake_args. With this option, configure reads the axis, so each mode configures and builds separately. No axis value selects debug. toolchain A gcc or MSVC provider, or a union. The default is the gcc default. zig is not supported. cmake_toolchain A graph_toolchain() of @imp/rules/c/cmake/toolchain. The default is the declared CMake default. unsafe_system_paths Skip the Bootlin wrapper guard that rejects -I, -isystem, and -L flags under /usr/include or /usr/lib, so that the project can use host system packages.

Returns an expansion: project:get(cmake_target_name, workflow, facet?) and project:all(workflow, facet?). workflow is BUILD, PACKAGE, or TEST. The TEST facet is always "unit".

Source: rules/c/cmake/expansion.luau:287.

cmake_project_expansion(options)

The expansion of each real CMake target (add_library and add_executable) of a project. See cmake_project for the options and the result.

Source: rules/c/cmake/expansion.luau:179.

cmake_project_specs()

The specs of the declared CMake projects, in declaration order.

Source: rules/c/cmake/expansion.luau:31.

cross_target_dependencies(named, ninja_graph)

The first pass of discovery: the other named targets that each target references, as { [name] = { { name, output_paths }, ... } }.

The walk of a target stops at the final outputs of the other targets (see reachable_edges_bounded in ./ninja_graph). output_paths holds each output of the dependency that this target references through | or ||. Both kinds matter: on Windows, a SHARED_LIBRARY dependency has a .dll.a import library that the link needs (|), and a .dll that the built executable needs at run time (||).

Source: rules/c/cmake/expansion.luau:56.

topo_sort_targets(named, cross_deps)

The targets in the order of the second pass: dependencies before dependents, so that each replay task can take the task handles of its dependencies. A CMake target graph has no cycles, so a cycle here means that the boundary detection is wrong, and the call fails.

Source: rules/c/cmake/expansion.luau:97.