remove zig files

This commit is contained in:
Fabien Freling 2023-12-18 22:21:03 +01:00
parent e6c28313e3
commit 25fa800391
13 changed files with 6 additions and 280 deletions

1
.gitignore vendored
View file

@ -1 +0,0 @@
build/

6
.gitmodules vendored
View file

@ -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

5
3rd-party/Tupfile vendored
View file

@ -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

1
3rd-party/raygui vendored

@ -1 +0,0 @@
Subproject commit 499e8bf7b1d9b0a92af8f685e646bc61f13c6dff

6
3rd-party/raygui.c vendored
View file

@ -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"

1
3rd-party/raylib vendored

@ -1 +0,0 @@
Subproject commit 18bedbd0952c27b0eb8bc5df0df4acf589cef181

View file

View file

@ -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);
}

View file

@ -1,2 +1 @@
use flake .
export CMAKE_GENERATOR=Ninja

View file

@ -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 ];
};
};
};
}

View file

@ -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 {}

View file

@ -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());
}

View file

@ -1,5 +0,0 @@
pub usingnamespace @cImport({
@cInclude("raylib.h");
@cInclude("raygui.h");
@cInclude("examples/custom_file_dialog/gui_window_file_dialog.h");
});