build.zig 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const std = @import("std");
  2. const builtin = @import("builtin");
  3. fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step {
  4. // Standard release options allow the person running `zig build` to select
  5. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
  6. const mode = b.standardReleaseOptions();
  7. const all = b.step(module, "All " ++ module ++ " examples");
  8. const dir = try std.fs.cwd().openDir(
  9. module,
  10. .{ .iterate = true },
  11. );
  12. var iter = dir.iterate();
  13. while (try iter.next()) |entry| {
  14. if (entry.kind != .File) continue;
  15. const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
  16. const name = entry.name[0..extension_idx];
  17. const path = try std.fs.path.join(b.allocator, &.{ module, entry.name });
  18. // zig's mingw headers do not include pthread.h
  19. if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
  20. const exe = b.addExecutable(name, path);
  21. exe.setTarget(target);
  22. exe.setBuildMode(mode);
  23. exe.linkLibC();
  24. exe.addObjectFile(switch (target.getOsTag()) {
  25. .windows => "../src/raylib.lib",
  26. .linux => "../src/libraylib.a",
  27. else => @panic("Unsupported OS"),
  28. });
  29. exe.addIncludeDir("../src");
  30. exe.addIncludeDir("../src/external");
  31. exe.addIncludeDir("../src/external/glfw/include");
  32. switch (exe.target.toTarget().os.tag) {
  33. .windows => {
  34. exe.linkSystemLibrary("winmm");
  35. exe.linkSystemLibrary("gdi32");
  36. exe.linkSystemLibrary("opengl32");
  37. exe.addIncludeDir("external/glfw/deps/mingw");
  38. },
  39. .linux => {
  40. exe.linkSystemLibrary("GL");
  41. exe.linkSystemLibrary("rt");
  42. exe.linkSystemLibrary("dl");
  43. exe.linkSystemLibrary("m");
  44. exe.linkSystemLibrary("X11");
  45. },
  46. else => {
  47. @panic("Unsupported OS");
  48. },
  49. }
  50. exe.setOutputDir(module);
  51. var run = exe.run();
  52. run.step.dependOn(&b.addInstallArtifact(exe).step);
  53. run.cwd = module;
  54. b.step(name, name).dependOn(&run.step);
  55. all.dependOn(&exe.step);
  56. }
  57. return all;
  58. }
  59. pub fn build(b: *std.build.Builder) !void {
  60. // Standard target options allows the person running `zig build` to choose
  61. // what target to build for. Here we do not override the defaults, which
  62. // means any target is allowed, and the default is native. Other options
  63. // for restricting supported target set are available.
  64. const target = b.standardTargetOptions(.{});
  65. const all = b.getInstallStep();
  66. all.dependOn(try add_module("audio", b, target));
  67. all.dependOn(try add_module("core", b, target));
  68. all.dependOn(try add_module("models", b, target));
  69. all.dependOn(try add_module("others", b, target));
  70. all.dependOn(try add_module("physics", b, target));
  71. all.dependOn(try add_module("shaders", b, target));
  72. all.dependOn(try add_module("shapes", b, target));
  73. all.dependOn(try add_module("text", b, target));
  74. all.dependOn(try add_module("textures", b, target));
  75. }