Browse Source

Add Zig build file (#2014)

The build file builds Raylib as a static library for either
Windows or Linux.
pull/2017/head
Tommi Sinivuo 3 years ago
committed by GitHub
parent
commit
206e1def6f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions
  1. +7
    -0
      .gitignore
  2. +58
    -0
      src/build.zig

+ 7
- 0
.gitignore View File

@ -93,3 +93,10 @@ build
GPATH
GRTAGS
GTAGS
# Zig programming language
zig-cache/
zig-out/
build/
build-*/
docgen_tmp/

+ 58
- 0
src/build.zig View File

@ -0,0 +1,58 @@
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(.{});
// 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",
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
};
const raylib = b.addStaticLibrary("raylib", "raylib.h");
raylib.setTarget(target);
raylib.setBuildMode(mode);
raylib.linkLibC();
raylib.addIncludeDir("external/glfw/include");
raylib.addCSourceFile("rcore.c", raylib_flags);
raylib.addCSourceFile("rmodels.c", raylib_flags);
raylib.addCSourceFile("raudio.c", raylib_flags);
raylib.addCSourceFile("rshapes.c", raylib_flags);
raylib.addCSourceFile("rtext.c", raylib_flags);
raylib.addCSourceFile("rtextures.c", raylib_flags);
raylib.addCSourceFile("utils.c", raylib_flags);
raylib.addCSourceFile("rglfw.c", raylib_flags);
switch (raylib.target.toTarget().os.tag) {
.windows => {
raylib.linkSystemLibrary("winmm");
raylib.linkSystemLibrary("gdi32");
raylib.linkSystemLibrary("opengl32");
raylib.addIncludeDir("external/glfw/deps/mingw");
},
.linux => {
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
raylib.linkSystemLibrary("dl");
raylib.linkSystemLibrary("m");
raylib.linkSystemLibrary("X11");
},
else => {
@panic("Unsupported OS");
},
}
raylib.setOutputDir("./");
raylib.install();
}

Loading…
Cancel
Save