Fork me on GitHub
#babashka
<
2023-10-11
>
borkdude11:10:04

Anyone wants to try the new self-contained binary uberjar approach? https://github.com/babashka/babashka/wiki/Self-contained-executable#uberjar

๐Ÿ‘€ 4
yeshugs 1
clojure-spin 1
borkdude11:10:08

๐Ÿงต

elken11:10:07

I have a good usecase for this, will investigate this afternoon and report back ๐Ÿ™‚

John12:10:25

i didnt try it but this confused me

cat ./bb uber.jar > my-binary

John12:10:59

wait does it mean, one would first use uberjar and then concat it to the end of bb ?

mmer12:10:57

Having invested in using the bb tasks approach, is there any way that that could be wrapped into an uberjar?

borkdude12:10:58

@U4C3ZU6KX tasks are project-specific, at least that is the intention

borkdude12:10:45

I do recall something with bb.edn in an uberjar being picked up so maybe it works

borkdude12:10:50

I'll try locally

mmer12:10:58

Interesting - I see them as alternative entry points into my code. The :init acts as the first part of a main and the task then is as if the main calls a particular end point.

borkdude12:10:43

@U4C3ZU6KX I'd probably use babashka.cli subcommands for your use case: https://github.com/babashka/cli#subcommands

mmer12:10:04

Neat. Thanks.

borkdude13:10:35

@U4C3ZU6KX I found a way to run bb tasks in a self-contained binary. Use this as your main entry point:

(ns buber
  (:require [babashka.tasks :as tasks]))

(defn -main [task & args]
  (binding [*command-line-args* args]
    (tasks/run (symbol task))))

๐Ÿ‘ 2
clojure-spin 2
borkdude13:10:49

and then put your bb.edn in META-INF in the uberjar

borkdude13:10:01

You will need the master version that was just pushed

Samuel Ludwig14:10:06

ohhh this is excitingggg gratitude

โž• 2
Tomas Brejla17:10:05

....I just tested it on windows and yes, it works as expected ๐Ÿ‘

copy /b bb.exe + foo.jar mybb.exe
C:\foo>mybb.exe 1 2 3
("1" "2" "3") 6

Tomas Brejla17:10:33

what a time to be alive! (โ„ข๏ธ) ๐Ÿ˜„

Tomas Brejla17:10:20

So if you're building some babashka CLI app, I believe you'll be able to generate native binaries for all the combinations of OSs (mac, linux, windows) and platforms (arm, amd64) in matter of seconds. No compilation whatsover. Looking forward to see how fast such CI pipeline can run ๐Ÿคž.

elken09:10:37

(better late than never...) So I'm looking at this now, for our usecase we have a seperate bb.edn with all the tasks defined in it; is it going to be preferable to refactor it to be a babashka.cli program instead? > and then put your bb.edn in META-INF in the uberjar I'm new to java packaging, so while I understand what this means I'm lost on how to do it ๐Ÿ˜…

elken09:10:53

I've been debating refactoring it to babashka.cli anyway, since we'd benefit from the extra additions, so having to do so to make this simpler is no trouble ๐Ÿ™‚

borkdude09:10:09

@U043RSZ25HQ So how to deal with tasks: โ€ข Add bb.edn to META-INF/bb.edn E.g.:

{:paths ["resources"]}
mkdir -p resources/META-INF
cp bb.edn resources/META-INF
In src/buber.clj:
(ns buber
  (:require [babashka.tasks :as tasks]))

(defn -main [task & args]
  (binding [*command-line-args* args]
    (tasks/run (symbol task))))
and then
bb uberjar tasks.jar -m buber 

borkdude09:10:20

and then proceed as documented with the self-contained jar

elken09:10:24

Ah I see, that clears that one up, thanks ๐Ÿ™‚

borkdude11:10:45

I added docs about tasks in self-contained binaries here now: https://github.com/babashka/babashka/wiki/Self-contained-executable#tasks

๐Ÿ™Œ 1
joost-diepenmaat15:10:03

Iโ€™ve been working with this approach today. I can even quickly create standalone binaries on github actions for all platforms on a single builder instance. Very nice. The only issue Iโ€™m running into now is that MacOS binaries need to be signed/notarized or they will give the usual annoying warning / message.

borkdude15:10:09

@U09N5N31T the bb binary itself isn't notarized. you won't have any problems with this if you download the binaries via a terminal. just don't download them via a browser and unzip them via finder

Tomas Brejla15:10:19

@U09N5N31T I've seen something similar on windows & avast antivirus. Once avast saw a new binary, it insisted on having it analysed on first execution. I have to wait a couple of 10s of seconds, but once it finished, it was working normally.

Tomas Brejla15:10:17

Btw how many different binaries did you build and how quick that process was? seconds?

borkdude15:10:00

it is only when you go through Finder's unzip, that macOS will think "wtf, a binary, let's set some attributes so nobody can run this" you undo that using:

sudo xattr -c ./my-binary

๐Ÿ˜† 1
borkdude15:10:38

the build process is as fast as you can run cat on two files

joost-diepenmaat15:10:56

Ooh good to know this is hooked into the browser download.

Ben Lieberman14:10:22

hi I am interested in using https://github.com/borkdude/etaoin-graal. Is this maintained and usable with Babashka or should I consider an alternative?

โœ… 1
mmer14:10:23

I am using etoain with bb

borkdude14:10:31

Regular etaoin works with bb now

Ben Lieberman14:10:52

Nice! Thank you :face_with_cowboy_hat:

grounded_sage16:10:55

I am spawning a babashka process to incrementally build a background task manager. This will likely get native compiled in the end. I noticed it terminates after receiving a SIGINT and there doesn't seem to be a way to handle it in babashka?

โœ… 1
Nundrum16:10:51

By "handle it" do you mean ignore it or react to it? You can add a shutdown hook with babashka:

(.addShutdownHook (Runtime/getRuntime) (Thread. (fn [] ...)))
Otherwise you'd have to try using jdk.internal.misc.Signal to implement a signal handler.

๐Ÿ‘ 1
grounded_sage18:10:07

Thanks! This solved it. I guess I just had not properly done this before and didnโ€™t know how to capture it

๐Ÿ‘ 3
Ben Lieberman22:10:58

Hey I just started a REPL and when def'ing vars I'm seeing this output #<Var@5f51c5c6: #{1 4 2}> instead of the typical namespace/var name combo. Is this expected behavior for bb? I would guess not.

Bob B22:10:05

I just attempted to repro... I feel like there was maybe a time when bb did this - are you running the latest version, and do you have a specific repro? Using bb repl and doing (def x #{ 1 2 3}) I get #'user/x - could maybe be a namespace thing?

Ben Lieberman23:10:28

ah yeah it seems I'm on a rather old version at home 1.0.168 and explains why I see this here and not at work where I have a release from just a few months ago

๐Ÿ‘ 1