aboutsummaryrefslogtreecommitdiff
path: root/system/libraries/build.zig
blob: a38cbc3ef8dc218a5c252e7bcfcaa44ed79b2c6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.resolveTargetQuery(.{
        .cpu_arch = .x86_64,
        .os_tag = .freestanding,
        .abi = .none,
    });

    var lib_dir = std.fs.cwd().openDir(".", .{ .iterate = true }) catch return;
    defer lib_dir.close();

    var lib_iter = lib_dir.iterate();
    while (lib_iter.next() catch null) |entry| {
        if (entry.kind != .directory) continue;

        const lib_name = entry.name;
        const lib_file = std.fmt.allocPrint(b.allocator, "{s}/{s}.zig", .{ lib_name, lib_name }) catch continue;
        defer b.allocator.free(lib_file);

        std.fs.cwd().access(lib_file, .{}) catch continue;

        const lib = b.addLibrary(.{
            .name = lib_name,
            .root_module = b.createModule(.{
                .root_source_file = b.path(lib_file),
                .target = target,
                .optimize = .ReleaseSmall,
            }),
        });

        lib.linkage = .static;
        b.installArtifact(lib);
    }
}