1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00
serenity/Ports/zig/scripts/generate-serenity-constants.zig
sin-ack cda5a530e6 Ports: Add zig port :^)
:yakkie:

The build process for the Zig compiler is more involved than most of
the other ports, because the Zig compiler is mostly self-hosting. In
order to build it, the zig-bootstrap build system is used, which does
the following:

1) Build LLVM for the host OS;
2) Build Zig for the host OS with the SerenityOS target enabled;
3) Build zlib, zstd and LLVM for SerenityOS using `zig cc` as the C/C++
   compiler;
4) Build Zig for SerenityOS using the host Zig.

A few hacks are required in order to tell `zig cc` and zig about what
Serenity's libc looks like in the build process, but other than that
it's fairly straightforward. All of the patches that are included with
this commit are Zig-upstream ready once the LLVM patches are upstreamed.
2022-12-11 19:55:37 -07:00

50 lines
1.4 KiB
Zig

const std = @import("std");
const SerenityIncludes = @cImport({
@cInclude("bits/pthread_integration.h");
@cInclude("dirent.h");
@cInclude("errno_codes.h");
@cInclude("fcntl.h");
@cInclude("limits.h");
@cInclude("link.h");
@cInclude("poll.h");
@cInclude("semaphore.h");
@cInclude("stdio.h");
@cInclude("sys/file.h");
@cInclude("sys/mman.h");
@cInclude("sys/stat.h");
@cInclude("sys/types.h");
@cInclude("sys/uio.h");
@cInclude("sys/wait.h");
@cInclude("time.h");
@cInclude("unistd.h");
});
const constant_file = @embedFile("./constants.txt");
const constants = blk: {
@setEvalBranchQuota(10000);
var constant_list: []const []const u8 = &.{};
var constant_iterator = std.mem.tokenize(u8, constant_file, "\n");
while (constant_iterator.next()) |constant| {
constant_list = constant_list ++ &[_][]const u8{constant};
}
break :blk constant_list;
};
pub fn main() !void {
const writer = std.io.getStdOut().writer();
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
inline for (constants) |constant| {
const value = @field(SerenityIncludes, constant);
const decl = try std.fmt.allocPrint(allocator, "pub const " ++ constant ++ " = {d};\n", .{value});
defer allocator.free(decl);
try writer.writeAll(decl);
}
}