From c6222a0913359ca8952ecf24e2c6656a69b8037b Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Sat, 23 May 2020 02:57:06 -0500 Subject: [PATCH 1/9] add raylib submodule also add build helper `lib.zig` to handle compiling and linking against raylib's source code, and update `build.zig` for examples to reflect lib.zig usage. --- .gitmodules | 3 ++ build.zig | 91 +++++++++++++++++++++++++++++++++++------------------ lib.zig | 42 +++++++++++++++++++++++++ raylib | 1 + 4 files changed, 107 insertions(+), 30 deletions(-) create mode 100644 .gitmodules create mode 100644 lib.zig create mode 160000 raylib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3ba065a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "raylib"] + path = raylib + url = https://github.com/raysan5/raylib diff --git a/build.zig b/build.zig index 6ad06fc..0ada318 100755 --- a/build.zig +++ b/build.zig @@ -7,39 +7,70 @@ const std = @import("std"); const Builder = std.build.Builder; +const raylib = @import("lib.zig").Pkg("."); -pub fn createExe(b: *Builder, name: []const u8, source: []const u8, desc: []const u8) *std.build.LibExeObjStep -{ +const Program = struct { + name: []const u8, + path: []const u8, + desc: []const u8, +}; + +pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); + const target = b.standardTargetOptions(.{}); - var exe = b.addExecutable(name, source); - exe.setBuildMode(mode); - exe.linkSystemLibrary("raylib"); - exe.addPackagePath("raylib", "lib/raylib-zig.zig"); - exe.addPackagePath("raylib-math", "lib/raylib-zig-math.zig"); + const examples = [_]Program{ + .{ + .name = "basic_window", + .path = "examples/core/basic_window.zig", + .desc = "Creates a basic window with text", + }, + .{ + .name = "input_keys", + .path = "examples/core/input_keys.zig", + .desc = "Simple keyboard input", + }, + .{ + .name = "input_mouse", + .path = "examples/core/input_mouse.zig", + .desc = "Simple mouse input", + }, + .{ + .name = "input_mouse_wheel", + .path = "examples/core/input_mouse_wheel.zig", + .desc = "Mouse wheel input", + }, + .{ + .name = "input_multitouch", + .path = "examples/core/input_multitouch.zig", + .desc = "Multitouch input", + }, + .{ + .name = "2d_camera", + .path = "examples/core/2d_camera.zig", + .desc = "Shows the functionality of a 2D camera", + }, + .{ + .name = "models_loading", + .path = "examples/models/models_loading.zig", + .desc = "Loads a model and renders it", + }, + }; - const runExe = exe.run(); - const exeStep = b.step(name, desc); - exeStep.dependOn(&runExe.step); - return exe; -} + const examples_step = b.step("examples", "Builds all the examples"); -pub fn build(b: *Builder) void -{ - var basicWindow = createExe(b, "basic_window" , "examples/core/basic_window.zig" , "Creates a basic window with text"); - var inputKeys = createExe(b, "input_keys" , "examples/core/input_keys.zig" , "Simple keyboard input"); - var inputMouse = createExe(b, "input_mouse" , "examples/core/input_mouse.zig" , "Simple mouse input"); - var inputMouseWheel = createExe(b, "input_mouse_wheel", "examples/core/input_mouse_wheel.zig", "Mouse wheel input"); - var inputMultitouch = createExe(b, "input_multitouch" , "examples/core/input_multitouch.zig" , "Multitouch input"); - var twoDCamera = createExe(b, "2d_camera" , "examples/core/2d_camera.zig" , "Shows the functionality of a 2D camera"); - var modelsLoading = createExe(b, "models_loading" , "examples/models/models_loading.zig" , "Loads a model and renders it"); + for (examples) |ex| { + const exe = b.addExecutable(ex.name, ex.path); + exe.setBuildMode(mode); + exe.setTarget(target); - const examplesStep = b.step("examples", "Builds all the examples"); - examplesStep.dependOn(&basicWindow.step); - examplesStep.dependOn(&inputKeys.step); - examplesStep.dependOn(&inputMouse.step); - examplesStep.dependOn(&inputMouseWheel.step); - examplesStep.dependOn(&inputMultitouch.step); - examplesStep.dependOn(&twoDCamera.step); - examplesStep.dependOn(&modelsLoading.step); -} + raylib.link(exe); + raylib.addAsPackage("raylib", exe); + raylib.math.addAsPackage("raylib-math", exe); + + const run_cmd = exe.run(); + const run_step = b.step(ex.name, ex.desc); + run_step.dependOn(&run_cmd.step); + examples_step.dependOn(&exe.step); + } +} \ No newline at end of file diff --git a/lib.zig b/lib.zig new file mode 100644 index 0000000..2fdfb89 --- /dev/null +++ b/lib.zig @@ -0,0 +1,42 @@ +const std = @import("std"); +const Builder = std.build.Builder; +const LibExeObjStep = std.build.LibExeObjStep; + +pub fn Pkg(pkgdir: comptime []const u8) type { + return struct { + pub fn link(exe: *LibExeObjStep) void { + const raylibFlags = &[_][]const u8{ + "-std=c99", + "-DPLATFORM_DESKTOP", + "-D_POSIX_C_SOURCE", + }; + if (exe.target.toTarget().os.tag == .windows) { + exe.linkSystemLibrary("winmm"); + exe.linkSystemLibrary("gdi32"); + } else { + exe.linkSystemLibrary("m"); + exe.linkSystemLibrary("X11"); + } + exe.linkLibC(); + + exe.addSystemIncludeDir(pkgdir ++ "/raylib/src"); + exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); + exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/models.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/raudio.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/rglfw.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/shapes.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/text.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/textures.c", raylibFlags); + exe.addCSourceFile(pkgdir ++ "/raylib/src/utils.c", raylibFlags); + } + pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void { + to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig"); + } + pub const math = struct { + pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void { + to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig-math.zig"); + } + }; + }; +} diff --git a/raylib b/raylib new file mode 160000 index 0000000..7ef114d --- /dev/null +++ b/raylib @@ -0,0 +1 @@ +Subproject commit 7ef114d1da2c34a70bba5442497103441647d8f3 From 6ece4e99f052e01d649a06817c7b5a92ee4f5ba0 Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Sun, 24 May 2020 06:04:21 -0500 Subject: [PATCH 2/9] add argument to Pkg().link to enable linking to system raylib --- build.zig | 6 ++++-- lib.zig | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 0ada318..aa7a60a 100755 --- a/build.zig +++ b/build.zig @@ -58,13 +58,15 @@ pub fn build(b: *Builder) void { }; const examples_step = b.step("examples", "Builds all the examples"); + const system_lib = b.option(bool, "system-raylib", "link to preinstalled raylib libraries") orelse false; for (examples) |ex| { const exe = b.addExecutable(ex.name, ex.path); + exe.setBuildMode(mode); exe.setTarget(target); - raylib.link(exe); + raylib.link(exe, system_lib); raylib.addAsPackage("raylib", exe); raylib.math.addAsPackage("raylib-math", exe); @@ -73,4 +75,4 @@ pub fn build(b: *Builder) void { run_step.dependOn(&run_cmd.step); examples_step.dependOn(&exe.step); } -} \ No newline at end of file +} diff --git a/lib.zig b/lib.zig index 2fdfb89..edecbb8 100644 --- a/lib.zig +++ b/lib.zig @@ -4,12 +4,13 @@ const LibExeObjStep = std.build.LibExeObjStep; pub fn Pkg(pkgdir: comptime []const u8) type { return struct { - pub fn link(exe: *LibExeObjStep) void { + pub fn link(exe: *LibExeObjStep, system_lib: bool) void { const raylibFlags = &[_][]const u8{ "-std=c99", "-DPLATFORM_DESKTOP", "-D_POSIX_C_SOURCE", }; + if (exe.target.toTarget().os.tag == .windows) { exe.linkSystemLibrary("winmm"); exe.linkSystemLibrary("gdi32"); @@ -19,6 +20,11 @@ pub fn Pkg(pkgdir: comptime []const u8) type { } exe.linkLibC(); + if (system_lib) { + exe.linkSystemLibrary("raylib"); + return; + } + exe.addSystemIncludeDir(pkgdir ++ "/raylib/src"); exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags); @@ -30,6 +36,7 @@ pub fn Pkg(pkgdir: comptime []const u8) type { exe.addCSourceFile(pkgdir ++ "/raylib/src/textures.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/utils.c", raylibFlags); } + pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void { to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig"); } From 44fee6a55030dff666bfaf12ae4a219ab357cc50 Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Sun, 24 May 2020 06:42:03 -0500 Subject: [PATCH 3/9] support mac and bsd --- lib.zig | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/lib.zig b/lib.zig index edecbb8..9073583 100644 --- a/lib.zig +++ b/lib.zig @@ -11,12 +11,38 @@ pub fn Pkg(pkgdir: comptime []const u8) type { "-D_POSIX_C_SOURCE", }; - if (exe.target.toTarget().os.tag == .windows) { - exe.linkSystemLibrary("winmm"); - exe.linkSystemLibrary("gdi32"); - } else { - exe.linkSystemLibrary("m"); - exe.linkSystemLibrary("X11"); + switch (exe.target.toTarget().os.tag) { + .windows => { + exe.linkSystemLibrary("winmm"); + exe.linkSystemLibrary("gdi32"); + exe.linkSystemLibrary("opengl32"); + }, + .macosx => { + exe.linkFramework("OpenGL"); + exe.linkFramework("Cocoa"); + exe.linkFramework("IOKit"); + exe.linkFramework("CoreAudio"); + exe.linkFramework("CoreVideo"); + }, + .freebsd, .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"); + }, } exe.linkLibC(); From 8771f17efbc52c6c063828221bbef2e6454d7bea Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Sun, 24 May 2020 15:31:08 -0500 Subject: [PATCH 4/9] attempt to automatically fetch raylib submodule if building against its source code --- lib.zig | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib.zig b/lib.zig index 9073583..d249b4c 100644 --- a/lib.zig +++ b/lib.zig @@ -4,6 +4,7 @@ const LibExeObjStep = std.build.LibExeObjStep; pub fn Pkg(pkgdir: comptime []const u8) type { return struct { + var ran_git = false; pub fn link(exe: *LibExeObjStep, system_lib: bool) void { const raylibFlags = &[_][]const u8{ "-std=c99", @@ -51,6 +52,13 @@ pub fn Pkg(pkgdir: comptime []const u8) type { return; } + fetchSubmodules(exe.builder) catch + std.debug.warn( + \\Warning: + \\Unable to fetch git submodule(s) Assuming package folder is not under + \\version control. If build fails, this is probably why. + , .{}); + exe.addSystemIncludeDir(pkgdir ++ "/raylib/src"); exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags); @@ -63,6 +71,34 @@ pub fn Pkg(pkgdir: comptime []const u8) type { exe.addCSourceFile(pkgdir ++ "/raylib/src/utils.c", raylibFlags); } + fn fetchSubmodules(b: *Builder) !void { + if (ran_git) return; + ran_git = true; + + std.debug.warn("attempting to fetch submodule(s)...\n", .{}); + + const git_proc = std.ChildProcess.init( + &[_][]const u8{ "git", "submodule", "update", "--init" }, + b.allocator, + ) catch { + std.debug.warn("unable to create child process for git. build interrupted\n", .{}); + std.os.exit(1); + }; + + const term = git_proc.spawnAndWait() catch { + std.debug.warn("unable to spawn child processfor git. build interrupted\n", .{}); + std.os.exit(1); + }; + + switch (term) { + .Exited => |code| if (code != 0) return error.GitFail, + else => { + std.debug.warn("git terminated unexpectedly. build interrupted\n", .{}); + std.os.exit(1); + }, + } + } + pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void { to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig"); } From 7fc94954b9b8864f1597ebf74d4ea50a02b7a9aa Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Sun, 24 May 2020 18:13:31 -0500 Subject: [PATCH 5/9] adapt projectSetup.sh for use with lib.zig and raylib submodule --- lib.zig | 4 ++-- projectSetup.sh | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib.zig b/lib.zig index d249b4c..c82b362 100644 --- a/lib.zig +++ b/lib.zig @@ -84,9 +84,9 @@ pub fn Pkg(pkgdir: comptime []const u8) type { std.debug.warn("unable to create child process for git. build interrupted\n", .{}); std.os.exit(1); }; - + git_proc.cwd = pkgdir; const term = git_proc.spawnAndWait() catch { - std.debug.warn("unable to spawn child processfor git. build interrupted\n", .{}); + std.debug.warn("unable to spawn child process for git. build interrupted\n", .{}); std.os.exit(1); }; diff --git a/projectSetup.sh b/projectSetup.sh index 5c47142..ce82ed5 100755 --- a/projectSetup.sh +++ b/projectSetup.sh @@ -6,27 +6,35 @@ fi mkdir "$PROJECT_NAME" && cd "$PROJECT_NAME" || exit touch build.zig +echo "generating project files..." +echo 'const std = @import("std"); +const Builder = std.build.Builder; +const raylib = @import("raylib-zig/lib.zig").Pkg("raylib-zig"); //call .Pkg() with the folder raylib-zig is in relative to project build.zig -echo 'const Builder = @import("std").build.Builder; pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); - const exe = b.addExecutable("'"$PROJECT_NAME"'", "src/main.zig"); + const target = b.standardTargetOptions(.{}); + + const system_lib = b.option(bool, "system-raylib", "link to preinstalled raylib libraries") orelse false; + + const exe = b.addExecutable("'$PROJECT_NAME'", "src/main.zig"); exe.setBuildMode(mode); - exe.linkSystemLibrary("raylib"); - exe.addPackagePath("raylib", "raylib-zig/raylib-zig.zig"); - exe.install(); + exe.setTarget(target); + + raylib.link(exe, system_lib); + raylib.addAsPackage("raylib", exe); + raylib.math.addAsPackage("raylib-math", exe); const run_cmd = exe.run(); - run_cmd.step.dependOn(b.getInstallStep()); - - const run_step = b.step("run", "Run the app"); + const run_step = b.step("run", "run '$PROJECT_NAME'"); run_step.dependOn(&run_cmd.step); + + exe.install(); } ' >> build.zig mkdir src -mkdir raylib-zig -cp ../lib/* raylib-zig -cp ../examples/core/basic_window.zig src -mv src/basic_window.zig src/main.zig \ No newline at end of file +cp ../examples/core/basic_window.zig src/main.zig +echo "cloning raylib-zig inside of project..." +git clone ../ raylib-zig From 92f9aca7439f0996d264f7193edc3060c89ba7d2 Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Tue, 26 May 2020 04:39:52 -0500 Subject: [PATCH 6/9] exclude build of raylibs vendored glfw on macosx --- lib.zig | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib.zig b/lib.zig index c82b362..174e4db 100644 --- a/lib.zig +++ b/lib.zig @@ -11,21 +11,30 @@ pub fn Pkg(pkgdir: comptime []const u8) type { "-DPLATFORM_DESKTOP", "-D_POSIX_C_SOURCE", }; - - switch (exe.target.toTarget().os.tag) { + const target_os = exe.target.toTarget().os.tag; + switch (target_os) { .windows => { exe.linkSystemLibrary("winmm"); exe.linkSystemLibrary("gdi32"); exe.linkSystemLibrary("opengl32"); }, .macosx => { + var buffer: [100]u8 = undefined; + + const frameworkDir = std.fmt.bufPrint(buffer[0..], "/Library/Developer/CommandLineTools/SDKs/MACOSX{}.{}.sdk/System/Library/Frameworks", .{ + exe.target.toTarget().os.version_range.semver.max.major, + exe.target.toTarget().os.version_range.semver.max.minor, + }) catch unreachable; + + exe.addFrameworkDir(frameworkDir); + exe.linkSystemLibrary("glfw"); exe.linkFramework("OpenGL"); exe.linkFramework("Cocoa"); exe.linkFramework("IOKit"); exe.linkFramework("CoreAudio"); exe.linkFramework("CoreVideo"); }, - .freebsd, .netbsd, .dragonfly => { + .freebsd, .openbsd, .netbsd, .dragonfly => { exe.linkSystemLibrary("GL"); exe.linkSystemLibrary("rt"); exe.linkSystemLibrary("dl"); @@ -59,12 +68,14 @@ pub fn Pkg(pkgdir: comptime []const u8) type { \\version control. If build fails, this is probably why. , .{}); - exe.addSystemIncludeDir(pkgdir ++ "/raylib/src"); - exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); + exe.addIncludeDir(pkgdir ++ "/raylib/src"); + exe.addIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); + exe.addIncludeDir(pkgdir ++ "/raylib/src/external/glfw/deps/mingw"); exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/models.c", raylibFlags); + if (target_os != .macosx) + exe.addCSourceFile(pkgdir ++ "/raylib/src/rglfw.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/raudio.c", raylibFlags); - exe.addCSourceFile(pkgdir ++ "/raylib/src/rglfw.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/shapes.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/text.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/textures.c", raylibFlags); From 0fc7e6875439dd18bfb1c23eb87e662880c8fb8e Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Wed, 27 May 2020 13:59:43 +1000 Subject: [PATCH 7/9] Silence OpenGL depreciation warnings on macOS --- lib.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib.zig b/lib.zig index 174e4db..c77b8e2 100644 --- a/lib.zig +++ b/lib.zig @@ -10,6 +10,7 @@ pub fn Pkg(pkgdir: comptime []const u8) type { "-std=c99", "-DPLATFORM_DESKTOP", "-D_POSIX_C_SOURCE", + "-DGL_SILENCE_DEPRECATION" }; const target_os = exe.target.toTarget().os.tag; switch (target_os) { From 1a955c291e3d94fe19ef1b9bf3c8fdad381ec8ea Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Wed, 27 May 2020 06:32:27 -0500 Subject: [PATCH 8/9] stub out macosx stuff --- lib.zig | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib.zig b/lib.zig index c77b8e2..377805f 100644 --- a/lib.zig +++ b/lib.zig @@ -10,7 +10,7 @@ pub fn Pkg(pkgdir: comptime []const u8) type { "-std=c99", "-DPLATFORM_DESKTOP", "-D_POSIX_C_SOURCE", - "-DGL_SILENCE_DEPRECATION" + "-DGL_SILENCE_DEPRECATION", }; const target_os = exe.target.toTarget().os.tag; switch (target_os) { @@ -19,21 +19,12 @@ pub fn Pkg(pkgdir: comptime []const u8) type { exe.linkSystemLibrary("gdi32"); exe.linkSystemLibrary("opengl32"); }, - .macosx => { - var buffer: [100]u8 = undefined; - - const frameworkDir = std.fmt.bufPrint(buffer[0..], "/Library/Developer/CommandLineTools/SDKs/MACOSX{}.{}.sdk/System/Library/Frameworks", .{ - exe.target.toTarget().os.version_range.semver.max.major, - exe.target.toTarget().os.version_range.semver.max.minor, - }) catch unreachable; - - exe.addFrameworkDir(frameworkDir); - exe.linkSystemLibrary("glfw"); - exe.linkFramework("OpenGL"); - exe.linkFramework("Cocoa"); - exe.linkFramework("IOKit"); - exe.linkFramework("CoreAudio"); - exe.linkFramework("CoreVideo"); + .macosx => if (system_lib) { + std.debug.warn("TODO: add libraries necessary for system_lib linking on macosx (maybe just glfw?)", .{}); + std.os.exit(1); + } else { + std.debug.warn("compiling raylib is unsupported on macosx\n", .{}); + std.os.exit(1); }, .freebsd, .openbsd, .netbsd, .dragonfly => { exe.linkSystemLibrary("GL"); From c2ba0af539a0242624c399bce54d841d08c727a2 Mon Sep 17 00:00:00 2001 From: Jesse Rudolph Date: Wed, 27 May 2020 20:18:39 -0500 Subject: [PATCH 9/9] use rlglfw only on windows apparently building glfw is non-trivial on linux, and rglfw.c only really exists in service of building raylib on windows requiring fewer steps --- lib.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib.zig b/lib.zig index 377805f..d8e9c32 100644 --- a/lib.zig +++ b/lib.zig @@ -18,6 +18,10 @@ pub fn Pkg(pkgdir: comptime []const u8) type { exe.linkSystemLibrary("winmm"); exe.linkSystemLibrary("gdi32"); exe.linkSystemLibrary("opengl32"); + // build vendored glfw as well + exe.addIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); + exe.addIncludeDir(pkgdir ++ "/raylib/src/external/glfw/deps/mingw"); + exe.addCSourceFile(pkgdir ++ "/raylib/src/rglfw.c", raylibFlags); }, .macosx => if (system_lib) { std.debug.warn("TODO: add libraries necessary for system_lib linking on macosx (maybe just glfw?)", .{}); @@ -27,6 +31,7 @@ pub fn Pkg(pkgdir: comptime []const u8) type { std.os.exit(1); }, .freebsd, .openbsd, .netbsd, .dragonfly => { + exe.linkSystemLibrary("glfw"); exe.linkSystemLibrary("GL"); exe.linkSystemLibrary("rt"); exe.linkSystemLibrary("dl"); @@ -39,6 +44,7 @@ pub fn Pkg(pkgdir: comptime []const u8) type { exe.linkSystemLibrary("Xcursor"); }, else => { // linux and possibly others + exe.linkSystemLibrary("glfw"); exe.linkSystemLibrary("GL"); exe.linkSystemLibrary("rt"); exe.linkSystemLibrary("dl"); @@ -61,12 +67,9 @@ pub fn Pkg(pkgdir: comptime []const u8) type { , .{}); exe.addIncludeDir(pkgdir ++ "/raylib/src"); - exe.addIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include"); - exe.addIncludeDir(pkgdir ++ "/raylib/src/external/glfw/deps/mingw"); + exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/models.c", raylibFlags); - if (target_os != .macosx) - exe.addCSourceFile(pkgdir ++ "/raylib/src/rglfw.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/raudio.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/shapes.c", raylibFlags); exe.addCSourceFile(pkgdir ++ "/raylib/src/text.c", raylibFlags);