Skip to content

Commit

Permalink
Merge pull request #1 from shrikecode/bin-build
Browse files Browse the repository at this point in the history
Bin build
  • Loading branch information
wmwnuk authored Jun 29, 2024
2 parents 4ebdeaf + c67df5e commit 70e2c38
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 8 deletions.
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
/.clj-kondo/
/.lsp/
classes/
.clj-kondo/
.cpcache/
.lsp/
*.build_artifacts.txt
bbb
bb
reports/
vendor/graalvm
/bin/base16-builder-bb
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/babashka"]
path = vendor/babashka
url = https://github.com/babashka/babashka
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DEFAULT_GOAL := build
.DESTDIR ?=

build:
rm bin/* || true
cp ./native-image.properties ./vendor/babashka/resources/META-INF/native-image/babashka/babashka/native-image.properties
bb native-image
cd vendor/babashka && git add resources/META-INF/native-image/babashka/babashka/native-image.properties && git reset --hard HEAD

install:
cp ./bin/base16-builder-bb ${DESTDIR}/usr/local/bin/base16-builder-bb
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

# base16 builder in babashka

It is kind of toy project to make base16 theme builder in Clojure, and since it's
a command-line tool, why not use babashka? For now you need to clone the whole
repo and run it like this:
It is kind of toy project to make base16 theme builder in Clojure, and since
it's a command-line tool, why not use babashka? For migh clone the whole repo
and run it like this:

``` sh
cat scheme.yaml | bb -m base16/-main --template template.mustache \
Expand All @@ -17,7 +17,34 @@ bb -m base16/-main --template template.mustache --scheme scheme.yaml \
> colorscheme.vim
```

## Installation

Just grab the `base16-builder-bb` from the releases, put somewhere in your `$PATH`
and you're good to go.

## Installing from source

Just run:

``` sh
make
sudo make install
```

### Build requirements

* babashka
* make
* git (obviously)

## Note

It is very barebones for now, will add some arguments and error handling in the
future.

## Roadmap

* [ ] add option to build whole dir with templates like newer builders
* [ ] build single binary from the project
* [ ] arguments like `--version`, `--help`
* [ ] arguments validation
* [x] build single binary from the project
114 changes: 112 additions & 2 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,113 @@
{:paths ["src"]
:deps {org.babashka/cli {:mvn/version "0.4.39"}
{:tasks {:init (def MAIN-NS "base16.core")

run (do
(require [(symbol MAIN-NS)])
(apply
(ns-resolve (find-ns (symbol MAIN-NS)) (symbol "-main"))
*command-line-args*))

run-clj {:depends [ensure-bb-submodule]
:task (deref (process (concat ["clj" "-m" MAIN-NS] *command-line-args*)
{:inherit true}))}

build {:depends [ensure-bb-submodule ensure-graalvm]
:task (shell {:extra-env EXTRA-ENV}
(str "clj -X:native-image '{:main-ns \"" MAIN-NS "\"} "))}

native-image {:depends [build]}

ensure-bb-submodule (shell "git submodule update --init --recursive")

ensure-graalvm {:task (when-not
(->> "which native-image"
(shell {:continue true
:out nil :err nil
:extra-env EXTRA-ENV})
(:exit)
(= 0))
(babashka.tasks/run "install-graalvm"))}

uberjar-bb (do (shell "mkdir -p classes/")
(println "bbb: Compiling" MAIN-NS)
(deref (process ["clj" "-e"
(str "(require '" MAIN-NS ")"
"(compile '" MAIN-NS ")")]))
(println "bbb: Building uberjar to" (str MAIN-NS ".jar"))
(deref (process ["bb" "-cp" (str (->> (shell {:out :string} "clojure -Spath")
:out str/trim)
":classes")
"uberjar"
(str MAIN-NS ".jar") "-m" MAIN-NS])))

uberjar-clj (do (deref (process ["clj" "-X:uberjar" ":jar" (str MAIN-NS ".jar")
":main-class" MAIN-NS]
{:inherit true})))

uberjar (do
(println "bbb: Building a JVM Clojure uberjar, use uberjar-bb instead for a babashka uberjar")
(babashka.tasks/run "uberjar-clj"))

install-graalvm (bbb/install-graalvm-locally (str (fs/canonicalize "vendor/graalvm")))

:enter (let [suffix (when (= (System/getProperty "os.name") "Mac OS X") "/Contents/Home")
graalpath (str (fs/canonicalize (str "vendor/graalvm" suffix)))]
(def LOCAL-GRAAL (when (-> (str graalpath "/bin/native-image") io/file .exists)
(-> graalpath fs/canonicalize str)))
(def EXTRA-ENV
(if LOCAL-GRAAL
{"PATH" (str graalpath "/bin" ":" (System/getenv "PATH"))
"GRAALVM_HOME" graalpath}
{})))

:requires [[babashka.process :refer [process]]
[bbb.core :as bbb]
[clojure.java.io :as io]
[clojure.string :as str]
[babashka.fs :as fs]]}

:aliases {:native-image
{:exec-args {:main-ns "example.core"} ;; example.core is a default, is overridden by MAIN-NS
:exec-fn bbb.dep-edn-alias/tools-deps-entrypoint
:jvm-opts ["-Dclojure.compiler.direct-linking=true"
;; ;; consider uncommenting the below options when building in docker or low mem envs
;; "-Dnative" "-Dnative-image.docker-build=true" "-Dnative-image.xmx=4g"
"-Dclojure.spec.skip-macros=true"]
:extra-deps
{clj.native-image/clj.native-image
{:git/url "https://github.com/taylorwood/clj.native-image.git"
:sha "4604ae76855e09cdabc0a2ecc5a7de2cc5b775d6"}}}

:uberjar
{:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
:exec-fn hf.depstar/uberjar
:exec-args {:jar "uber.jar"
:aot true}}}
:paths ["src"]
:deps {borkdude/spartan.spec {:git/url "https://github.com/borkdude/spartan.spec"
:sha "12947185b4f8b8ff8ee3bc0f19c98dbde54d4c90"}
selmer/selmer {:mvn/version "1.12.44"},
org.clojure/clojure {:mvn/version "1.11.0-alpha1"},
org.clojure/tools.logging {:mvn/version "1.1.0"},
org.clojure/tools.cli {:mvn/version "1.0.206"},
rewrite-clj/rewrite-clj {:mvn/version "1.0.699-alpha"},
hiccup/hiccup {:mvn/version "2.0.0-alpha2"},
org.clojure/data.xml {:mvn/version "0.2.0-alpha6"},
org.clojure/data.csv {:mvn/version "1.0.0"},
com.taoensso/timbre {:mvn/version "5.1.2"},
com.cognitect/transit-clj {:mvn/version "1.0.324"},
babashka/babashka.curl {:mvn/version "0.0.3"},
clj-commons/clj-yaml {:mvn/version "0.7.107"},
cheshire/cheshire {:mvn/version "5.10.1"},
org.clojure/core.match {:mvn/version "1.0.0"},
org.clojure/test.check {:mvn/version "1.1.0"},
babashka/fs {:mvn/version "0.0.5"},
nrepl/bencode {:mvn/version "1.1.0"},
org.clojure/core.async {:mvn/version "1.4.627"},
;; added deps
babashka/babashka {:local/root "vendor/babashka"}

cli-matic/cli-matic {:git/url "https://github.com/l3nz/cli-matic.git"
:sha "1aa64070fec1556998b5bbb95d72f3513667ff6a"}
http-kit/http-kit {:mvn/version "2.5.3"}
org.babashka/cli {:mvn/version "0.4.39"}
pogonos/pogonos {:mvn/version "0.2.1"}}}
Empty file added bin/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions deps.edn
29 changes: 29 additions & 0 deletions native-image.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

ImageName=bin/base16-builder-bb
Args=-H:+ReportExceptionStackTraces \
-J-Dborkdude.dynaload.aot=true \
-H:IncludeResources=BABASHKA_VERSION \
-H:IncludeResources=META-INF/babashka/.* \
-H:IncludeResources=src/babashka/.* \
-H:IncludeResources=SCI_VERSION \
-H:Log=registerResource:3 \
--enable-url-protocols=http,https,jar,unix \
--enable-all-security-services \
-H:+JNI \
--no-server \
--report-unsupported-elements-at-runtime \
--initialize-at-build-time=com.fasterxml.jackson \
--initialize-at-build-time=java.sql.SQLException \
--initialize-at-build-time=org.yaml.snakeyaml \
--initialize-at-run-time=org.postgresql.sspi.SSPIClient \
--initialize-at-run-time=org.httpkit.client.ClientSslEngineFactory$SSLHolder \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileReader \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileReader \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.MixerProvider \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.FormatConversionProvider \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.sampled.spi.AudioFileWriter \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiDeviceProvider \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.SoundbankReader \
-H:ServiceLoaderFeatureExcludeServices=javax.sound.midi.spi.MidiFileWriter \
-H:ServiceLoaderFeatureExcludeServices=java.net.ContentHandlerFactory \
-H:ServiceLoaderFeatureExcludeServices=java.nio.charset.spi.CharsetProvider
10 changes: 10 additions & 0 deletions reflection-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "java.lang.reflect.AccessibleObject",
"methods": [
{
"name": "canAccess"
}
]
}
]
1 change: 1 addition & 0 deletions vendor/babashka
Submodule babashka added at 7abd00

0 comments on commit 70e2c38

Please sign in to comment.