DoxigAlpha

getGraph

Intended to be used during the make phase only.

Given that root is the root Module of a compilation, return all Modules in the module graph, including root itself. root is guaranteed to be the first module in the returned slice.

Function parameters

Parameters

#
root:*Module

Type definitions in this namespace

Types

#
CreateOptions
Unspecified options here will be inherited from parent `Module` when
Graph
Elements of `modules` and `names` are matched one-to-one.

Functions in this namespace

Functions

#
addImport
Adds an existing module to be used with `@import`.
addAnonymousImport
Creates a new module and adds it to be used with `@import`.
addOptions
Converts a set of key-value pairs into a Zig source file, and then inserts it into
addCSourceFiles
Handy when you have many non-Zig source files and want them all to have the same flags.
addWin32ResourceFile
Resource files must have the extension `.rc`.
addCMacro
Equvialent to the following C code, applied to all C source files owned by
getGraph
Intended to be used during the make phase only.

Source

Implementation

#
pub fn getGraph(root: *Module) Graph {
    if (root.cached_graph.modules.len != 0) {
        return root.cached_graph;
    }

    const arena = root.owner.graph.arena;

    var modules: std.AutoArrayHashMapUnmanaged(*std.Build.Module, []const u8) = .empty;
    var next_idx: usize = 0;

    modules.putNoClobber(arena, root, "root") catch @panic("OOM");

    while (next_idx < modules.count()) {
        const mod = modules.keys()[next_idx];
        next_idx += 1;
        modules.ensureUnusedCapacity(arena, mod.import_table.count()) catch @panic("OOM");
        for (mod.import_table.keys(), mod.import_table.values()) |import_name, other_mod| {
            modules.putAssumeCapacity(other_mod, import_name);
        }
    }

    const result: Graph = .{
        .modules = modules.keys(),
        .names = modules.values(),
    };
    root.cached_graph = result;
    return result;
}