From ba7b7c97f87991916ddff317b746e339a5cb5418 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Fri, 18 Mar 2022 16:57:15 +0100 Subject: [PATCH] Update build system to latest raylib --- .gitignore | 9 +-- build.zig | 2 +- examples/core/input_multitouch.zig | 3 +- lib.zig | 114 +++++++++++++++-------------- raylib | 2 +- 5 files changed, 64 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 49620d6..8539333 100755 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,7 @@ zig-cache/ .idea/ Project/* -**/raylib.h -**/raymath.h -**/.DS_Store -**/CMakeLists.txt -**/cmake-build-debug -examples/**/**.c +raylib.h +raymath.h libraylib.a +**/.DS_Store diff --git a/build.zig b/build.zig index e6c5e55..0799d55 100755 --- a/build.zig +++ b/build.zig @@ -7,7 +7,7 @@ const std = @import("std"); const Builder = std.build.Builder; -const raylib = @import("lib.zig").Pkg("."); +const raylib = @import("lib.zig"); const Program = struct { name: []const u8, diff --git a/examples/core/input_multitouch.zig b/examples/core/input_multitouch.zig index 5992858..9c0b126 100755 --- a/examples/core/input_multitouch.zig +++ b/examples/core/input_multitouch.zig @@ -59,8 +59,7 @@ pub fn main() anyerror!void if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it { // Draw circle and touch index number - rl.DrawCircle(@floatToInt(c_int, touchPosition.x), @floatToInt(c_int, touchPosition.y), 34, rl.ORANGE); - //DrawCircleV(touchPosition, 34, ORANGE); + rl.DrawCircleV(touchPosition, 34, rl.ORANGE); rl.DrawText(rl.FormatText("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.BLACK); } } diff --git a/lib.zig b/lib.zig index 20d84a5..6b1f1a2 100644 --- a/lib.zig +++ b/lib.zig @@ -1,62 +1,64 @@ const std = @import("std"); const Builder = std.build.Builder; const LibExeObjStep = std.build.LibExeObjStep; -const rl = @import("raylib/src/build.zig").Pkg("raylib/src"); +const rl = @import("raylib/src/build.zig"); -pub fn Pkg(pkgdir: []const u8) type { - return struct { - var ran_git = false; - pub fn link(exe: *LibExeObjStep, system_lib: bool) void { - if (system_lib) { - exe.linkSystemLibrary("raylib"); - return; - } else { - exe.linkLibrary(rl.addRaylib(exe.builder, exe.target)); - } +var ran_git = false; +const srcdir = getSrcDir(); - const target_os = exe.target.toTarget().os.tag; - switch (target_os) { - .windows => { - exe.linkSystemLibrary("winmm"); - exe.linkSystemLibrary("gdi32"); - exe.linkSystemLibrary("opengl32"); - }, - .macos => { - exe.linkFramework("OpenGL"); - exe.linkFramework("Cocoa"); - exe.linkFramework("IOKit"); - exe.linkFramework("CoreAudio"); - exe.linkFramework("CoreVideo"); - }, - .freebsd, .openbsd, .netbsd, .dragonfly => { - exe.linkSystemLibrary("GL"); - exe.linkSystemLibrary("rt"); - exe.linkSystemLibrary("dl"); - exe.linkSystemLibrary("m"); - exe.linkSystemLibrary("X11"); - exe.linkSystemLibrary("Xrandr"); - exe.linkSystemLibrary("Xinerama"); - exe.linkSystemLibrary("Xi"); - exe.linkSystemLibrary("Xxf86vm"); - exe.linkSystemLibrary("Xcursor"); - }, - else => { // linux and possibly others - exe.linkSystemLibrary("GL"); - exe.linkSystemLibrary("rt"); - exe.linkSystemLibrary("dl"); - exe.linkSystemLibrary("m"); - exe.linkSystemLibrary("X11"); - }, - } - } - - pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void { - to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig"); - } - pub const math = struct { - pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void { - to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig-math.zig"); - } - }; - }; +fn getSrcDir() []const u8 { + return std.fs.path.dirname(@src().file) orelse "."; } + +pub fn link(exe: *LibExeObjStep, system_lib: bool) void { + if (system_lib) { + exe.linkSystemLibrary("raylib"); + return; + } else { + exe.linkLibrary(rl.addRaylib(exe.builder, exe.target)); + } + + const target_os = exe.target.toTarget().os.tag; + switch (target_os) { + .windows => { + exe.linkSystemLibrary("winmm"); + exe.linkSystemLibrary("gdi32"); + exe.linkSystemLibrary("opengl32"); + }, + .macos => { + exe.linkFramework("OpenGL"); + exe.linkFramework("Cocoa"); + exe.linkFramework("IOKit"); + exe.linkFramework("CoreAudio"); + exe.linkFramework("CoreVideo"); + }, + .freebsd, .openbsd, .netbsd, .dragonfly => { + exe.linkSystemLibrary("GL"); + exe.linkSystemLibrary("rt"); + exe.linkSystemLibrary("dl"); + exe.linkSystemLibrary("m"); + exe.linkSystemLibrary("X11"); + exe.linkSystemLibrary("Xrandr"); + exe.linkSystemLibrary("Xinerama"); + exe.linkSystemLibrary("Xi"); + exe.linkSystemLibrary("Xxf86vm"); + exe.linkSystemLibrary("Xcursor"); + }, + else => { // linux and possibly others + exe.linkSystemLibrary("GL"); + exe.linkSystemLibrary("rt"); + exe.linkSystemLibrary("dl"); + exe.linkSystemLibrary("m"); + exe.linkSystemLibrary("X11"); + }, + } +} + +pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void { + to.addPackagePath(name, srcdir ++ "/lib/raylib-zig.zig"); +} +pub const math = struct { + pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void { + to.addPackagePath(name, srcdir ++ "/lib/raylib-zig-math.zig"); + } +}; diff --git a/raylib b/raylib index a6aa5a1..9ecbc46 160000 --- a/raylib +++ b/raylib @@ -1 +1 @@ -Subproject commit a6aa5a1e4c34e7d8dfbede6d17ee40f7648265bb +Subproject commit 9ecbc465a934fdde9e3d69a709370a370bf193a0