From d0e74454216bd6eaa3358edcfbea43aaf512cb48 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Fri, 25 Oct 2024 13:24:40 +0300 Subject: [PATCH] initial commit --- .gitignore | 2 ++ README.md | 5 +++++ build.zig | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ build.zig.zon | 21 ++++++++++++++++++++ src/main.zig | 36 +++++++++++++++++++++++++++++++++ src/root.zig | 10 ++++++++++ 6 files changed, 129 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 build.zig create mode 100644 build.zig.zon create mode 100644 src/main.zig create mode 100644 src/root.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c046b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache +zig-out \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d49262 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# DAQ view & transform + +```shell +zig build run +``` \ No newline at end of file diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..4ee24fe --- /dev/null +++ b/build.zig @@ -0,0 +1,55 @@ +const std = @import("std"); +const Module = std.Build.Module; + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const libdaq_dep = b.dependency("libdaq", .{}); + _ = libdaq_dep; // TODO: Build libdaq + + var lib: *Module = undefined; + { + lib = b.createModule(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + const unit_tests = b.addTest(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + const run_unit_tests = b.addRunArtifact(unit_tests); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_unit_tests.step); + } + + { + const raylib_dep = b.dependency("raylib-zig", .{ + .target = target, + .optimize = optimize, + }); + + const exe = b.addExecutable(.{ + .name = "daq-view", + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + exe.linkLibrary(raylib_dep.artifact("raylib")); + exe.root_module.addImport("raylib", raylib_dep.module("raylib")); + + b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the program"); + run_step.dependOn(&run_cmd.step); + } +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..072f4b0 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,21 @@ +.{ + .name = "Baigiamasis projektas", + .version = "0.1.0", + + .dependencies = .{ + .libdaq = .{ + .url = "https://github.com/snort3/libdaq/archive/refs/tags/v3.0.17.tar.gz", + .hash = "1220338b42823b08d2f848549d03958b19836b4794c12f9a7875bca37a8f9477a5c0", + }, + .@"raylib-zig" = .{ + .url = "https://github.com/Not-Nik/raylib-zig/archive/43d15b05c2b97cab30103fa2b46cff26e91619ec.tar.gz", + .hash = "12204a223b19043e17b79300413d02f60fc8004c0d9629b8d8072831e352a78bf212" + }, + }, + + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..ba029f9 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const rl = @import("raylib"); + +fn toTraceLogLevel(log_level: std.log.Level) rl.TraceLogLevel { + return switch (log_level) { + .err => rl.TraceLogLevel.log_error, + .warn => rl.TraceLogLevel.log_warning, + .info => rl.TraceLogLevel.log_info, + .debug => rl.TraceLogLevel.log_all, + }; +} + +pub fn main() !void { + rl.setTraceLogLevel(toTraceLogLevel(std.log.default_level)); + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + defer _ = gpa.deinit(); + + _ = allocator; + + rl.initWindow(800, 450, "DAQ view"); + defer rl.closeWindow(); + rl.setWindowState(.{ .window_resizable = true }); + + rl.setTargetFPS(60); + + while (!rl.windowShouldClose()) { + rl.beginDrawing(); + defer rl.endDrawing(); + + rl.clearBackground(rl.Color.white); + + rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray); + } +} diff --git a/src/root.zig b/src/root.zig new file mode 100644 index 0000000..ecfeade --- /dev/null +++ b/src/root.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const testing = std.testing; + +export fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + try testing.expect(add(3, 7) == 10); +}