Simplify build.zig to not require user to specify raylib path (#2383)

We can figure out the source file location based on the location of the
build.zig file. No need to require the library user to specify where
raylib is stored.
This commit is contained in:
Komari Spaghetti 2022-03-11 19:04:24 +01:00 committed by GitHub
parent cda1324e87
commit 8065504aba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,6 @@
const std = @import("std");
pub fn Pkg(srcdir: []const u8) type {
return struct {
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
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();
@ -76,15 +74,9 @@ pub fn Pkg(srcdir: []const u8) type {
},
}
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
@ -92,5 +84,13 @@ pub fn build(b: *std.build.Builder) void {
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
_ = lib.addRaylib(b, target);
const lib = addRaylib(b, target);
lib.setOutputDir(srcdir);
lib.install();
}
const srcdir = getSrcDir();
fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}