Backlog/build/generateRc.zig

39 lines
1.2 KiB
Zig

const std = @import("std");
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
// Get output filename from build system
const args = try std.process.argsAlloc(allocator);
if (args.len < 3) @panic("Missing output filename");
const out_path = args[1];
// Generate a startup module function that invokes
// startup module for each zig function
// and generates an api
var content = std.ArrayList(u8).init(allocator);
var writer = content.writer();
const iconPath = args[2];
try writer.print("#include <windows.h>\r\n", .{});
try writer.print("IDI_ICON1 ICON \"../../../content/", .{}); //{s}\"", .{iconPath});
for (iconPath) |c| {
if (c == '\\') {
try writer.writeByte('/');
} else {
try writer.writeByte(c);
}
}
try writer.writeByte('"');
// Write to specified output file
// Open or create the file for writing (overwrites if it exists)
const file = try std.fs.cwd().createFile(out_path, .{});
defer file.close();
// Write the content to the file
try file.writeAll(content.items);
}