https://github.com/phronmophobic/clj-libffi
https://github.com/phronmophobic/clj-libffi
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/phronmophobic/clj-libffi
- Owner: phronmophobic
- License: epl-1.0
- Created: 2021-09-13T00:00:57.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-08T23:00:03.000Z (over 1 year ago)
- Last Synced: 2025-02-27T05:02:41.406Z (over 1 year ago)
- Language: Clojure
- Size: 60.5 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# clj-libffi
A wrapper for libffi.
## Rationale
On the jvm, using clj-libffi is worse than other similar options like jna and jdk16's ffi. However, when compiling to native using graalvm, only static calls to c libraries are possible (afaik). Using libffi, loading and calling arbitrary functions from arbitrary shared libraries can be achieved.
## Deps
Leiningen/Boot
`[com.phronemophobic/clj-lbbffi "1.5"]`
Clojure CLI/deps.edn
`com.phronemophobic/clj-libffi {:mvn/version "1.5"}`
## Usage
```clojure
(require '[com.phronemophobic.clj-libffi :as ffi])
(ffi/call "cos" :float64 :float64 Math/PI)
;; -1.0
(ffi/load-library "libmy.dylib")
(ffi/call "myfn" :void
:int64 42
:int8 -1)
```
### Graalvm
To compile for graalvm, you must link against libffi. See [examples/ffitest/scripts/compile-test.sh](examples/ffitest/scripts/compile-test.sh).
### Limitations
* Currently only runs on Mac OSX. If you'd like to see support for other platforms, please comment or upvote the issues for [linux](https://github.com/phronmophobic/clj-libffi/issues/1) and [windows](https://github.com/phronmophobic/clj-libffi/issues/2).
## License
Copyright © 2021 Adrian Smith
Distributed under the Eclipse Public License version 1.0.