diff options
| author | andromeda <andromeda@lenovo> | 2026-06-14 01:31:35 +0200 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-06-14 01:31:35 +0200 |
| commit | 00205c3111c41018aad135456a70ecb4943cb8f0 (patch) | |
| tree | 7dba8710cb43c0f0ed856a340c0e1a1265653915 /build.zig | |
| parent | d3a1fe476d6ce9cac90fea61d03f8158b2d09c0e (diff) | |
RSGL
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 64 |
1 files changed, 54 insertions, 10 deletions
@@ -1,25 +1,69 @@ const std = @import("std"); -pub fn build(b: *std.Build) void { +pub fn build(b: *std.Build) !void { + const opengl = b.option(bool, "opengl", "Exposes OpenGL helper functions in RGFW.h and links OpenGL. Default: true") orelse true; + const x11 = b.option(bool, "x11", "X11 backend. Default: true") orelse true; + const target = b.standardTargetOptions(.{}); -// const optimize = b.standardOptimizeOption(.{}); + const optimize = b.standardOptimizeOption(.{}); + var macros = std.ArrayList([2][]const u8).empty; + defer macros.deinit(b.allocator); + var syslibs = std.ArrayList(struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}).empty; + defer syslibs.deinit(b.allocator); + + try macros.append(b.allocator, [2][]const u8{"RSGL_RFONT", ""}); + + if (target.result.os.tag == std.Target.Os.Tag.linux or target.result.os.tag == std.Target.Os.Tag.macos) + try macros.append(b.allocator, [2][]const u8{"RGFW_UNIX", ""}); + + if (x11) { + try macros.append(b.allocator, [2][]const u8{"RGFW_X11", ""}); + try syslibs.append(b.allocator, struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}{"X11", .{}}); + try syslibs.append(b.allocator, struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}{"Xrandr", .{}}); + } else { + try macros.append(b.allocator, [2][]const u8{"RGFW_NO_X11", ""}); + } + if (opengl) { + try macros.append(b.allocator, [2][]const u8{"RGFW_OPENGL", ""}); + try syslibs.append(b.allocator, struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}{"GL", .{}}); + } else { + std.debug.panic("no backend other than OpenGL supported by RSGL.h", .{}); + } + + const rgfw = b.addTranslateC(.{ + .root_source_file = b.path("include/RGFW.h"), + .target = target, + .optimize = optimize, + }); + for (macros.items) |macro| {rgfw.defineCMacro(macro[0], macro[1]);} + const rgfw_mod = rgfw.addModule("rgfw"); + + const rsgl = b.addTranslateC(.{ + .root_source_file = b.path("include/RSGL_gl.h"), + .target = target, + .optimize = optimize, + }); + for (macros.items) |macro| {rsgl.defineCMacro(macro[0], macro[1]);} + const rsgl_mod = rsgl.addModule("rsgl"); const term = b.createModule(.{ .root_source_file = b.path("main.zig"), .target = target, - .link_libc = true, + .optimize = optimize, + .imports = &.{ + .{.name = "rgfw", .module = rgfw_mod}, + .{.name = "rsgl", .module = rsgl_mod}, + }, }); term.addCMacro("RGFW_IMPLEMENTATION", ""); - term.addCMacro("RGFW_OPENGL", ""); + term.addCMacro("RFONT_IMPLEMENTATION", ""); + term.addCMacro("RSGL_IMPLEMENTATION", ""); + for (macros.items) |macro| {term.addCMacro(macro[0], macro[1]);} term.addIncludePath(b.path("include")); - term.addCSourceFile(.{ - .file = b.addWriteFiles().add("rgfw.c", "#include <RGFW.h>"), - }); + term.addCSourceFile(.{.file = b.addWriteFiles().add("rgfw.c", "#include <RSGL_gl.h>\n#include <RGFW.h>"),}); - term.linkSystemLibrary("GL", .{}); - term.linkSystemLibrary("X11", .{}); - term.linkSystemLibrary("Xrandr", .{}); + for (syslibs.items) |lib| {term.linkSystemLibrary(lib[0], lib[1]);} const exe = b.addExecutable(.{ .name = "term", |
