diff options
| author | Nikolas <[email protected]> | 2022-01-08 22:13:44 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-08 22:13:44 +0100 |
| commit | a6aa5a1e4c34e7d8dfbede6d17ee40f7648265bb (patch) | |
| tree | 0d39ff990722f00c6b72023ddcee97addc6586b1 /src/build.zig | |
| parent | 9d6fcd1710270c7557cd4be2e66868e0c6d63486 (diff) | |
| download | raylib-a6aa5a1e4c34e7d8dfbede6d17ee40f7648265bb.tar.gz raylib-a6aa5a1e4c34e7d8dfbede6d17ee40f7648265bb.zip | |
Make zig build functionality available to zig programs (#2271)
Diffstat (limited to 'src/build.zig')
| -rw-r--r-- | src/build.zig | 135 |
1 files changed, 73 insertions, 62 deletions
diff --git a/src/build.zig b/src/build.zig index 76d4a661..915d33a8 100644 --- a/src/build.zig +++ b/src/build.zig @@ -1,72 +1,83 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. - const target = b.standardTargetOptions(.{}); +pub fn Pkg(srcdir: []const u8) type { + return struct { + pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep { + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + const raylib_flags = &[_][]const u8{ + "-std=gnu99", + "-DPLATFORM_DESKTOP", + "-DGL_SILENCE_DEPRECATION=199309L", + "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891 + }; - const raylib_flags = &[_][]const u8{ - "-std=gnu99", - "-DPLATFORM_DESKTOP", - "-DGL_SILENCE_DEPRECATION", - "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891 - }; + const raylib = b.addStaticLibrary("raylib", srcdir ++ "/raylib.h"); + raylib.setTarget(target); + raylib.setBuildMode(mode); + raylib.linkLibC(); - const raylib = b.addStaticLibrary("raylib", "raylib.h"); - raylib.setTarget(target); - raylib.setBuildMode(mode); - raylib.linkLibC(); + raylib.addIncludeDir(srcdir ++ "/external/glfw/include"); - raylib.addIncludeDir("external/glfw/include"); + raylib.addCSourceFiles(&.{ + srcdir ++ "/raudio.c", + srcdir ++ "/rcore.c", + srcdir ++ "/rmodels.c", + srcdir ++ "/rshapes.c", + srcdir ++ "/rtext.c", + srcdir ++ "/rtextures.c", + srcdir ++ "/utils.c", + }, raylib_flags); - raylib.addCSourceFiles(&.{ - "raudio.c", - "rcore.c", - "rmodels.c", - "rshapes.c", - "rtext.c", - "rtextures.c", - "utils.c", - }, raylib_flags); + switch (raylib.target.toTarget().os.tag) { + .windows => { + raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); + raylib.linkSystemLibrary("winmm"); + raylib.linkSystemLibrary("gdi32"); + raylib.linkSystemLibrary("opengl32"); + raylib.addIncludeDir("external/glfw/deps/mingw"); + }, + .linux => { + raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); + raylib.linkSystemLibrary("GL"); + raylib.linkSystemLibrary("rt"); + raylib.linkSystemLibrary("dl"); + raylib.linkSystemLibrary("m"); + raylib.linkSystemLibrary("X11"); + }, + .macos => { + // On macos rglfw.c include Objective-C files. + const raylib_flags_extra_macos = &[_][]const u8{ + "-ObjC", + }; + raylib.addCSourceFiles( + &.{srcdir ++ "/rglfw.c"}, + raylib_flags ++ raylib_flags_extra_macos, + ); + raylib.linkFramework("Foundation"); + }, + else => { + @panic("Unsupported OS"); + }, + } - switch (raylib.target.toTarget().os.tag) { - .windows => { - raylib.addCSourceFiles(&.{"rglfw.c"}, raylib_flags); - raylib.linkSystemLibrary("winmm"); - raylib.linkSystemLibrary("gdi32"); - raylib.linkSystemLibrary("opengl32"); - raylib.addIncludeDir("external/glfw/deps/mingw"); - }, - .linux => { - raylib.addCSourceFiles(&.{"rglfw.c"}, raylib_flags); - raylib.linkSystemLibrary("GL"); - raylib.linkSystemLibrary("rt"); - raylib.linkSystemLibrary("dl"); - raylib.linkSystemLibrary("m"); - raylib.linkSystemLibrary("X11"); - }, - .macos => { - // On macos rglfw.c include Objective-C files. - const raylib_flags_extra_macos = &[_][]const u8{ - "-ObjC", - }; - raylib.addCSourceFiles( - &.{"rglfw.c"}, - raylib_flags ++ raylib_flags_extra_macos, - ); - raylib.linkFramework("Foundation"); - }, - else => { - @panic("Unsupported OS"); - }, - } + raylib.setOutputDir("./"); + raylib.install(); + return raylib; + } + }; +} + +const lib = Pkg("."); + +pub fn build(b: *std.build.Builder) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); - raylib.setOutputDir("./"); - raylib.install(); + _ = lib.addRaylib(b, target); } |
