This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-03
Channels
- # aleph (6)
- # announcements (4)
- # babashka (73)
- # beginners (117)
- # calva (25)
- # chlorine-clover (59)
- # cider (21)
- # clara (3)
- # cljdoc (8)
- # cljs-dev (54)
- # cljsrn (15)
- # clojure (65)
- # clojure-france (5)
- # clojure-spec (3)
- # clojure-uk (13)
- # clojurescript (79)
- # conf-proposals (1)
- # conjure (17)
- # core-logic (11)
- # datomic (21)
- # fulcro (82)
- # graalvm (11)
- # helix (7)
- # jobs-discuss (11)
- # joker (2)
- # juxt (3)
- # local-first-clojure (1)
- # luminus (5)
- # nrepl (61)
- # off-topic (12)
- # pathom (70)
- # re-frame (3)
- # reitit (3)
- # rum (1)
- # shadow-cljs (58)
- # sql (1)
- # tools-deps (26)
- # xtdb (3)
I'm not sure where else to ask since it's a fairly specific question (maybe in the graalvm channel later)
I have a script that works just fine if I run it with bb and that is also set up to be compile-able (as far as I can tell) but when I try to create a native image it tells me an assertion failed:
Execution error (AssertionError) at clojure.tools.cli/compile-option-specs (cli.cljc:282).
I looked into the error report and it said it had an issue expanding on line 163 which corresponds to:
(when-not (System/getProperty "babashka.main")
(apply -main *command-line-args*))
so I removed that and tried compiling it manually, but then it just tells meit cant find the main entry point.
Error: Main entry point class 'nativity' not found.
com.oracle.svm.core.util.UserError$UserException: Main entry point class 'nativity' not found.
> Execution error (AssertionError) at clojure.tools.cli/compile-option-specs (cli.cljc:282)
So maybe you are trying to do that on the top level in a namespace. Move it inside a function
the cli-options vector is defined in the top-level namespace but that doesn't use anything from http://tools.li
I noticed that it seems to run itself before compiling..
Marianos-MacBook-Pro:nativity mariano$ ./nativity.clj which.clj -m untouched
reading file
making directory
making modified script-file
making deps file
compiling native binary
Compiling nativity
Compiling which
/usr/bin/which
[which:60487] classlist: 7,439.09 ms, 1.32 GB
[which:60487] (cap): 1,191.32 ms, 1.32 GB
[which:60487] setup: 2,911.96 ms, 1.32 GB
so this code:
(when-not (System/getProperty "babashka.main")
(apply -main *command-line-args*))
this line is there to make the script execute as a script, when babashka.main is not set. so if you set babashka.main, it won't
you can add a check to it, to see if you're running with graalvm native-image or something else
hmmm okay I'll solve that separately, because when I remove it still fails to find main for some reason
(defn generate-deps-file [name-space native-image-name]
{:deps {'cheshire {:mvn/version "5.10.0"}
'org.clojure/tools.cli {:mvn/version "1.0.194"}
'org.clojure/clojure {:mvn/version "1.10.2-alpha1"}
'org.clojure/core.async {:mvn/version "1.1.587"}
'com.cognitect/transit-clj {:mvn/version "1.0.324"}
'bencode {:mvn/version "0.2.5"}
'org.clojure/data.csv {:mvn/version "1.0.0"}}
:aliases {:native-image
{:main-opts [(str "-m clj.native-image " name-space)
"--initialize-at-build-time "
;; optional native image name override
(str "-H:Name=" native-image-name)
"-H:+ReportExceptionStackTraces"]
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]
:extra-deps
{'clj.native-image
{:git/url ""
:sha "7708e7fd4572459c81f6a6b8e44c96f41cdd92d4"}}}}})
I don't know how the clj native tool works, but when I compile it with leiningen, I produce an uberjar that has a main method. So you can execute it with java -jar foo.jar
I found it much simpler to get the tooling out of the way and just use GraalVM directly
I'll yolo it for a bit more and then do exactly that.. probably starting with trying to compile with java first
You add a check like (find-ns 'babashka.classpath)
to determine if you're not running inside babashka
oh.. ok I'll leave both and modify the examples to include this check as well so it doesn't run for no reason
Well I'm not exactly sure why, but tools.cli doesn't allow compiling (it fails an assertion) if you have a 2 short flags that are not distinct. (even if those short flags are an empty string)
After figuring that out I finally made it so nativity can make a native binary out of itself! Probably pointless but I think it's cool.
hello @borkdude,
when I run this function in clj it works fine.
however in bb
I get an exception.
$ clj
user=> ((fn [& sqs]
(if (= 3 (ffirst sqs))
sqs
(recur (map #(map inc %) sqs)))) [1 2] [3 4])
((3 4) (5 6))
$ bb '((fn [& sqs] (if (= 3 (ffirst sqs)) sqs (recur (map #(map inc %) sqs)))) [1 2] [3 4])'
clojure.lang.ExceptionInfo: clojure.lang.LazySeq cannot be cast to java.lang.Number [at line 1, column 18]
I don’t know why :thinking_face: . Maybe the problem is in the recur binding.
in the first recursive iteration using clj
, sqs
is ((2 3) (4 5))
and using bb
I guess that sqs is (((2 3) (4 5)))
ok, thanks.
@UGRGT9RSR Fixed on master.
great!
one question: should I wait for a new release to update the cli via homebrew for example ?
yeah, but if you want a binary now, you can also grab one from #babashka_circleci_builds or build one yourself
thank you
as promised, here's a light psql
library for those that don't want to maintain their own jdbc-enabled bb
build: https://github.com/DarinDouglass/clj-psql
➜ bb --classpath ~/.m2/repository/douglass/clj-psql/0.1.2-SNAPSHOT/clj-psql-0.1.2-SNAPSHOT.jar
Babashka v0.0.88-2 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (require '[psql.core :as psql])
nil
user=> (def conn {:host "localhost",
:port 5432,
:username "postgres",
:password "",
:name "postgres"})
#'user/conn
user=> (psql/query conn :grades {})
({:name "Suzy Butterbean", :subject "Math", :grade "100", :comment "N/A"} {:name "Bobby Tables", :subject "Math", :grade "100", :comment "N/A"})
user=>
@ddouglass Awesome!
@ddouglass Does it also take vectors like ["select * from address where id = ?" 2]
?
At the moment this would translate to (psql/query conn :address {:id 2})
Replacing the simple form of “just give me your query” with the vector approach would be pretty simple if it feels more natural
Yeah. We can have all three supported. Ez Pz
user> (psql/query conn ["select * from grades where name = ? and grade = ?" "Bobby Tables" 100])
({:name "Bobby Tables",
:subject "Math",
:grade "100",
:comment "N/A"})
user>
It doesn’t. There’s a way to add “variables” like that through psql, but i wanted to start small
Even so, you still need to format correctly to avoid SQL injection, I haven’t found a good way to guard against that without having access to jdbc, etc.