Taking a small risk.. this project is not at all close to baked, but just in case anybody might find it useful in my super niche case (building native-image binaries in Clojure depending on libsodium): https://codeberg.org/coreagile/javasodium -- I've completely integrated it into a little Clojure multi user dungeon I'm building with a few friends...
Nice, we also did some libsodium FFI over here: https://github.com/babashka/babashka-workshop-spectre/blob/main/src/spectre/scrypt_ffi.clj Any reason you went with JNI?
The Java ffi libraries for libsodium didn't work with native-image and I was impatient 🤣
Everybody that I could find who talked about making ffi stuff work with native-image talked about how hard it was
Very open to things that are easier if you have ideas!
I’ll have to read what you did.. it looks deceptively simple so I don't know where those people got their ideas from
@stephen676 The babashka.ffi library also works on the JVM and with native-image
I'll check it out! Thanks!
Does it have a way to include the native libraries directly into your final binary? That was the weirdest thing to build lol
no. the way you can do that in native image if I recall correctly is using the GraalVM C API
but what you can do is this pattern: 1. you include your native lib as a resource in your native image 2. you spit it out to a cache dir on start-up once 3. you load this specific library for your FFI bindings. babashka.ffi supports targeting a specific lib
Ok thanks for the info!
I use that pattern in babashka.esbuild if you want an example
Thanks! I'll check it out!
> Does it have a way to include the native libraries directly into your final binary? That was the weirdest thing to build lol If you build a libsodium.a archive, you should be able to statically link it so that it is included in the final executable (and won't require extracting and loading).
Is that something you can tell native-image to do?
yea
there's a flag. let me see if I can find an example
I've done this with libffi in babashka. mac:
-H:NativeLinkerOption=-Wl,-force_load,$libffi_archive
linux:
-H:NativeLinkerOption=-Wl,--whole-archive,$libffi_archive,--no-whole-archive
Windows:
"-H:NativeLinkerOption=/WHOLEARCHIVE:%LIBFFI_LIB%"
And you need @CFunction symbol bindings (using the native image C API):
https://github.com/babashka/ffi/blob/main/src-java/babashka/ffi/impl/Libffi.javaThose flags look right. If you use dtype-next for ffi, then it can generate the bytecode and @CFunction annotations for you from clojure code, but writing a bit of java isn't too bad either.
I guess static linking makes sense if you want to avoid writing a file on startup (which can be cached) for a dedicated CLI but not for a platform like babashka, or Node.js or whatever, which should be able to load any lib dynamically
yea, if want to deploy a standalone executable where you know which libraries you need at compile time.
and you don't want people to use a different one at runtime (which could be inflexible)
It probably would be too hard to extend babashka.ffi to support this (it may already work since native image now supports ffm).
yeah perhaps... hmm
I'd definitely be open for a PR ;)
Y'all too smart for me.. but you're right.. I want someone to be able to download a self-contained executable and run it. Not too concerned about it writing a temp file at startup (which is what my little JNI lib does) but I'll take even more optimization if I can get it!
statechart-viz: draws any Fulcro statechart as a Graphviz diagram, with the active states highlighted. It runs on the JVM, in babashka, and in the browser via SCI.
Playground: https://sheluchin.github.io/statechart-viz/
Paste a chart, click its events, and watch it run. Share gives you a link to your chart, or point #src= at a raw gist. Everything runs in the browser with no server.
Repo: https://github.com/sheluchin/statechart-viz
Disclaimer: I used an LLM to create this.
(Sorry for LinkedIn like tone, I am crossposting here) Hi all, I implemented a Theorem Prover focused on Operations Research called Rainbow. Main things you should know: 1. It is in Clojure 2. it has two parts, one part is proving maths and the second is generating code, that is proved correct, and runs fast 3. It already has over 1000 main theories in Operations Research proven 4. It already has also over 1000 implemented functions, that are proven correct 5. Theorem proving part is free, and open source with Apache license. Code generation part is going with Pro license. What am I targeting is to offer implementations that can offer guarantees like: 🍀 The algorithm offers solutions {0.00001%} close to optimum. It is mathematically guaranteed, it is not possible to find a better solution. 🍀 This algorithm is able to handle ANY case that can possible happen. Yes, even events that happen once in the existence of universe. 🍀 This algorithm is always going to keep in these boundaries, no matter what. No, this device will never kill its users unexpectedly, you can trust us with your airplane, or pacemaker. And it will run fast. And it has access to the rest of Clojure ecosystem (that means whole JVM ecosystem). We are already proposing using this system to 3 vendors. A synthetic jet fuel power plant, where we found a way to make a ton of fuel 5463 €/ton instead of projected 6583 €/ton. We not only optimized the proposal, but can guarantee that there is no better option than ours. This can save tens of millions of euro per plant and make renewable flying cheaper for everyone. Hydrogen stations network for trucks near ports positioning based on workload. We have shown locations and capacities that are optimal and cannot be improved. And a system for wind turbines, that can prevent 62% of large birds being killed at record low 6045 €/year cost. All other solutions are 1.6 to 89 times worse financially (for instance, seasonal shutdowns can go well over 100,000 €). This way, we could save dozens of vultures, and other big birds just in Andalusia alone every year. You can check and download Rainbow here https://github.com/Flexiana/rainbow
Announcing https://github.com/grid-coordination/clj-urpx
A Clojure library for https://urpx.org (Utility Rate Plan Exchange) — parse, validate, and resolve prices from URPX rate plan documents (JSON-LD).
What is URPX?
URPX is an https://lfenergy.org/ open standard for exchanging utility rate plan information using semantic web technologies (RDF, OWL, SHACL, JSON-LD).
It enables precise, machine-readable data exchange between utilities, regulators, vendors, and researchers.
The standard's source of truth — ontology, SHACL shapes, JSON-LD context, tutorial, and reference test cases — lives at http://github.com/urpx-org/urpx;
What does this library do?
• Parse URPX JSON-LD rate plan documents into Clojure data structures
• Validate & coerce parsed data against https://github.com/metosin/malli schemas — string leaves become BigDecimal, LocalDate, LocalTime, LocalDateTime, ZonedDateTime, OffsetTime, Duration, Period, integer month numbers
• Resolve the per-ledger, per-tier prices that apply at a given instant in a given timezone — TOU period, season, day-of-week, midnight-wrapping brackets, block-tier ladders
• Generate contiguous price-interval schedules suitable for https://www.openadr.org/ events, either sampled on a grid or as exact segments whose boundaries come from the tariff
• Emit URPX JSON-LD from coerced Clojure entities (the inverse of parse + coerce) — useful for round-trip validation and programmatic authoring of URPX documents
• Author URPX entities idiomatically in Clojure via urpx.dsl — per-entity builders with auto-coercion, validation-on-construct, and keyword refs scoped via dsl-scope