How to write file at comptime?

Can I write file at comptime?
I’m working with types, and I want to generate middleware dll + exe from implemented functions, as I’m working in environment where direct connection of debugger, would lead program to crush.

comptime {
    var file = try std.fs.openFileAbsolute(
        "C:/path/file.txt",
        .{ .mode = .write_only },
    );
    defer file.close();
    file.write("Hello!");
}

P.S. That snippet doesn’t work
error: unable to evaluate comptime expression

IO is not allowed at comptime. This would need to be done at build time.

5 Likes

To further explain: OP should write to these files inside it’s build.zig, to create the appropriate files.

6 Likes

I think, I’ve found way to do a little more work, to make it through generics, and without code generation. May be even all exports, through comptime and inline for loop.
Thanks for answers!

P.S. I need to define each function that must be exported and then use a generic. Additional step, but compiles faster, than code generation.