mirror of
https://github.com/The-Memory-Managers/cpu-vs-ai.git
synced 2025-09-03 21:48:12 +00:00
Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.zig-cache/
|
||||
zig-out/
|
81
build.zig
Normal file
81
build.zig
Normal file
@@ -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);
|
||||
}
|
18
build.zig.zon
Normal file
18
build.zig.zon
Normal file
@@ -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",
|
||||
},
|
||||
}
|
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@@ -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
|
||||
}
|
37
flake.nix
Normal file
37
flake.nix
Normal file
@@ -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;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
1
include/lib.h
Normal file
1
include/lib.h
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
38
src/main.zig
Normal file
38
src/main.zig
Normal file
@@ -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);
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user