From 751e6d1fa8efc6b56a89c07c40d956078f8d043e Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Wed, 12 Jul 2023 10:07:05 -0700 Subject: [PATCH] remove old libmach approach (see hexops/mach#858) Signed-off-by: Stephen Gutekanst --- libmach/.gitignore | 2 -- libmach/Makefile | 12 --------- libmach/README.md | 12 --------- libmach/test.c | 52 -------------------------------------- libmach/test.lisp | 63 ---------------------------------------------- 5 files changed, 141 deletions(-) delete mode 100644 libmach/.gitignore delete mode 100644 libmach/Makefile delete mode 100644 libmach/README.md delete mode 100644 libmach/test.c delete mode 100644 libmach/test.lisp diff --git a/libmach/.gitignore b/libmach/.gitignore deleted file mode 100644 index b018793c..00000000 --- a/libmach/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -build/ -test diff --git a/libmach/Makefile b/libmach/Makefile deleted file mode 100644 index f5dd8ce8..00000000 --- a/libmach/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -build/libmach.dylib: ../build.zig ../src/*.zig ../src/**/*.zig - cd ..; zig build - -test: test.c build/libmach.dylib - clang -L./build -lmach -o test test.c - -test_c: test - # my best attempt at cross-platform dynamic linking (for now) - DYLD_LIBRARY_PATH=./build LD_LIBRARY_OATH=./build ./test - -test_lisp: build/libmach.dylib - sbcl --load test.lisp diff --git a/libmach/README.md b/libmach/README.md deleted file mode 100644 index 3344952c..00000000 --- a/libmach/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# libmach - -Build the `libmach` dynamic library by running `make` (or running `zig build` in the parent directory). -The resulting binary should be located in `libmach/build/`. - -Test the functionality of `libmach` using `make test_c` and `make test_lisp`. -These commands use C and Lisp to call into `libmach`, and both should show a blank window for 5 seconds. -If you resize the window, it should print the new dimensions to the standard output. - -Note: `make test_lisp` requires a relatively recent version of Steel Bank Common Lisp (`sbcl`) to be installed, plus Quicklisp. - -You can find the Zig source code for `libmach` in `src/platform/libmach.zig`. diff --git a/libmach/test.c b/libmach/test.c deleted file mode 100644 index 318da1d6..00000000 --- a/libmach/test.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include - -typedef void resize_callback(void*, uint32_t, uint32_t); - -typedef enum MachStatus { - MachStatus_Success = 0x00000000, - MachStatus_Error = 0x00000001, - MachStatus_Force32 = 0x7FFFFFFF -} MachStatus; - -// `libmach` exported API bindings -void* mach_core_init(void); -void mach_core_deinit(void*); -void mach_core_set_should_close(void*); -bool mach_core_window_should_close(void*); -MachStatus mach_core_update(void*, resize_callback); -float mach_core_delta_time(void*); - -void resize_fn(void* core, uint32_t width, uint32_t height) { - printf("Resize callback: %u %u\n", width, height); -} - -static float elapsed = 0; - -int main() { - void* core = mach_core_init(); - - if (core == 0) { - printf("Error instantiating mach core\n"); - return 0; - } - - while (!mach_core_window_should_close(core)) { - if (mach_core_update(core, resize_fn) == MachStatus_Error) { - printf("Error updating Mach\n"); - break; - }; - - elapsed += mach_core_delta_time(core); - if (elapsed > 5.0) { - mach_core_set_should_close(core); - } - - // printf("Elapsed: %f\n", elapsed); - } - - mach_core_deinit(core); - - return 0; -} diff --git a/libmach/test.lisp b/libmach/test.lisp deleted file mode 100644 index b83f8541..00000000 --- a/libmach/test.lisp +++ /dev/null @@ -1,63 +0,0 @@ -;; Tests the behavior of `libmach` using Common Lisp's CFFI -;; This Lisp script is basically a one-to-one translation of `test.c` - -(ql:quickload :cffi) - -(defpackage :cffi-user - (:use :cl :cffi)) - -(in-package :cffi-user) - -(define-foreign-library libmach - (t (:default "./build/libmach"))) - -(use-foreign-library libmach) - -;; Note: CFFI automatically translates C_style names into lispier kebab-case ones - -(defcenum mach-status - (:success 0) - (:error 1)) - -(defcfun "mach_core_init" :pointer) - -(defcfun "mach_core_update" :int - (core :pointer) (resize-fn :pointer)) - -(defcfun "mach_core_deinit" :void - (core :pointer)) - -;; void mach_set_should_close(void*); -(defcfun "mach_core_set_should_close" :void - (core :pointer)) - -;; float mach_delta_time(void*); -(defcfun "mach_core_delta_time" :float - (core :pointer)) - -;; bool mach_window_should_close(void*); -(defcfun "mach_core_window_should_close" :bool - (core :pointer)) - -;; main -(defvar *elapsed* 0.0) - -(defcallback resize-fn :void ((core :pointer) (width :unsigned-int) (height :unsigned-int)) - (format t "Resize Callback: ~S ~S~%" width height)) - -(setf core (mach-core-init)) - -(when (pointer-eq core (null-pointer)) - (format t "Failed to initialize mach core~%") - (sb-ext:exit)) - -(loop while (not (mach-core-window-should-close core)) - do (progn - (when (= (foreign-enum-value 'mach-status :error) - (mach-core-update core (callback resize-fn))) - (format t "Error updating mach~%") - (sb-ext:exit)) - (when (> (incf *elapsed* (mach-core-delta-time core)) 5.0) - (mach-core-set-should-close core)))) - -(sb-ext:exit)