Fork me on GitHub
#babashka
<
2024-03-26
>
Michael W00:03:37

I am trying to use a statechart library to manage state in my babashka script, but am having a problem bringing up the event loop:

Type:     java.lang.Exception
Message:  Unable to resolve classname: java.util.concurrent.CountDownLatch
Location: taoensso/encore.cljc:87:3

Michael W00:03:32

Is this expected? That java class is not included into bb?

Bob B00:03:46

The short answer is yes. Every java class that gets included takes some space in the executable (for graalvm reasons). I think borkdude typically recommends something along the lines of "if there's a compelling use case, create an issue on the bb repo to see if it should be added, how much size it adds to the executable, etc"

Bob B00:03:00

I think there actually was a similar ask about the same class maybe a week ago

Bob B00:03:41

based on https://clojurians.slack.com/archives/CLX41ASCS/p1710278088582459, it looks like it might be a recent addition... you could check if your bb is up to date, or it might be that a new version just hasn't been released since that change was made - you could maybe try with a master build (if you wanna get a little experimental)

Bob B00:03:20

the commit that added the class in question looks like it's from 3/13, and the latest release on github is from the end of February

Michael W00:03:07

Yeah, it'll be in the next version I guess, just tried to brew upgrade but my bb is already newest. Thanks.

Bob B00:03:21

if you want to give it a shot (to see if there are any other classes that might be needed or whatever), #CSDUA8S6B has links to CI builds for some of the linux and macos architectures

Michael W01:03:44

Mmmm the links in there for the linux static binary do not download anything, just a server not found page. I guess I'll have to wait till the next release. Thanks for the pointer though I would not have liked to scrap the whole idea for my app state.

Bob B01:03:53

Interesting... maybe those links go stale since they're a few days old now. Depending on how bad you want it, you could probably go to circleci using the badge in the github readme and find a build and maybe get an artifact from there (if you want to do a little exploring)

borkdude06:03:03

Try this:

bash <(curl ) --dev-build --dir /tmp

borkdude06:03:09

this installs the master versoin in /tmp

Michael W16:03:26

Thanks @U04V15CAJ that let me get the latest build of bb installed. Unfortunately the statecharts library still doesn't work. It works great in clojure, but in bb it gets weird errors on missing symbol:

clojure.lang.ExceptionInfo: Could not resolve symbol: taoensso.encore/catching
I have the dependency for that in bb.edn though:
com.taoensso/encore                           {:mvn/version "3.98.0-RC7"}

borkdude16:03:20

taoensso.encore isn't a great library to run in bb since it contains all kinds of unidiomatic hacks :)

Michael W16:03:20

Yeah I am seeing that in the source now that I Iook, the statecharts library is damn good but he uses encore from many of his libraries.

borkdude16:03:11

what does statecharts do?

borkdude16:03:19

I have no clue when reading the readme

Michael W16:03:22

It is a series of state machines, it lets me handle the entire flow of my app and the state in a very systematic way.

Michael W16:03:51

Basically it's an iteration on statemachines that gives more flexibility and a "pretty" way to define them.

Michael W16:03:45

I have it all working on clojure and was hoping to move it to bb for the startup speed since it's a cli app. It was I think very close to working, but for the decision to use timbre and encore for that statecharts lib.

borkdude16:03:39

perhaps there's a hack that we can apply

Michael W16:03:31

I would love to move to bb for this to distribute for more operating systems and also that startup speed boost.

borkdude16:03:44

perhaps make a fork of this statecharts library and try to get rid of this catching macro

borkdude16:03:50

and then see if it works

borkdude16:03:24

or put a file on your classpath like so:

taoensso/encore.cljc
with the macros inside

borkdude16:03:40

only that catching macro and the try* macro which it depends on

Michael W16:03:38

It's used from the log namespace too, which is taoensso.timbre

Michael W16:03:22

That is the actual line that bb complains about a missing symbol.

Michael W16:03:23

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: taoensso.encore/catching
Data:     {:type :sci/error, :line 178, :column 1, :file "com/fulcrologic/statecharts/chart.cljc", :phase "analysis"}
Location: com/fulcrologic/statecharts/chart.cljc:184:3
Phase:    analysis

borkdude16:03:16

spy is there:

$ bb -e "(requiring-resolve 'taoensso.timbre/spy)"
#'taoensso.timbre/spy

borkdude16:03:40

try my suggestion and then report the next issue please

Michael W16:03:24

I will play with it thanks for your time looking at it.