summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-07-25 18:35:58 +0300
committerKyren223 <Kyren223@proton.me>2025-07-25 18:35:58 +0300
commitddf14daac53f3a926bc5910e75f5bdfdf435c781 (patch)
treecf78886d4bf3ee2fa606fbb80539773eec758835
Initial commit
-rw-r--r--.gitignore2
-rw-r--r--build.zig81
-rw-r--r--build.zig.zon18
-rw-r--r--flake.lock61
-rw-r--r--flake.nix37
-rw-r--r--include/lib.h1
-rw-r--r--src/lib.c1
-rw-r--r--src/main.zig38
8 files changed, 239 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3389c86
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.zig-cache/
+zig-out/
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..b82734b
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,81 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+
+ const exe_mod = b.createModule(.{
+ .root_source_file = b.path("src/main.zig"),
+ .target = target,
+ .optimize = optimize,
+ });
+
+ const exe = b.addExecutable(.{
+ .name = "hackathon",
+ .root_module = exe_mod,
+ });
+
+ // Raylib
+ const raylib_dep = b.dependency("raylib_zig", .{
+ .target = target,
+ .optimize = optimize,
+
+ // See https://github.com/Not-Nik/raylib-zig/issues/219
+ // We can either have users download both, or maybe try disabling lld?
+ .shared = true,
+ });
+
+ const raylib = raylib_dep.module("raylib"); // main raylib module
+ const raygui = raylib_dep.module("raygui"); // raygui module
+ const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
+
+ exe.linkLibrary(raylib_artifact);
+ exe.root_module.addImport("raylib", raylib);
+ exe.root_module.addImport("raygui", raygui);
+
+ // Build the C library
+ const lib_c = b.addStaticLibrary(.{
+ .name = "c_lib",
+ .target = target,
+ .optimize = optimize,
+ });
+
+ lib_c.addCSourceFile(.{
+ .file = b.path("src/lib.c"),
+ .flags = &[_][]const u8{"-std=c99"},
+ });
+ lib_c.addIncludePath(b.path("include"));
+ lib_c.linkLibC();
+
+ exe.addIncludePath(b.path("include"));
+ exe.addIncludePath(b.path("src"));
+ exe.linkLibrary(lib_c);
+ exe.linkLibC();
+
+ b.installArtifact(exe);
+
+ const run_cmd = b.addRunArtifact(exe);
+
+ // By making the run step depend on the install step, it will be run from the
+ // installation directory rather than directly from within the cache directory.
+ // This is not necessary, however, if the application depends on other installed
+ // files, this ensures they will be present and in the expected location.
+ run_cmd.step.dependOn(b.getInstallStep());
+
+ // Allow passing args to the exe like this: `zig build run -- arg1 arg2 etc`
+ if (b.args) |args| {
+ run_cmd.addArgs(args);
+ }
+
+ const run_step = b.step("run", "Run the app");
+ run_step.dependOn(&run_cmd.step);
+
+ const exe_tests = b.addTest(.{
+ .root_module = exe_mod,
+ });
+
+ const run_exe_tests = b.addRunArtifact(exe_tests);
+
+ const test_step = b.step("test", "Run tests");
+ test_step.dependOn(&run_exe_tests.step);
+}
diff --git a/build.zig.zon b/build.zig.zon
new file mode 100644
index 0000000..416d2f5
--- /dev/null
+++ b/build.zig.zon
@@ -0,0 +1,18 @@
+.{
+ .name = .hackathon,
+ .version = "0.0.0",
+ .fingerprint = 0x8b3af64ffae8ae0f,
+ .minimum_zig_version = "0.14.0",
+ .dependencies = .{
+ .raylib_zig = .{
+ .url = "git+https://github.com/Not-Nik/raylib-zig?ref=devel#5013830647196ba938a3a25a36b8245606e9a9cd",
+ .hash = "raylib_zig-5.6.0-dev-KE8REM0tBQAHVn9Xjqlgu9l1qgfTmP8aJa1kLhD584bV",
+ },
+ },
+ .paths = .{
+ "build.zig",
+ "build.zig.zon",
+ "src",
+ "include",
+ },
+}
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..80a25ac
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,61 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1731533236,
+ "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1753250450,
+ "narHash": "sha256-i+CQV2rPmP8wHxj0aq4siYyohHwVlsh40kV89f3nw1s=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "fc02ee70efb805d3b2865908a13ddd4474557ecf",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..3ac1538
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,37 @@
+{
+ description = "Run a zig project with raylib-zig bindings";
+
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = { nixpkgs, flake-utils, ... }:
+ flake-utils.lib.eachDefaultSystem (
+ system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ nativeBuildInputs = with pkgs; [
+ pkg-config
+ ];
+
+ buildInputs = with pkgs; [
+ xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr xorg.libXinerama # For x11
+ libxkbcommon wayland glfw-wayland wayland-scanner # For wayland
+ SDL
+ ];
+
+ in {
+ devShells.default = pkgs.mkShell {inherit nativeBuildInputs buildInputs;};
+
+ packages.default = pkgs.stdenv.mkDerivation {
+ pname = "template";
+ version = "0.0.0";
+ src = ./.;
+
+ inherit nativeBuildInputs;
+ inherit buildInputs;
+ LD_LIBRARY_PATH = flake-utils.lib.makeLibraryPath buildInputs;
+ };
+ }
+ );
+}
diff --git a/include/lib.h b/include/lib.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/include/lib.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/src/lib.c b/src/lib.c
new file mode 100644
index 0000000..a82b12f
--- /dev/null
+++ b/src/lib.c
@@ -0,0 +1 @@
+#include "lib.h"
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..5cfbe53
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,38 @@
+const std = @import("std");
+const rl = @import("raylib");
+
+pub fn main() anyerror!void {
+ // var frameArena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
+ // const allocator = frameArena.allocator();
+ // defer frameArena.deinit();
+
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const screenWidth = 800;
+ const screenHeight = 450;
+
+ rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
+ defer rl.closeWindow(); // Close window and OpenGL context
+
+ rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
+ rl.setExitKey(.caps_lock);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!rl.windowShouldClose()) { // Detect window close button or ESC key
+ // Update
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ rl.beginDrawing();
+ defer rl.endDrawing();
+
+ rl.clearBackground(.white);
+
+ rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray);
+ //----------------------------------------------------------------------------------
+ }
+}