Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

addModule

Private Function
std.Build.Serialize.addModule
fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index

Params

File

Build/Serialize.zig:1168
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {
    if (s.module_map.get(m)) |index| return index;

    const wc = s.wc;
    const arena = s.arena;

    const rpaths = try arena.alloc(Configuration.Module.RPath, m.rpaths.items.len);
    for (rpaths, m.rpaths.items) |*dest, src| dest.* = switch (src) {
        .lazy_path => |lp| .{ .lazy_path = try addLazyPath(s, lp) },
        .special => |slice| .{ .special = try wc.addString(slice) },
    };

    const link_objects = try arena.alloc(Configuration.Module.LinkObject, m.link_objects.items.len);
    for (link_objects, m.link_objects.items) |*dest, *src| dest.* = switch (src.*) {
        .static_path => |lp| .{ .static_path = try addLazyPath(s, lp) },
        .other_step => |cs| .{ .other_step = stepIndex(s, &cs.step) },
        .system_lib => |*sl| .{ .system_lib = try addSystemLib(s, sl) },
        .assembly_file => |lp| .{ .assembly_file = try addLazyPath(s, lp) },
        .c_source_file => |csf| .{ .c_source_file = try addCSourceFile(s, csf) },
        .c_source_files => |csf| .{ .c_source_files = try addCSourceFiles(s, csf) },
        .win32_resource_file => |wrf| .{ .win32_resource_file = try addRcSourceFile(s, wrf) },
    };

    const frameworks = try arena.alloc(Configuration.Module.Framework, m.frameworks.entries.len);
    for (frameworks, m.frameworks.keys(), m.frameworks.values()) |*dest, name, options| dest.* = .{
        .flags = .{
            .needed = options.needed,
            .weak = options.weak,
        },
        .name = try wc.addString(name),
    };

    const lib_paths = try initLazyPathList(s, m.lib_paths.items);
    const c_macros = try initStringList(s, m.c_macros.items);
    const export_symbol_names = try initStringList(s, m.export_symbol_names);

    const module_index: Configuration.Module.Index = try wc.addExtra(Configuration.Module, .{
        .flags = .{
            .optimize = .init(m.optimize),
            .strip = .init(m.strip),
            .unwind_tables = .init(m.unwind_tables),
            .dwarf_format = .init(m.dwarf_format),
            .single_threaded = .init(m.single_threaded),
            .stack_protector = .init(m.stack_protector),
            .stack_check = .init(m.stack_check),
            .sanitize_c = .init(m.sanitize_c),
            .sanitize_thread = .init(m.sanitize_thread),
            .fuzz = .init(m.fuzz),
            .code_model = m.code_model,
            .c_macros = c_macros.len != 0,
            .include_dirs = m.include_dirs.items.len != 0,
            .lib_paths = lib_paths.len != 0,
            .rpaths = rpaths.len != 0,
            .frameworks = frameworks.len != 0,
            .link_objects = link_objects.len != 0,
            .export_symbol_names = export_symbol_names.len != 0,
        },
        .flags2 = .{
            .valgrind = .init(m.valgrind),
            .pic = .init(m.pic),
            .red_zone = .init(m.red_zone),
            .omit_frame_pointer = .init(m.omit_frame_pointer),
            .error_tracing = .init(m.error_tracing),
            .link_libc = .init(m.link_libc),
            .link_libcpp = .init(m.link_libcpp),
            .no_builtin = .init(m.no_builtin),
        },
        .owner = try s.builderToPackage(m.owner),
        .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file),
        .import_table = .invalid,
        .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target),
        .c_macros = .{ .slice = c_macros },
        .lib_paths = .{ .slice = lib_paths },
        .export_symbol_names = .{ .slice = export_symbol_names },
        .include_dirs = .init(try s.initIncludeDirList(m.include_dirs.items)),
        .rpaths = .init(rpaths),
        .link_objects = .init(link_objects),
        .frameworks = .{ .slice = frameworks },
    });

    // The import table is the only place that modules can form dependency
    // loops. Therefore, we populate the module indexes only after adding
    // the module to module_map.
    try s.module_map.putNoClobber(arena, m, module_index);

    var imports = try std.MultiArrayList(Configuration.ImportTable.Import).initCapacity(arena, m.import_table.entries.len);
    imports.len = m.import_table.entries.len;
    for (
        imports.items(.name),
        imports.items(.module),
        m.import_table.keys(),
        m.import_table.values(),
    ) |*dest_name, *dest_module, src_name, src_module| {
        dest_name.* = try wc.addString(src_name);
        dest_module.* = try addModule(s, src_module);
    }

    comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".field_names[2], "import_table"));
    comptime assert(@typeInfo(Configuration.Module).@"struct".field_types[2] == Configuration.ImportTable.Index);
    assert(wc.extra.items[@backingInt(module_index) + 2] == @backingInt(Configuration.ImportTable.Index.invalid));
    const import_table_index = try wc.addDeduped(Configuration.ImportTable, .{
        .imports = .{ .mal = imports },
    });
    wc.extra.items[@backingInt(module_index) + 2] = @backingInt(import_table_index);

    return module_index;
}