Capturing build options in a string

You also can use @embedFile if you want to embed the source code of the (generated) config module:

const std = @import("std");

const config = @import("config");
const config_string = @embedFile("config");

pub fn main() !void {
    inline for (comptime std.meta.declarations(config)) |decl| {
        std.debug.print("{s: <10}{any}\n", .{ decl.name ++ ":", @field(config, decl.name) });
    }

    std.debug.print("\nor the config source:\n{s}", .{config_string});
}

Options are just implemented as generated normal modules and when you use embed file you end up embedding the root source file of the corresponding module.

5 Likes