From 52c1a4e7d003f0be64b2e2eec27307f03b0f0727 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 14 Oct 2021 12:45:41 +0200 Subject: [PATCH 1/2] Update SPONSORS.md --- SPONSORS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SPONSORS.md b/SPONSORS.md index db05789c7..d128414ec 100644 --- a/SPONSORS.md +++ b/SPONSORS.md @@ -62,7 +62,7 @@ The following people has **sponsored raylib** in the past, allowing the project ### Notes for Current/Past raylib Sponsor - - **If you are not on the list, feel free to send a PR to add you if desired.** - - **If you want your personal webpage listed along your GitHub account, feel free to send a PR to add it.** - - **If you prefer not to listed in this list, feel free to send a PR to remove it.** + - If you are not on the list, feel free to send a PR to be added (if desired). + - If you want your personal webpage or project listed, feel free to send a PR to be added. + - If you prefer not to be in this list, feel free to send a PR to be remove. From 588131c9d526d6bf63ced0c9a95a660801a3d711 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 14 Oct 2021 07:24:00 -0400 Subject: [PATCH 2/2] Add zig buildfile for examples. (#2051) * Add zig buildfile for examples. - `zig build` to compile all examples - `zig build [module]` to compile all examples for a module (e.g. `zig build core`) - `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`) You can use `-Dtarget=` to compile for a non-native platform, such as `zig build -Dtarget=x86_64-windows-gnu` to compile from Linux to Windows. * Skip pthread example on Windows. * Select appropriate lib file based on target. --- examples/README.md | 18 ++++++++++ examples/build.zig | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 examples/build.zig diff --git a/examples/README.md b/examples/README.md index ddf69fe5c..14d566b23 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,3 +1,21 @@ +## Building the Examples + +The examples assume you have already built the `raylib` library in `../src`. + +### With GNU make + +- `make` builds all examples +- `make [module]` builds all examples for a particular module (e.g `make core`) + +### With Zig + +The [Zig](https://ziglang.org/) toolchain can compile `C` and `C++` in addition to `Zig`. +You may find it easier to use than other toolchains, especially when it comes to cross-compiling. + +- `zig build` to compile all examples +- `zig build [module]` to compile all examples for a module (e.g. `zig build core`) +- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`) + ## EXAMPLES LIST ### category: core diff --git a/examples/build.zig b/examples/build.zig new file mode 100644 index 000000000..c05808bf7 --- /dev/null +++ b/examples/build.zig @@ -0,0 +1,86 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step { + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const all = b.step(module, "All " ++ module ++ " examples"); + const dir = try std.fs.cwd().openDir( + module, + .{ .iterate = true }, + ); + var iter = dir.iterate(); + while (try iter.next()) |entry| { + if (entry.kind != .File) continue; + const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue; + const name = entry.name[0..extension_idx]; + const path = try std.fs.path.join(b.allocator, &.{ module, entry.name }); + + // zig's mingw headers do not include pthread.h + if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue; + + const exe = b.addExecutable(name, path); + exe.setTarget(target); + exe.setBuildMode(mode); + exe.linkLibC(); + exe.addObjectFile(switch (target.getOsTag()) { + .windows => "../src/raylib.lib", + .linux => "../src/libraylib.a", + else => @panic("Unsupported OS"), + }); + + exe.addIncludeDir("../src"); + exe.addIncludeDir("../src/external"); + exe.addIncludeDir("../src/external/glfw/include"); + + switch (exe.target.toTarget().os.tag) { + .windows => { + exe.linkSystemLibrary("winmm"); + exe.linkSystemLibrary("gdi32"); + exe.linkSystemLibrary("opengl32"); + exe.addIncludeDir("external/glfw/deps/mingw"); + }, + .linux => { + exe.linkSystemLibrary("GL"); + exe.linkSystemLibrary("rt"); + exe.linkSystemLibrary("dl"); + exe.linkSystemLibrary("m"); + exe.linkSystemLibrary("X11"); + }, + else => { + @panic("Unsupported OS"); + }, + } + + exe.setOutputDir(module); + + var run = exe.run(); + run.step.dependOn(&b.addInstallArtifact(exe).step); + run.cwd = module; + b.step(name, name).dependOn(&run.step); + all.dependOn(&exe.step); + } + return all; +} + +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(.{}); + + const all = b.getInstallStep(); + + all.dependOn(try add_module("audio", b, target)); + all.dependOn(try add_module("core", b, target)); + all.dependOn(try add_module("models", b, target)); + all.dependOn(try add_module("others", b, target)); + all.dependOn(try add_module("physics", b, target)); + all.dependOn(try add_module("shaders", b, target)); + all.dependOn(try add_module("shapes", b, target)); + all.dependOn(try add_module("text", b, target)); + all.dependOn(try add_module("textures", b, target)); +}