From 25fa80039169d12b09d6f62e62f38dde54ba6f55 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Mon, 18 Dec 2023 22:21:03 +0100 Subject: [PATCH] remove zig files --- .gitignore | 1 - .gitmodules | 6 --- 3rd-party/Tupfile | 5 -- 3rd-party/raygui | 1 - 3rd-party/raygui.c | 6 --- 3rd-party/raylib | 1 - Tupfile.ini | 0 build.zig | 79 ------------------------------- envrc.sample | 1 - flake.nix | 45 ++---------------- justfile | 22 ++------- src/main.zig | 114 --------------------------------------------- src/raylib.zig | 5 -- 13 files changed, 6 insertions(+), 280 deletions(-) delete mode 100644 .gitignore delete mode 100644 .gitmodules delete mode 100644 3rd-party/Tupfile delete mode 160000 3rd-party/raygui delete mode 100644 3rd-party/raygui.c delete mode 160000 3rd-party/raylib delete mode 100644 Tupfile.ini delete mode 100644 build.zig delete mode 100644 src/main.zig delete mode 100644 src/raylib.zig diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 567609b..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 600b63f..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "3rd-party/raygui"] - path = 3rd-party/raygui - url = https://github.com/raysan5/raygui.git -[submodule "3rd-party/raylib"] - path = 3rd-party/raylib - url = https://github.com/raysan5/raylib.git diff --git a/3rd-party/Tupfile b/3rd-party/Tupfile deleted file mode 100644 index c307e54..0000000 --- a/3rd-party/Tupfile +++ /dev/null @@ -1,5 +0,0 @@ -BDIR := ../build/raygui - -: raygui.c |> clang -c %f -o %o -I../build/raylib/include -Iraygui/src |> $(BDIR)/%B.o -: $(BDIR)/*.o |> ar crs %o %f |> $(BDIR)/libraygui.a - diff --git a/3rd-party/raygui b/3rd-party/raygui deleted file mode 160000 index 499e8bf..0000000 --- a/3rd-party/raygui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 499e8bf7b1d9b0a92af8f685e646bc61f13c6dff diff --git a/3rd-party/raygui.c b/3rd-party/raygui.c deleted file mode 100644 index 2f9910a..0000000 --- a/3rd-party/raygui.c +++ /dev/null @@ -1,6 +0,0 @@ -#define RAYGUI_IMPLEMENTATION -#include "raygui.h" -#undef RAYGUI_IMPLEMENTATION - -#define GUI_WINDOW_FILE_DIALOG_IMPLEMENTATION -#include "../examples/custom_file_dialog/gui_window_file_dialog.h" diff --git a/3rd-party/raylib b/3rd-party/raylib deleted file mode 160000 index 18bedbd..0000000 --- a/3rd-party/raylib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 18bedbd0952c27b0eb8bc5df0df4acf589cef181 diff --git a/Tupfile.ini b/Tupfile.ini deleted file mode 100644 index e69de29..0000000 diff --git a/build.zig b/build.zig deleted file mode 100644 index efae36f..0000000 --- a/build.zig +++ /dev/null @@ -1,79 +0,0 @@ -const std = @import("std"); - -// Although this function looks imperative, note that its job is to -// declaratively construct a build graph that will be executed by an external -// runner. -pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - - const exe = b.addExecutable(.{ - .name = "fabapp", - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, - }); - - // - // C dependencies - // - exe.linkLibC(); - - // Raylib - exe.addIncludePath(.{ .path = "build/raylib/include" }); - exe.addLibraryPath(.{ .path = "build/raylib" }); - exe.linkSystemLibrary("raylib"); - - // Raygui - exe.addIncludePath(.{ .path = "3rd-party/raygui/src" }); - exe.addIncludePath(.{ .path = "3rd-party/raygui" }); - exe.addLibraryPath(.{ .path = "build/raygui" }); - exe.linkSystemLibrary("raygui"); - - // SQLite - exe.linkSystemLibrary("sqlite3"); - - // This declares intent for the executable to be installed into the - // standard location when the user invokes the "install" step (the default - // step when running `zig build`). - b.installArtifact(exe); - - // This *creates* a Run step in the build graph, to be executed when another - // step is evaluated that depends on it. The next line below will establish - // such a dependency. - 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()); - - // This allows the user to pass arguments to the application in the build - // command itself, like this: `zig build run -- arg1 arg2 etc` - if (b.args) |args| { - run_cmd.addArgs(args); - } - - // This creates a build step. It will be visible in the `zig build --help` menu, - // and can be selected like this: `zig build run` - // This will evaluate the `run` step rather than the default, which is "install". - const run_step = b.step("run", "Run the app"); - run_step.dependOn(&run_cmd.step); - - // Creates a step for unit testing. This only builds the test executable - // but does not run it. - const unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, - }); - - const run_unit_tests = b.addRunArtifact(unit_tests); - - // Similar to creating the run step earlier, this exposes a `test` step to - // the `zig build --help` menu, providing a way for the user to request - // running the unit tests. - const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&run_unit_tests.step); -} diff --git a/envrc.sample b/envrc.sample index 54c13ac..a5dbbcb 100644 --- a/envrc.sample +++ b/envrc.sample @@ -1,2 +1 @@ use flake . -export CMAKE_GENERATOR=Ninja diff --git a/flake.nix b/flake.nix index 8df9335..628ed9a 100644 --- a/flake.nix +++ b/flake.nix @@ -29,49 +29,10 @@ devShells.default = with pkgs; mkShell { - # EM_CONFIG = pkgs.writeText ".emscripten" '' - # EMSCRIPTEN_ROOT = '${pkgs.emscripten}/share/emscripten' - # LLVM_ROOT = '${pkgs.emscripten.llvmEnv}/bin' - # BINARYEN_ROOT = '${pkgs.binaryen}' - # NODE_JS = '${pkgs.nodejs-18_x}/bin/node' - # CACHE = '${toString ./.cache}' - # ''; - - nativeBuildInputs = [ clang cmake just ninja tup ]; - - buildInputs = [ - sqlite - - # Android - android-tools - godot_4 - - # Zig / webAssembly impl. - zig - zls - emscripten - - # Linux graphical deps - ## X11 - xorg.libX11 - xorg.libXcursor - xorg.libXi - xorg.libXext - xorg.libXrandr - xorg.libXinerama - xorg.libxcb - libGL - libGLU - pkg-config - - ## Wayland - wayland-protocols - wayland - libxkbcommon - ]; - + LD_LIBRARY_PATH = lib.makeLibraryPath [ stdenv.cc.cc ]; # For libstdc++.so.6 + nativeBuildInputs = [ clang just android-tools godot_4 ]; + buildInputs = [ sqlite ]; }; - }; }; } diff --git a/justfile b/justfile index 15f5c3d..d79686d 100644 --- a/justfile +++ b/justfile @@ -1,32 +1,17 @@ -cpp_build_dir := justfile_directory() / "build" - alias b := build alias r := run alias t := test alias fmt := format +edit: + godot4 --editor godot/project.godot + pre-build: git submodule update --init --recursive -raylib: - mkdir -p {{ cpp_build_dir }} - cmake -B {{ cpp_build_dir }} -S {{ justfile_directory() }}/3rd-party/raylib \ - -DBUILD_EXAMPLES=OFF - cmake --build {{ cpp_build_dir }} - -raygui: - tup - -deps: pre-build raylib raygui - build: zig build -Doptimize=Debug -# web-build: pre-build -# # zig build-lib src/main.zig -target wasm32-freestanding -dynamic -rdynamic -# zig build -Dtarget=wasm32-emscripten --sysroot /nix/store/lszbak7w3k1jmx3cm3qb2qzillsib71v-emscripten-3.1.24/bin/emcc -# # zig build -Dtarget=wasm32-emscripten - run: nixGL zig build run -- {{ justfile_directory() }}/life.sqlite3 @@ -34,5 +19,4 @@ test: zig build test format: - fd -e zig -X zig fmt {} fd -e nix -X nix fmt {} diff --git a/src/main.zig b/src/main.zig deleted file mode 100644 index 695cf2e..0000000 --- a/src/main.zig +++ /dev/null @@ -1,114 +0,0 @@ -const std = @import("std"); -const raylib = @import("raylib.zig"); -const c = @cImport({ - @cInclude("sqlite3.h"); -}); - -const StateTag = enum { - unloaded, - loaded, -}; - -const State = union(StateTag) { - unloaded: void, - loaded: *c.sqlite3, -}; - -fn loadSqlite(path: [:0]const u8) State { - var db_opt: ?*c.sqlite3 = undefined; - - const result = c.sqlite3_open(path.ptr, &db_opt); - if (result != c.SQLITE_OK) { - std.debug.print("[SQLite] err {}: {s}\n", .{ result, c.sqlite3_errmsg(db_opt) }); - _ = c.sqlite3_close(db_opt); - return State{ .unloaded = {} }; - } - - if (db_opt) |db| { - std.debug.print("[SQLite] Success\n", .{}); - return State{ .loaded = db }; - } - - return State{ .unloaded = {} }; -} - -pub fn main() !void { - var state = State{ .unloaded = {} }; - - const alloc = std.heap.c_allocator; - - const args = try std.process.argsAlloc(alloc); - defer std.process.argsFree(alloc, args); - - std.debug.print("Arguments: {s}\n", .{args}); - - if (args.len > 1) { - state = loadSqlite(args[1]); - } - - const screen_width = 800; - const screen_height = 450; - raylib.InitWindow(screen_width, screen_height, "Loggy"); - raylib.SetTargetFPS(60); - - var file_dialog_state = raylib.InitGuiWindowFileDialog(raylib.GetWorkingDirectory()); - // const ext = ".sqlite3"; - // @memcpy(file_dialog_state.filterExt[0..ext.len], ext); - var checked = false; - - while (!raylib.WindowShouldClose()) { - // - // Update - // - { - if (file_dialog_state.SelectFilePressed) { - // C-strings -> slices - const dir = std.mem.sliceTo(&file_dialog_state.dirPathText, 0); - const file = std.mem.sliceTo(&file_dialog_state.fileNameText, 0); - - // slices -> C-string (null-terminated) - const db_path = try std.fs.path.joinZ(alloc, &[_][]const u8{ dir, file }); - defer alloc.free(db_path); - state = loadSqlite(db_path); - } - file_dialog_state.SelectFilePressed = false; - } - - // - // Render - // - { - raylib.BeginDrawing(); - defer raylib.EndDrawing(); - raylib.ClearBackground(raylib.RAYWHITE); - - switch (state) { - .unloaded => { - if (file_dialog_state.windowActive) raylib.GuiLock(); - defer raylib.GuiUnlock(); - - const button_size = 200; - if (raylib.GuiButton(.{ .x = (screen_width - button_size) / 2, .y = (screen_height - button_size) / 2, .width = 200, .height = 200 }, "Load db file") == 1) { - file_dialog_state.windowActive = true; - } - }, - - .loaded => |*db| { - _ = db; - const label_rect: raylib.Rectangle = .{ .x = 10, .y = 10, .width = 40, .height = 40 }; - _ = raylib.GuiCheckBox(label_rect, "Eat well", &checked); - }, - } - - raylib.GuiWindowFileDialog(&file_dialog_state); - } - } - raylib.CloseWindow(); -} - -test "simple test" { - var list = std.ArrayList(i32).init(std.testing.allocator); - defer list.deinit(); // try commenting this out and see if zig detects the memory leak! - try list.append(42); - try std.testing.expectEqual(@as(i32, 42), list.pop()); -} diff --git a/src/raylib.zig b/src/raylib.zig deleted file mode 100644 index 937ee90..0000000 --- a/src/raylib.zig +++ /dev/null @@ -1,5 +0,0 @@ -pub usingnamespace @cImport({ - @cInclude("raylib.h"); - @cInclude("raygui.h"); - @cInclude("examples/custom_file_dialog/gui_window_file_dialog.h"); -});