2020-01-08 20:30:50 +00:00
# Developing Babashka
2020-03-23 10:35:34 +00:00
You need [lein ](https://leiningen.org/ ) for running JVM tests and/or producing uberjars. For building binaries you need GraalVM. Currently we use java8-19.3.1.
2020-03-23 10:35:10 +00:00
2020-03-23 10:31:47 +00:00
## Clone repository
2020-01-08 20:30:50 +00:00
To work on Babashka itself make sure Git submodules are checked out.
``` shellsession
$ git clone https://github.com/borkdude/babashka --recursive
```
To update later on:
``` shellsession
$ git submodule update --recursive
```
## REPL
`lein repl` will get you a standard REPL/nREPL connection. To work on tests use `lein with-profiles +test repl` .
2020-04-30 11:01:36 +00:00
## Adding libraries and classes
When adding libraries to babashka, consider these evaluation criteria:
2020-04-30 11:07:38 +00:00
- The library or class is useful for general purpose scripting or accomplishing
2020-04-30 11:16:20 +00:00
small devops tasks.
2020-04-30 11:15:14 +00:00
- Adding the library or class would make babashka more compatible with Clojure
libraries relevant to scripting or small devops tasks.
2020-04-30 11:04:46 +00:00
- The functionality can't be met by shelling out to another CLI or can't be
written as a small layer over an existing CLI (like `babashka.curl` ) instead.
2020-04-30 11:01:36 +00:00
2020-04-30 11:18:10 +00:00
If not all of the criteria are met, but adding a feature is still useful to a
particular company or niche audience, adding it behind a feature flag is still a
possibility. This is currently the case for `next.jdbc` and the `PostgresQL` and
`HSQLDB` database drivers. Companies interested in these features can compile an
2020-04-30 11:19:18 +00:00
instance of babashka for their internal use.
2020-04-30 11:01:36 +00:00
2020-01-08 20:30:50 +00:00
### Adding classes
Add necessary classes to `babashka/impl/classes.clj` . For every addition, write
a unit test, so it's clear why it is added and removing it will break the
tests. Try to reduce the size of the binary by only adding the necessary parts
of a class in `:instance-check` , `:constructors` , `:methods` , `:fields` or
`:custom` .
The `reflection.json` file that is needed for GraalVM compilation is generated
with:
lein with-profiles +reflection run
## Test
Test on the JVM (for development):
script/test
Test the native version:
BABASHKA_TEST_ENV=native script/test
## Build
2020-04-26 11:10:30 +00:00
See [build.md ](build.md ).
2020-01-08 20:30:50 +00:00
2020-04-26 19:19:49 +00:00
## JDBC
2020-04-26 19:21:41 +00:00
Findings from various experiments with JDBC drivers in babashka:
2020-04-26 19:19:49 +00:00
- Postgres: adds 3MB to the binary. It seems the maintainers have put in effort
2020-04-26 19:21:41 +00:00
to make the driver compatible with Graal. The driver is part of `bb` since
`v0.0.89` .
2020-04-26 19:19:49 +00:00
- Sqlite: I feel like I'm close to a working solution, but it hangs. It adds
2020-04-26 19:30:31 +00:00
20MB to the binary. Since sqlite has a nice CLI we could also just shell out
to it (there's an example in the examples dir). We could also build a
2020-04-26 19:25:48 +00:00
`babashka.sqlite` namespace around the CLI maybe similar to
`babashka.curl` . See [#385 ](https://github.com/borkdude/babashka/issues/385 )
for details.
- HSQLDB: easy to get going with Graalvm. Adds 10 MB to the binary. It's under a
2020-04-27 18:37:23 +00:00
feature flag right now on master. See [build.md ](build.md ) for details. Derby
2020-04-26 19:25:48 +00:00
and H2 are known to not work with GraalVM, so far this is the "best" embedded
2020-04-27 18:37:23 +00:00
option from a Graal perspective. Setting the -Xmx value for Docker to 4500m
got it to crash. 4800m did work, but it took 17 minutes (compared to 10
minutes without this feature).
2020-04-26 19:25:48 +00:00
- MySQL / MariaDB: can't get those to work yet. Work in progress in issue
[#387 ](https://github.com/borkdude/babashka/issues/387 ).
To progress work on sqlite and mySQL, I need a working Clojure example. If you
2020-04-26 19:26:16 +00:00
want to contribute, consider making a an example Clojure GraalVM CLI that puts
something in a sqlite / mysql DB and reads something from it.
2020-04-26 19:19:49 +00:00
2020-01-08 20:30:50 +00:00
## Binary size
2020-01-08 21:08:30 +00:00
Keep notes here about how adding libraries and classes to Babashka affects the binary size.
2020-04-18 18:54:05 +00:00
We're registering the size of the macOS binary (as built on CircleCI).
2020-01-08 21:08:30 +00:00
2020-04-24 13:08:26 +00:00
2020/04/23 Added `next.jdbc` and postgres JDBC driver:
(- 51019836 48099780) = 2920kb added
2020-04-23 08:55:34 +00:00
2020/04/23 Added BigDecimal
(- 48103868 47857732) = 246kb added
2020-04-18 19:04:34 +00:00
2020/04/18 Added clojure.data.xml
47808572 - 45923028 = 1886kb added.
2020-04-15 10:22:08 +00:00
2020/03/29 Added clj-yaml for parsing and generating yaml.
45196996 - 42626884 = 2570kb added.
2020-03-27 23:27:32 +00:00
2020/03/28 Added java.nio.file.FileSystem(s) to support extracting zip files
42562284 - 42021244 = 541kb added.
2020-03-22 10:49:14 +00:00
2020/03/22 Added java.io.FileReader
42025276 - 42008876 = 16kb added.
2020-03-20 16:16:42 +00:00
2020/03/20 Added transit write, writer, read, reader
42004796 - 41025212 = 980kb added (305kb zipped).
2020-01-08 20:30:50 +00:00
2020-03-20 13:28:19 +00:00
2020/03/19 Added java.lang.NumberFormatException, java.lang.RuntimeException,
java.util.MissingResourceException and java.util.Properties to support
[cprop ](https://github.com/tolitius/cprop/ ).
41025180 - 40729908 = 295kb added.
2020-01-08 20:30:50 +00:00
2020-03-20 13:28:19 +00:00
2020/02/21
2020-02-21 20:32:28 +00:00
Added java.time.temporal.ChronoUnit
40651596 - 40598260 = 53kb added.
2020-01-08 21:04:59 +00:00
2020-02-19 22:27:44 +00:00
2020/02/19, e43727955a2cdabd2bb0189c20dd7f9a18156fc9
Added fipp.edn/pprint
40598268 - 39744804 = 853kb added.
2020-02-09 19:49:55 +00:00
2020/02/09, c8fd1c7931d7842ebaec1fa8faf06d4ab58573bd
Added java.lang.BigInteger and java.security.MessageDigest.
2020-02-09 19:45:29 +00:00
39281972 - 39072764 = 209kb added.
2020-02-09 19:49:55 +00:00
2020/04/02 v0.0.69 38883676
2020-01-24 10:11:54 +00:00
2020/01/24, 43eef7075f9dac038d8d28a5ee4e49b6affd9864: 38.3mb, 11.1mb zipped
Added hierarchies (derive, isa?, etc).
2020/01/23, 485fef7df54d6701936704573468a1ec4c66d221: 37.4mb / 10.9mb zipped
Added: StringBuilder, java.io.{Reader,Writer,PrinterWriter,PushbackReader}
2020/01/08, 303ca9e825d76a4a45bc4240a59139d342c13964: 36.9mb / 10.8mb zipped
2020-01-09 09:46:39 +00:00
Removing cheshire from bb: 36.2mb / 10.5mb zipped.