Fork me on GitHub
#graalvm
<
2021-09-04
>
Joshua Suskalo19:09:55

I'm just getting started with making some graalvm images on my own rather than using cambada. I've been using the way to generate a package listing from https://github.com/lread/clj-graal-docs/issues/53 but whenever I use this my resulting images crash with an exception saying that they can't find the clojure/core/server__init.class files. When I pass an empty string, it works as intended, triggering my main function as normal. Is this something that someone else has run into?

borkdude19:09:46

This means that list just isn't complete. As of now, you don't yet need that list and you can just say --initialize-at-build-time

borkdude19:09:03

you also need clojure.server separately for some reason I think

Joshua Suskalo19:09:26

Oh, okay. So I guess that appending clojure like this one does isn't sufficient anymore.

Joshua Suskalo19:09:42

I guess then I'm puzzled why it filters out all the clojure packages.

borkdude19:09:57

perhaps you're just missing one package and that's why it complains about clojure.server

Joshua Suskalo19:09:18

I just tried not filtering out any clojure packages and it still broke.

Joshua Suskalo19:09:31

same error too, which is odd

borkdude19:09:50

I mean, you're missing just one random package from some random namespace

borkdude19:09:37

not from clojure itself

borkdude19:09:08

but clojure generates code in which clojure.server is referred so this can happen from any clojure code really

borkdude19:09:26

I vaguely remember something like this

borkdude19:09:41

perhaps in the main entry point

borkdude19:09:46

with gen-class

borkdude19:09:04

not sure, should look at the bytecode, it's been a while

Joshua Suskalo19:09:53

Oh it's just occurred to me what my problem is

Joshua Suskalo19:09:10

The call to all-ns is in the wrong jvm

Joshua Suskalo19:09:41

Alright, well for now I won't bother with specifying a list.

borkdude19:09:57

I will make a library to do this soon

borkdude19:09:05

since I will need it in a dozen of projects

Joshua Suskalo19:09:23

The other question I have is how to specify the name of the output image? I'm trying -H:Name=blah and it still just uses the name of the jar it's sourced from.

borkdude19:09:01

that should work

borkdude19:09:10

just check the babashka compile script

borkdude19:09:43

yeah, that should work

Joshua Suskalo19:09:49

Then I am very confused, because it is getting passed, but it's not changing the name.

borkdude19:09:01

can you show it

Joshua Suskalo19:09:10

(b/process {:command-args [native-image
                                 "-H:Name=fermented-formatter-standalone"
                                 "-jar" "fermented-formatter-standalone.jar"
                                 "--initialize-at-build-time"
                                 "--no-fallback"]
                  :dir target-dir})

Joshua Suskalo19:09:31

I had previously just fermented-formatter to pass the -H:Name= and it did nothing

Joshua Suskalo19:09:52

that is, it still had the -standalone suffix

borkdude19:09:19

I also recommend "--no-server"

Joshua Suskalo19:09:36

I had it on there for a bit, but at least on my machine it just says that's an invalid flag since it's not a server.

borkdude19:09:46

oh are you on windows or so?

Joshua Suskalo19:09:09

nope, manjaro, installed graalvm and native-image through the aur for the jdk11-graalvm-bin packages

borkdude19:09:54

are you sure you're using Oracle's native-image? 😆

Joshua Suskalo19:09:33

no I'm not, I didn't really check what the sources are for the aur packages. 😛

borkdude19:09:03

The help:

Usage: native-image [options] class [imagename] [options]
           (to build an image for a class)
   or  native-image [options] -jar jarfile [imagename] [options]
           (to build an image for a jar file)

Joshua Suskalo19:09:17

ooh, so I could just put the imagename at the end

borkdude19:09:44

it's a bit confusing

borkdude19:09:01

but the order probably matters

Joshua Suskalo19:09:25

Well the jayfu one you pointed me to had the -H before the -jar, but maybe it didn't matter for them since they are using the same name.

Joshua Suskalo19:09:27

Ah, I see, so it should probably go after

Joshua Suskalo19:09:36

or at least it's after in clj-kondo

borkdude19:09:10

ok, then I should probably correct this in jayfu

Joshua Suskalo20:09:19

Is there something special I have to do to have resources included?

Joshua Suskalo20:09:56

Or I guess I should step back a minute, is there any way for me to use the normal resources flow of using io/resource to get a file out from inside the resulting binary? It seems like there should be with the -H:IncludeResources flag

Joshua Suskalo20:09:04

But after including that, it doesn't appear to work.

borkdude20:09:17

yes, that should work. check clj-kondo for example

borkdude20:09:36

it includes the resources/clj_kondo/impl/built_in files

borkdude20:09:47

and they can be accessed through io/resource

borkdude20:09:09

also I usually include BABASHKA_VERSION in resources which I can read at runtime

Joshua Suskalo20:09:53

So order of arguments definitely fixed the problems with -H:Name worked. That said, same order as in babashka is giving me issues. I'm gonna try a couple more things then I'll push and post a link to see if you can spot anything if you're willing to look it over.

borkdude20:09:08

Do the resources work now? Glancing over the code it seems that you're using two ending //s perhaps, but just printing the resources config out will probably help spot that

Joshua Suskalo20:09:47

You're right, I am having a double slash now. I added those ending slashes for consistency just a minute ago. I'll try again without the double slash, but I don't think that's the issue.

borkdude21:09:03

can you post what the resources dirs look like now?

Joshua Suskalo21:09:26

-H:IncludeResources=resources/.* is what it is now, I'm doing a rebuild atm

Joshua Suskalo21:09:17

It did have the double slash last build tho

Joshua Suskalo21:09:28

Same error though.

borkdude21:09:51

you should probably not include resources

Joshua Suskalo21:09:53

I have the full verbose output I can post in a file if that'd help

borkdude21:09:56

as the pattern works over the classpath

Joshua Suskalo21:09:11

I thought it was an absolute file directory

borkdude21:09:32

and .* will include everything on the claspath probably so perhaps not the best thing to do :)

Joshua Suskalo21:09:21

I guess maybe what I should actually do is a file-seq that makes an alternation-based regex that's got every resource quoted

borkdude21:09:40

what is it that you want to include?

borkdude21:09:03

you can just do fermented_formatter/config.edn

borkdude21:09:08

if it's about that file

Joshua Suskalo21:09:33

Yes, it's about that file.

Joshua Suskalo21:09:46

Although I'd prefer to not have to edit this if I add more resources later.

Joshua Suskalo21:09:29

Or I could just do fermented_formatter/.* and commit to only putting resources under that path.

borkdude21:09:32

-H:IncludeResources=BABASHKA_VERSION \

borkdude21:09:39

is what I have in babashka

borkdude21:09:47

this includes resources/BABASHKA_VERSION

borkdude21:09:58

And then native image will automatically pick up on those

Joshua Suskalo21:09:34

awesome, it works now!

Joshua Suskalo21:09:51

I'll take a look

Joshua Suskalo21:09:49

I really appreciate all the help!