Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

104 wiersze
4.2 KiB

  1. const std = @import("std");
  2. const builtin = @import("builtin");
  3. // This has been tested to work with zig master branch as of commit 87de821 or May 14 2023
  4. fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step {
  5. if (target.getOsTag() == .emscripten) {
  6. @panic("Emscripten building via Zig unsupported");
  7. }
  8. const all = b.step(module, "All " ++ module ++ " examples");
  9. const dir = try std.fs.cwd().openIterableDir(module, .{});
  10. var iter = dir.iterate();
  11. while (try iter.next()) |entry| {
  12. if (entry.kind != .File) continue;
  13. const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
  14. const name = entry.name[0..extension_idx];
  15. const path = try std.fs.path.join(b.allocator, &.{ module, entry.name });
  16. // zig's mingw headers do not include pthread.h
  17. if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
  18. const exe = b.addExecutable(.{
  19. .name = name,
  20. .target = target,
  21. .optimize = optimize,
  22. });
  23. exe.addCSourceFile(path, &[_][]const u8{});
  24. exe.linkLibC();
  25. exe.addObjectFile(switch (target.getOsTag()) {
  26. .windows => "../src/zig-out/lib/raylib.lib",
  27. .linux => "../src/zig-out/lib/libraylib.a",
  28. .macos => "../src/zig-out/lib/libraylib.a",
  29. .emscripten => "../src/zig-out/lib/libraylib.a",
  30. else => @panic("Unsupported OS"),
  31. });
  32. exe.addIncludePath("../src");
  33. exe.addIncludePath("../src/external");
  34. exe.addIncludePath("../src/external/glfw/include");
  35. switch (target.getOsTag()) {
  36. .windows => {
  37. exe.linkSystemLibrary("winmm");
  38. exe.linkSystemLibrary("gdi32");
  39. exe.linkSystemLibrary("opengl32");
  40. exe.addIncludePath("external/glfw/deps/mingw");
  41. exe.defineCMacro("PLATFORM_DESKTOP", null);
  42. },
  43. .linux => {
  44. exe.linkSystemLibrary("GL");
  45. exe.linkSystemLibrary("rt");
  46. exe.linkSystemLibrary("dl");
  47. exe.linkSystemLibrary("m");
  48. exe.linkSystemLibrary("X11");
  49. exe.defineCMacro("PLATFORM_DESKTOP", null);
  50. },
  51. .macos => {
  52. exe.linkFramework("Foundation");
  53. exe.linkFramework("Cocoa");
  54. exe.linkFramework("OpenGL");
  55. exe.linkFramework("CoreAudio");
  56. exe.linkFramework("CoreVideo");
  57. exe.linkFramework("IOKit");
  58. exe.defineCMacro("PLATFORM_DESKTOP", null);
  59. },
  60. else => {
  61. @panic("Unsupported OS");
  62. },
  63. }
  64. b.installArtifact(exe);
  65. var run = b.addRunArtifact(exe);
  66. run.cwd = module;
  67. b.step(name, name).dependOn(&run.step);
  68. all.dependOn(&exe.step);
  69. }
  70. return all;
  71. }
  72. pub fn build(b: *std.Build) !void {
  73. // Standard target options allows the person running `zig build` to choose
  74. // what target to build for. Here we do not override the defaults, which
  75. // means any target is allowed, and the default is native. Other options
  76. // for restricting supported target set are available.
  77. const target = b.standardTargetOptions(.{});
  78. // Standard optimization options allow the person running `zig build` to select
  79. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
  80. // set a preferred release mode, allowing the user to decide how to optimize.
  81. const optimize = b.standardOptimizeOption(.{});
  82. const all = b.getInstallStep();
  83. all.dependOn(try add_module("audio", b, target, optimize));
  84. all.dependOn(try add_module("core", b, target, optimize));
  85. all.dependOn(try add_module("models", b, target, optimize));
  86. all.dependOn(try add_module("others", b, target, optimize));
  87. all.dependOn(try add_module("shaders", b, target, optimize));
  88. all.dependOn(try add_module("shapes", b, target, optimize));
  89. all.dependOn(try add_module("text", b, target, optimize));
  90. all.dependOn(try add_module("textures", b, target, optimize));
  91. }