1.1--- a/build.rs Mon May 15 21:40:24 2023 -0400
1.2+++ b/build.rs Fri May 19 22:38:49 2023 -0400
1.3@@ -13,4 +13,5 @@
1.4 cbindgen::generate(crate_dir)
1.5 .expect("Unable to find cbindgen.toml configuration file")
1.6 .write_to_file(build_dir.join("demo.h"));
1.7+
1.8 }
2.1--- a/demo.asd Mon May 15 21:40:24 2023 -0400
2.2+++ b/demo.asd Fri May 19 22:38:49 2023 -0400
2.3@@ -11,7 +11,6 @@
2.4 #+(or ccl sbcl)
2.5 :clack
2.6 :clog
2.7- :clog-web
2.8 :cl-rocksdb
2.9 :verbose
2.10 :alexandria
3.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2+++ b/demo.ros Fri May 19 22:38:49 2023 -0400
3.3@@ -0,0 +1,12 @@
3.4+#!/bin/sh
3.5+#|-*- mode:lisp -*-|#
3.6+#|
3.7+exec ros -Q -- $0 "$@"
3.8+|#
3.9+(progn ;;init forms
3.10+ (ros:ensure-asdf)
3.11+ #+quicklisp(ql:quickload '(demo) :silent t))
3.12+
3.13+(defun main (&rest argv)
3.14+ (declare (ignorable argv))
3.15+ (demo:main))
4.1--- a/ffi.lisp Mon May 15 21:40:24 2023 -0400
4.2+++ b/ffi.lisp Fri May 19 22:38:49 2023 -0400
4.3@@ -1,11 +1,28 @@
4.4 (in-package :demo)
4.5+(defparameter quiche-lib-path #p"./ffi/libquiche.dylib")
4.6+(defparameter rocksdb-lib-path #p"./ffi/librocksdb.dylib")
4.7+(defparameter demo-lib-path (find-rs-cdylib "libdemo.dylib"))
4.8+(defmacro find-rs-cdylib (name &optional debug)
4.9+ "Find the rust dll specified by NAME."
4.10+ (cond
4.11+ ((uiop:directory-exists-p (merge-pathnames *cargo-target* "release"))
4.12+ `,(mkstr "./target/release/" name))
4.13+ ((uiop:directory-exists-p (merge-pathnames *cargo-target* "debug"))
4.14+ `,(mkstr "./target/debug/" name))
4.15+ (t `(progn
4.16+ ,(uiop:run-program '("cargo" "build" (unless debug "--release")) :output t)
4.17+ (find-rs-cdylib ,name ,debug)))))
4.18
4.19 (define-foreign-library demo
4.20 (:win32 (:default "demo"))
4.21 (t (:default "libdemo")))
4.22+(define-foreign-library quiche
4.23+ (:win32 (:default "quiche"))
4.24+ (t (:default "libquiche")))
4.25+(define-foreign-library rocksdb
4.26+ (:win32 (:default "rocksdb"))
4.27+ (t (:default "librocksdb")))
4.28
4.29-(defun install-demo-lib (&optional path)
4.30- (if path
4.31- (use-foreign-library path)
4.32- (let ((path (rs-find-dll "libdemo.dylib")))
4.33- (use-foreign-library path))))
4.34+(defun load-libdemo () (load-foreign-library (find-rs-cdylib "libdemo.dylib")))
4.35+(defun install-quiche-lib (&optional path) (load-foreign-library (or path quiche-lib-path)))
4.36+(defun install-rocksdb-lib (&optional path) (load-foreign-library (or path rocksdb-lib-path)))
5.1--- a/ffi/demo.h Mon May 15 21:40:24 2023 -0400
5.2+++ b/ffi/demo.h Fri May 19 22:38:49 2023 -0400
5.3@@ -10,6 +10,12 @@
5.4 #include <stdint.h>
5.5 #include <stdlib.h>
5.6
5.7+#define KEY_LEN 32
5.8+
5.9+#define OUT_LEN 32
5.10+
5.11+#define OUT_LEN_HEX (OUT_LEN * 2)
5.12+
5.13 typedef struct CustomService CustomService;
5.14
5.15 /**
6.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2+++ b/install.lisp Fri May 19 22:38:49 2023 -0400
6.3@@ -0,0 +1,5 @@
6.4+(asdf:load-asd "demo.asd")
6.5+(ql:quickload :demo)
6.6+;; (asdf:make :demo)
6.7+(save-lisp-and-die "demo")
6.8+(quit)
7.1--- a/makefile Mon May 15 21:40:24 2023 -0400
7.2+++ b/makefile Fri May 19 22:38:49 2023 -0400
7.3@@ -1,12 +1,16 @@
7.4+M ?= release
7.5 L ?= sbcl
7.6-O ?= /tmp/demo
7.7+P ?= python3
7.8+
7.9+RS:Cargo.toml build.rs lib.rs obj fig
7.10+CL:*.asd *.lisp
7.11 .PHONY:build
7.12-$(O):;mkdir -p $@
7.13-clean:;rm -rf *.fasl;scriipts/clean.ros
7.14-fmt:;scripts/fmt.ros
7.15-build:;scripts/build.ros
7.16-docs:;scripts/docs.ros
7.17-test:;scripts/test.ros
7.18-pack:;scripts/pack.ros
7.19-check:;scripts/check.ros
7.20-ci:clean fmt build docs test pack;
7.21+clean:;rm -rf *.fasl;cargo clean
7.22+fmt:;cargo fmt
7.23+build:$(RS) $(CL);cargo build --$(M);$L install.lisp
7.24+ffi:build;cp target/$(M)/libdemo.dylib ffi;cd ffi;$(P) ffi/build.py
7.25+docs:$(RS);cargo doc
7.26+test:$(RS);cargo test
7.27+#pack:;scripts/pack.ros
7.28+#check:;scripts/check.ros
7.29+ci:clean fmt build ffi docs test;
8.1--- a/pkg.lisp Mon May 15 21:40:24 2023 -0400
8.2+++ b/pkg.lisp Fri May 19 22:38:49 2023 -0400
8.3@@ -10,57 +10,68 @@
8.4 (#:bt #:bordeaux-threads)
8.5 (#:cli #:clingon))
8.6 ;; db.lisp
8.7- (:export #:create-options
8.8- #:destroy-options
8.9- #:increase-parallelism
8.10- #:optimize-level-style-compaction
8.11- #:set-create-if-missing
8.12- #:create-writeoptions
8.13- #:destroy-writeoptions
8.14- #:create-readoptions
8.15- #:destroy-readoptions
8.16- #:open-db
8.17- #:close-db
8.18- #:cancel-all-background-work
8.19- #:put-kv
8.20- #:put-kv-str
8.21- #:get-kv
8.22- #:get-kv-str
8.23- #:create-iter
8.24- #:destroy-iter
8.25- #:move-iter-to-first
8.26- #:move-iter-forward
8.27- #:move-iter-backword
8.28- #:valid-iter-p
8.29- #:iter-key
8.30- #:iter-key-str
8.31- #:iter-value
8.32- #:iter-value-str
8.33- #:with-open-db
8.34- #:with-iter)
8.35+ (:export
8.36+ #:create-options
8.37+ #:destroy-options
8.38+ #:increase-parallelism
8.39+ #:optimize-level-style-compaction
8.40+ #:set-create-if-missing
8.41+ #:create-writeoptions
8.42+ #:destroy-writeoptions
8.43+ #:create-readoptions
8.44+ #:destroy-readoptions
8.45+ #:open-db
8.46+ #:close-db
8.47+ #:cancel-all-background-work
8.48+ #:put-kv
8.49+ #:put-kv-str
8.50+ #:get-kv
8.51+ #:get-kv-str
8.52+ #:create-iter
8.53+ #:destroy-iter
8.54+ #:move-iter-to-first
8.55+ #:move-iter-forward
8.56+ #:move-iter-backword
8.57+ #:valid-iter-p
8.58+ #:iter-key
8.59+ #:iter-key-str
8.60+ #:iter-value
8.61+ #:iter-value-str
8.62+ #:with-open-db
8.63+ #:with-iter)
8.64 ;; demo.lisp
8.65- (:export #:main
8.66- #:demo-path
8.67- #:db-path
8.68- #:cli-opts
8.69- #:cli-handler
8.70- #:cli-cmd)
8.71+ (:export
8.72+ #:main
8.73+ #:demo-path
8.74+ #:db-path
8.75+ #:cli-opts
8.76+ #:cli-handler
8.77+ #:cli-cmd)
8.78 ;; ui.lisp
8.79- (:export #:on-new-window
8.80- #:start-ui)
8.81+ (:export
8.82+ #:on-new-window
8.83+ #:start-ui)
8.84 ;; tk.lisp
8.85 (:export
8.86- #:*cargo-target*
8.87- #:*rs-macros*
8.88+ #:source-dir
8.89 #:random-id
8.90 #:scan-dir
8.91 #:mkstr
8.92 #:symb
8.93- #:sbq-reader
8.94- #:rs-find-dll
8.95+ #:sbq-reader)
8.96+ ;; rs.lisp
8.97+ (:export
8.98+ #:*cargo-target*
8.99+ #:*rs-macros*
8.100 #:rs-defmacro
8.101 #:rs-macroexpand-1
8.102 #:rs-macroexpand)
8.103 ;; ffi.lisp
8.104- ;; (:export)
8.105- )
8.106+ (:export
8.107+ #:quiche-lib-path
8.108+ #:rocksdb-lib-path
8.109+ #:demo-lib-path
8.110+ #:find-rs-cdylib
8.111+ #:install-demo-lib
8.112+ #:install-quiche-lib
8.113+ #:install-rocksdb-lib))
9.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2+++ b/rs.lisp Fri May 19 22:38:49 2023 -0400
9.3@@ -0,0 +1,70 @@
9.4+;;; RUST DSL
9.5+(in-package :demo)
9.6+
9.7+(defvar *cargo-target* #p"/Users/ellis/dev/otom8/demo/target/")
9.8+(defvar *rs-macros* nil)
9.9+
9.10+(defun rs-mod-form (crate &optional mods pub)
9.11+ "Generate a basic mod form (CRATE . [MODS] [PUB])"
9.12+ `(,crate ,mods ,pub))
9.13+
9.14+(defmacro with-rs-env (imports &body body)
9.15+ "Generate an environment for use within a Rust generator macro."
9.16+ `(let ((imports ,(mapcar #'rs-mod-form imports)))
9.17+ (format nil "~A~&~A" imports ',body)))
9.18+
9.19+(defun rs-use (crate &optional mods pub)
9.20+ "Generate a single Rust use statement."
9.21+ (concatenate
9.22+ 'string
9.23+ (if pub "pub " "")
9.24+ "use " crate "::{"
9.25+ (cond
9.26+ ((consp mods)
9.27+ (reduce
9.28+ (lambda (x y) (format nil "~A,~A" x y))
9.29+ mods))
9.30+ (t mods))
9.31+ "};"))
9.32+
9.33+(defun rs-mod (mod &optional pub)
9.34+ "Generate a single Rust mod statement."
9.35+ (concatenate
9.36+ 'string
9.37+ (if pub "pub " "")
9.38+ "mod " mod ";"))
9.39+
9.40+(defun rs-imports (&rest imports)
9.41+ "Generate a string of Rust 'use' statements."
9.42+ (cond
9.43+ ((consp imports)
9.44+ (mapcar (lambda (x) (apply #'rs-use (apply #'rs-mod-form x))) imports))
9.45+ (t imports)))
9.46+
9.47+(defmacro rs-extern-c-fn (name args &optional pub unsafe no-mangle &body body)
9.48+ "Generate a Rust extern 'C' fn."
9.49+ `(concatenate
9.50+ 'string
9.51+ ,(when no-mangle (format nil "#[no_mangle]~&"))
9.52+ ,(when pub "pub ")
9.53+ ,(when unsafe "unsafe ")
9.54+ "extern \"C\" fn " ,name "("
9.55+ ,(cond
9.56+ ((consp args) (reduce (lambda (x y) (format nil "~A,~A" x y)) args))
9.57+ (t args))
9.58+ ")" "{" ,@body "}"))
9.59+
9.60+(defun rs-obj-impl (obj)
9.61+ "Implement Objective for give OBJ."
9.62+ (format nil "impl Objective for ~A {};" obj))
9.63+
9.64+;; (defun rs-macroexpand-1 (form &optional env))
9.65+
9.66+;; (defun rs-macroexpand (env &rest body)
9.67+;; "Cbindgen is quite the menace and really doesn't like our macros used
9.68+;; to generate C FFI bindings. To compensate for this, we use a tool
9.69+;; called cargo-expand by the most excellent dtolnay which expands Rust
9.70+;; macros. The expansions are assembled into an equivalent Rust source
9.71+;; file which cbindgen won't get stuck in an infinite compile loop on.")
9.72+
9.73+;;;
10.1--- a/scripts/build.ros Mon May 15 21:40:24 2023 -0400
10.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3@@ -1,23 +0,0 @@
10.4-#!/bin/sh
10.5-#|-*- mode:lisp -*-|#
10.6-#|
10.7-exec ros -Q -- $0 "$@"
10.8-|#
10.9-(progn ;;init forms
10.10- (ros:ensure-asdf)
10.11- #+quicklisp(ql:quickload '() :silent t)
10.12- )
10.13-
10.14-(defpackage :ros.script.build.3891893519
10.15- (:use :cl))
10.16-(in-package :ros.script.build.3891893519)
10.17-
10.18-(defun main (&rest argv)
10.19- (declare (ignorable argv))
10.20- (write-line "> cargo build --release")
10.21- (uiop:run-program "cargo build --release")
10.22- (wrie-line " built rust libs and bindings")
10.23- (asdf:load-asd "cl-demo.asd")
10.24- (asdf:load-system "demo")
10.25- (asdf:make :demo))
10.26-;;; vim: set ft=lisp lisp:
11.1--- a/scripts/clean.ros Mon May 15 21:40:24 2023 -0400
11.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3@@ -1,23 +0,0 @@
11.4-#!/bin/sh
11.5-#|-*- mode:lisp -*-|#
11.6-#|
11.7-exec ros -Q -- $0 "$@" ;
11.8-|#
11.9-
11.10-;; clean:;rm -rf out *.fasl;pushd rust;cargo clean;popd
11.11-
11.12-(progn ;;init forms
11.13- (ros:ensure-asdf)
11.14- #+quicklisp(ql:quickload '() :silent t)
11.15- )
11.16-
11.17-(defpackage :ros.script.clean.3891893753
11.18- (:use :cl))
11.19-(in-package :ros.script.clean.3891893753)
11.20-
11.21-(defun main (&rest argv)
11.22- (declare (ignorable argv))
11.23- (write-line "> cargo clean")
11.24- (uiop:run-program "cargo clean")
11.25- (write-line " cleaned rust crates"))
11.26-;;; vim: set ft=lisp lisp:
12.1--- a/scripts/docs.ros Mon May 15 21:40:24 2023 -0400
12.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
12.3@@ -1,14 +0,0 @@
12.4-#!/bin/sh
12.5-#|-*- mode:lisp -*-|#
12.6-#|
12.7-exec ros -Q -- $0 "$@"
12.8-|#
12.9-(progn ;;init forms
12.10- (ros:ensure-asdf)
12.11- #+quicklisp(ql:quickload '() :silent t))
12.12-
12.13-(defun main (&rest argv)
12.14- (declare (ignorable argv))
12.15- (write-line "> cargo doc")
12.16- (uiop:run-program "cargo doc")
12.17- (write-line " generated rust documentation"))
13.1--- a/scripts/fmt.ros Mon May 15 21:40:24 2023 -0400
13.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3@@ -1,20 +0,0 @@
13.4-#!/bin/sh
13.5-#|-*- mode:lisp -*-|#
13.6-#|
13.7-exec ros -Q -- $0 "$@"
13.8-|#
13.9-(progn ;;init forms
13.10- (ros:ensure-asdf)
13.11- #+quicklisp(ql:quickload '() :silent t)
13.12- )
13.13-
13.14-(defpackage :ros.script.build.3891893519
13.15- (:use :cl))
13.16-(in-package :ros.script.build.3891893519)
13.17-
13.18-(defun main (&rest argv)
13.19- (declare (ignorable argv))
13.20- (write-line "> cargo fmt")
13.21- (uiop:run-program "cargo fmt")
13.22- (write-line " formatted rust code"))
13.23-;;; vim: set ft=lisp lisp:
14.1--- a/tk.lisp Mon May 15 21:40:24 2023 -0400
14.2+++ b/tk.lisp Fri May 19 22:38:49 2023 -0400
14.3@@ -1,9 +1,5 @@
14.4 (in-package :demo)
14.5
14.6-(defvar *cargo-target* #p"/Users/ellis/dev/otom8/demo/target/")
14.7-
14.8-(defvar *rs-macros* nil)
14.9-
14.10 (defun mkstr (&rest args)
14.11 (with-output-to-string (s)
14.12 (dolist (a args) (princ a s))))
14.13@@ -30,80 +26,3 @@
14.14 (eval-when (:execute)
14.15 (set-dispatch-macro-character
14.16 #\# #\` #'demo:sbq-reader))
14.17-
14.18-;;; RUST MACROS
14.19-(defmacro rs-find-dll (name &optional debug)
14.20- "Find the rust dll specified by NAME."
14.21- (cond
14.22- ((uiop:directory-exists-p (merge-pathnames *cargo-target* "release"))
14.23- `,(mkstr "./target/release/" name))
14.24- ((uiop:directory-exists-p (merge-pathnames *cargo-target* "debug"))
14.25- `,(mkstr "./target/debug/" name))
14.26- (t `(progn
14.27- ,(uiop:run-program '("cargo" "build" (unless debug "--release")) :output t)
14.28- (rs-find-dll ,name ,debug)))))
14.29-
14.30-(defun rs-mod-form (crate &optional mods pub)
14.31- "Generate a basic mod form (CRATE . [MODS] [PUB])"
14.32- `(,crate ,mods ,pub))
14.33-
14.34-(defmacro with-rs-env (imports &body body)
14.35- "Generate an environment for use within a Rust generator macro."
14.36- `(let ((imports ,(mapcar #'rs-mod-form imports)))
14.37- (format nil "~A~&~A" imports ',body)))
14.38-
14.39-(defun rs-use (crate &optional mods pub)
14.40- "Generate a single Rust use statement."
14.41- (concatenate
14.42- 'string
14.43- (if pub "pub " "")
14.44- "use " crate "::{"
14.45- (cond
14.46- ((consp mods)
14.47- (reduce
14.48- (lambda (x y) (format nil "~A,~A" x y))
14.49- mods))
14.50- (t mods))
14.51- "};"))
14.52-
14.53-(defun rs-mod (mod &optional pub)
14.54- "Generate a single Rust mod statement."
14.55- (concatenate
14.56- 'string
14.57- (if pub "pub " "")
14.58- "mod " mod ";"))
14.59-
14.60-(defun rs-imports (&rest imports)
14.61- "Generate a string of Rust 'use' statements."
14.62- (cond
14.63- ((consp imports)
14.64- (mapcar (lambda (x) (apply #'rs-use (apply #'rs-mod-form x))) imports))
14.65- (t imports)))
14.66-
14.67-(defmacro rs-extern-c-fn (name args &optional pub unsafe no-mangle &body body)
14.68- "Generate a Rust extern 'C' fn."
14.69- `(concatenate
14.70- 'string
14.71- ,(when no-mangle (format nil "#[no_mangle]~&"))
14.72- ,(when pub "pub ")
14.73- ,(when unsafe "unsafe ")
14.74- "extern \"C\" fn " ,name "("
14.75- ,(cond
14.76- ((consp args) (reduce (lambda (x y) (format nil "~A,~A" x y)) args))
14.77- (t args))
14.78- ")" "{" ,@body "}"))
14.79-
14.80-(defun rs-obj-impl (obj)
14.81- "Implement Objective for give OBJ."
14.82- (format nil "impl Objective for ~A {};" obj))
14.83-
14.84-;; (defun rs-macroexpand-1 (form &optional env))
14.85-
14.86-;; (defun rs-macroexpand (env &rest body)
14.87-;; "Cbindgen is quite the menace and really doesn't like our macros used
14.88-;; to generate C FFI bindings. To compensate for this, we use a tool
14.89-;; called cargo-expand by the most excellent dtolnay which expands Rust
14.90-;; macros. The expansions are assembled into an equivalent Rust source
14.91-;; file which cbindgen won't get stuck in an infinite compile loop on.")
14.92-
14.93-;;;