const std = @import("std"); const builtin = @import("builtin"); const HEAD_location = ".git/HEAD"; const commit_location = ".git/refs/heads/master"; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const root = b.addModule("game-mod", .{ .optimize = optimize, .target = target, .link_libc = true, }); // Adding a build version const build_ver = GetVersionString(b, optimize) catch "Build UNTRACKED"; if (build_ver.len > 0) root.addCMacro("BUILD_VERSION", build_ver); root.addCSourceFiles(.{ .files = &[_][]const u8 { "src/main.c", "src/utils/stringBuilder.c", "src/wren_inter/wren_inter.c", "src/resources/resources.c", "src/resources/config.c", "src/ui_elements/UI.c", "src/ui_elements/TextEditor.c", "src/ui_elements/Button.c", "src/scenes/sceneManager.c", "src/scenes/mainMenu.c", "src/scenes/resultView.c", "src/scenes/puzzleScene.c", "src/puzzles/puzzle.c", } }); // Linking raylib if (builtin.target.os.tag == .windows) { // If you are building on windows you need to provide your own // raylib. Put it in the raylib dir root.addLibraryPath(b.path("raylib/lib/")); root.addIncludePath(b.path("raylib/include/")); } root.linkSystemLibrary("raylib", .{.needed = true}); root.addIncludePath(b.path("include/")); // Linking wren. They do not provide system-wide libraries so you have to // provide them yourself root.addIncludePath(b.path("wren/src/include/")); root.addLibraryPath(b.path("wren/lib/")); root.linkSystemLibrary("wren", .{ .needed = true, .preferred_link_mode = .static, }); const exe = b.addExecutable(.{ .name = "game", .root_module = root, }); b.installArtifact(exe); const run_step = b.step("run", "Run the app"); const run_cmd = b.addRunArtifact(exe); run_step.dependOn(&run_cmd.step); if (b.args) |args| { run_cmd.addArgs(args); } } // Returns a build version. Returns an empty string if build in release mode fn GetVersionString(b: *std.Build, optimization: std.builtin.OptimizeMode) ![]u8 { if (optimization != .Debug) { return ""; } const allocator = b.allocator; var threaded = std.Io.Threaded.init(allocator, .{}); defer threaded.deinit(); const headContents = try std.Io.Dir.cwd().readFileAlloc(threaded.io(), HEAD_location, allocator, .limited(std.math.maxInt(usize))); var headIter = std.mem.tokenizeAny(u8, headContents[0..headContents.len - 1], "/"); var branchName: []const u8 = ""; while (headIter.next()) |token| { branchName = token; } const commitContents = try std.Io.Dir.cwd().readFileAlloc(threaded.io(), commit_location, allocator, .limited(std.math.maxInt(usize))); return try std.fmt.allocPrint(allocator, "\"Build {s}:{s}\"", .{ branchName, commitContents[0..@min(commitContents.len-1, 10)] }); }