소스 검색

Add options to zig compile (#3115)

* Add options to zig compile options

Support for compiling with raygui, raymath, and physac.
Also outputs the required headers.

Raygui should be located `../raygui` relative to the repo root
Physac should be located `../physac` relative to the repo root

This behavior matches options in the Makefile

* Move Options struct

* Remove physac, explicit raymath, always copy rlgl.h and raymath.h

* Remove unused options from build.zig

* Add srcdir as include path for raygui.h
pull/3120/head
Dante Catalfamo 1 년 전
committed by GitHub
부모
커밋
3a90acf08e
No known key found for this signature in database GPG 키 ID: 4AEE18F83AFDEB23
1개의 변경된 파일28개의 추가작업 그리고 2개의 파일을 삭제
  1. +28
    -2
      src/build.zig

+ 28
- 2
src/build.zig 파일 보기

@ -1,7 +1,7 @@
const std = @import("std");
// This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) *std.Build.CompileStep {
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep {
const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
@ -28,6 +28,16 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built
srcdir ++ "/utils.c",
}, raylib_flags);
var gen_step = std.build.Step.WriteFile.create(b);
raylib.step.dependOn(&gen_step.step);
if (options.raygui) {
_ = gen_step.add(srcdir ++ "/raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
raylib.addCSourceFile(srcdir ++ "/raygui.c", raylib_flags);
raylib.addIncludePath(srcdir);
raylib.addIncludePath(srcdir ++ "/../../raygui/src");
}
switch (target.getOsTag()) {
.windows => {
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
@ -105,6 +115,10 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built
return raylib;
}
const Options = struct {
raygui: bool = false,
};
pub fn build(b: *std.Build) 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
@ -116,8 +130,20 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const lib = addRaylib(b, target, optimize);
const raygui = b.option(bool, "raygui", "Compile with raygui support");
const lib = addRaylib(b, target, optimize, .{
.raygui = raygui orelse false,
});
lib.installHeader("src/raylib.h", "raylib.h");
lib.installHeader("src/raymath.h", "raymath.h");
lib.installHeader("src/rlgl.h", "rlgl.h");
if (raygui orelse false) {
lib.installHeader("../raygui/src/raygui.h", "raygui.h");
}
b.installArtifact(lib);
}

불러오는 중...
취소
저장