changeset 13: |
1fedeaa5bfc5 |
child: |
2bbf5ce73537 |
author: |
ellis <ellis@rwest.io> |
date: |
Fri, 19 May 2023 22:38:49 -0400 |
permissions: |
-rw-r--r-- |
description: |
tweaks to ffi and makefile |
4 (defvar *cargo-target* #p"/Users/ellis/dev/otom8/demo/target/") 5 (defvar *rs-macros* nil) 7 (defun rs-mod-form (crate &optional mods pub) 8 "Generate a basic mod form (CRATE . [MODS] [PUB])" 11 (defmacro with-rs-env (imports &body body) 12 "Generate an environment for use within a Rust generator macro." 13 `(let ((imports ,(mapcar #'rs-mod-form imports))) 14 (format nil "~A~&~A" imports ',body))) 16 (defun rs-use (crate &optional mods pub) 17 "Generate a single Rust use statement." 25 (lambda (x y) (format nil "~A,~A" x y)) 30 (defun rs-mod (mod &optional pub) 31 "Generate a single Rust mod statement." 37 (defun rs-imports (&rest imports) 38 "Generate a string of Rust 'use' statements." 41 (mapcar (lambda (x) (apply #'rs-use (apply #'rs-mod-form x))) imports)) 44 (defmacro rs-extern-c-fn (name args &optional pub unsafe no-mangle &body body) 45 "Generate a Rust extern 'C' fn." 48 ,(when no-mangle (format nil "#[no_mangle]~&")) 50 ,(when unsafe "unsafe ") 51 "extern \"C\" fn " ,name "(" 53 ((consp args) (reduce (lambda (x y) (format nil "~A,~A" x y)) args)) 57 (defun rs-obj-impl (obj) 58 "Implement Objective for give OBJ." 59 (format nil "impl Objective for ~A {};" obj)) 61 ;; (defun rs-macroexpand-1 (form &optional env)) 63 ;; (defun rs-macroexpand (env &rest body) 64 ;; "Cbindgen is quite the menace and really doesn't like our macros used 65 ;; to generate C FFI bindings. To compensate for this, we use a tool 66 ;; called cargo-expand by the most excellent dtolnay which expands Rust 67 ;; macros. The expansions are assembled into an equivalent Rust source 68 ;; file which cbindgen won't get stuck in an infinite compile loop on.")