taoensso / encore

Core utils library for Clojure/Script
https://www.taoensso.com/encore
Eclipse Public License 1.0
272 stars 50 forks source link

Cannot use from babashka #75

Closed michaelwhitford closed 1 month ago

michaelwhitford commented 2 months ago

When I try to use catching from babashka I am seeing this error:

clojure.lang.ExceptionInfo: Could not resolve symbol: taoensso.encore/catching

Should this library work from babashka? I hope this can work I want to use encore from babashka for many more things.

michaelwhitford commented 2 months ago

I tried the exact same command from clojure and it's working.

ptaoussanis commented 2 months ago

@michaelwhitford Hi Michael,

It should work fine, and there's no obvious reason you'd see that error.

Can you please share more info? What command are you running? What version of Encore are you using? Have you tried running lein clean or equivalent, to ensure you don't have any stale build artifacts?

michaelwhitford commented 2 months ago

Sorry for the sketchy details. I have a new error now, and it's right when I try to require just encore. I'm thinking I was not seeing an error when it tried to load from the namespace require, and it was failing to load the library. When I then tried to use it I saw the error resolving the symbol. When I open a babashka repl with only encore and timbre in the bb.edn deps I see this error when I do the require:

Babashka v1.3.190 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[taoensso.encore :as enc])
java.lang.Exception: Unable to resolve classname: java.util.function.UnaryOperator [at taoensso/encore.cljc:104:3]

My bb.edn file:

{:paths ["src"]
 :deps  {com.taoensso/timbre {:mvn/version "6.5.0"}
         com.taoensso/encore {:mvn/version "3.106.0"}}
ptaoussanis commented 2 months ago

What version of Java are you using? java.util.function.UnaryOperator was added in Java 8, I believe.

michaelwhitford commented 2 months ago

It's babashka, which I think currently is using Java 21. babashka does not include all the classes from java to keep the binary size smaller. I guess encore is not going to work unless babashka adds that java class to it's build.

ptaoussanis commented 2 months ago

babashka does not include all the classes from java to keep the binary size smaller. I guess encore is not going to work unless babashka adds that java class to it's build.

Interesting- I didn't realise that. I'm not too familiar with babashka, my only experience with it is for the basic Graal test run by Encore, etc.

Could you maybe provide a simple reproducible example I can experiment with, to see if I can get Encore building correctly?

michaelwhitford commented 2 months ago

Sure, I created a small repository on gitlab that shows the issue and does not include anything outside of what I am trying to do with encore. It's a contrived example, but is one of the usages I was hoping to have.

https://gitlab.com/michaelwhitford/encore-babashka.git

ptaoussanis commented 2 months ago

Thanks for that! 🙏 Looked into it a little, and it seems there's more than just the one (UnaryOperator) class missing from babashka.

I also hadn't understood before that babashka actually implements only a subset of Clojure.

Encore currently uses a fair number of dark corners of Clojure where it benefits performance, and trying to keep all that in sync with the babashka subset seems like it may be a challenge.

What exactly in Encore are you interested in using in babashka? I suspect that just extracting what you need might be easiest.

No one's asked about this before, but if there's a common desire to support at least some subset of Encore in babashka - I could try schedule some time to look into it further to see what options might exist.

michaelwhitford commented 1 month ago

This all started because I use the excellent statecharts library from fulcro. For the event loop in that library it uses taoensso.encore/catching. I initially did try to extract just catching into a local namespace, but I am still a beginner at clojure and could not get it working. The statecharts library only uses catching on 1 line so I hoped the override would be simple, but every new macro/function I added, gave more errors that I did not understand...

ptaoussanis commented 1 month ago

Okay, gotcha- let me see if I can help.

To clarify - your goal is that you'd like to use this linked statecharts library with bb, but it won't work because it depends on Encore?

Or your goal is to have your own version of catching since you'd like to use it yourself? If this one, could you describe your motivation? I can give you a minimal self-contained version if I know what you intend to use it for.

(The current version of Encore's catching is based on try*, though I suspect you won't need/want all that).

michaelwhitford commented 1 month ago

I'd like to use statecharts with bb. I think I could use catching in the future, but really for right now getting statecharts to work under bb is the main goal. My cli app works great under clojure, and I want to eliminate the slow start of the jvm. Without statecharts the rest of my app works fine under bb.

ptaoussanis commented 1 month ago

getting statecharts to work under bb is the main goal

Gotcha. I can't much help with that unfortunately, sorry!

My cli app works great under clojure, and I want to eliminate the slow start of the jvm.

Just checking if you've tried AOT? That can dramatically speed up start time. GraalVM might be another option, though I've not much experience with it myself.

Encore (and my other libs) are tested to work under Graal, and I expect Graal would be an easier compatibility target for statecharts too.

Maybe that avenue could be of some use?

Good luck!

michaelwhitford commented 1 month ago

Thank you for looking at the issue, and the advice on Graalvm. I'll keep poking at it.