graalvm

Discuss GraalVM related topics. Use clojure 1.10.2 or newer for all new projects. Contribute to https://github.com/clj-easy/graal-docs and https://github.com/BrunoBonacci/graalvm-clojure. GraalVM slack: https://www.graalvm.org/slack-invitation/.
heyarne 2021-06-19T16:16:12.150400Z

Hey there ๐Ÿ™‚ Is anybody here who could help me understand how graalvm and nix interact? I'm trying to build https://github.com/theiceshelf/firn/ from nix and it seems to succeed, but the resulting binary gives me an error when trying to execute it:

Error: Could not find or load main class firn.core
Caused by: java.lang.ClassNotFoundException: firn.core

heyarne 2021-06-19T16:28:21.151700Z

i'd also gladyly use pre-built binaries, but executing any graalvm bin on nixos aborts with "file does not exist or is not an executable". if somebody knows how to fix that, that would be amazing as well

Karol Wรณjcik 2021-06-19T16:53:49.152400Z

chmod +x <executable>?

heyarne 2021-06-19T16:56:40.152600Z

Unfortunately it's not that simple

heyarne 2021-06-19T16:57:04.152800Z

Meaning that I checked that already and I still get the same message

borkdude 2021-06-19T17:01:52.153Z

@arne-clojurians This is probably because the executable you build/use is glibc-linked

heyarne 2021-06-19T17:01:54.153200Z

The exact error is

Failed to execute process '../firn-test/firn'. Reason:
The file '../firn-test/firn' does not exist or could not be executed.
It's not limited to firn though, when trying out bootleg I hit the same error

borkdude 2021-06-19T17:02:19.153500Z

Try the babashka static binary, it probably works

borkdude 2021-06-19T17:02:30.153700Z

It is statically linked against musl

borkdude 2021-06-19T17:02:53.153900Z

The Error: Could not find or load main class firn.core is probably due to dynamic requires or so

heyarne 2021-06-19T17:04:36.154100Z

The same thing happens with the most recent prebuilt babashka bin

borkdude 2021-06-19T17:06:00.154600Z

@arne-clojurians The -> static <- pre-built bin?

heyarne 2021-06-19T17:07:22.155Z

Ah no, you're right ๐Ÿ™‚

heyarne 2021-06-19T17:07:44.155400Z

Can I see how exactly that's built?

borkdude 2021-06-19T17:07:52.155600Z

sure, babashka is open source.

heyarne 2021-06-19T17:08:17.155800Z

Found the install file already

heyarne 2021-06-19T17:08:19.156Z

Thanks!

heyarne 2021-06-19T17:08:30.156200Z

And thanks for babashka of course

borkdude 2021-06-19T17:08:46.156400Z

For static linking with musl, you also might want to read: https://github.com/lread/clj-graal-docs#static-linking-with-musl

heyarne 2021-06-19T17:09:52.156800Z

Yes, that's exactly what I was looking for

borkdude 2021-06-19T17:13:35.157Z

Ah I see firn is already made to be compatible for graalvm

heyarne 2021-06-19T17:25:19.157600Z

Yes, exactly. But the provided binary raises the error described above

heyarne 2021-06-19T17:25:27.157800Z

Which I'm trying to wrap my head around

borkdude 2021-06-19T17:28:56.158Z

which one

borkdude 2021-06-19T17:29:20.158200Z

the executable not found error I already explained: this is because it's linked against glibc

borkdude 2021-06-19T17:29:33.158400Z

and glibc isn't in a standard location in nixos

borkdude 2021-06-19T17:30:09.158600Z

but perhaps it would work if you build it locally though, hmm

borkdude 2021-06-19T17:30:18.158800Z

perhaps @thiagokokada can help you, he also uses nixos

borkdude 2021-06-19T17:32:33.159Z

as does @ericdallo

kokada 2021-06-19T17:32:56.159200Z

I am trying to understand the exactly problem here? Is babashka static binary also having this issue of "file not found" :thinking_face: ?

kokada 2021-06-19T17:33:22.159400Z

BTW, if firn is having this issue it is probably using dynamic link

kokada 2021-06-19T17:33:27.159600Z

You can use ldd to check this

borkdude 2021-06-19T17:33:42.159800Z

the bb static should work.

ericdallo 2021-06-19T17:34:06.160Z

Graalvm non static binaries doesn't work on NixOS unless you compile the image on your machine

borkdude 2021-06-19T17:34:08.160200Z

but if you build firn locally in nixos, wouldn't it work with glibc as well?

ericdallo 2021-06-19T17:34:19.160400Z

The bb static works fine for me and @thiagokokada on nixos

kokada 2021-06-19T17:36:12.160600Z

BTW

ldd firn
ldd: warning: you do not have execution permission for `./firn'
	linux-vdso.so.1 (0x00007ffe6a9cb000)
	libpthread.so.0 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib/libpthread.so.0 (0x00007f2fb26f4000)
	libdl.so.2 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib/libdl.so.2 (0x00007f2fb26ef000)
	libz.so.1 =&gt; not found
	libc.so.6 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib/libc.so.6 (0x00007f2fb252e000)
	/lib64/ld-linux-x86-64.so.2 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib64/ld-linux-x86-64.so.2 (0x00007f2fb63d2000)

kokada 2021-06-19T17:37:22.160800Z

> but if you build firn locally in nixos, wouldn't it work with glibc as well? It works as long the PATH to glibc doesn't change (but it changes frequently, for example, if any library that glibc depends is updated, the hash on the path is updated)

ericdallo 2021-06-19T17:38:16.161Z

so, for graalvm works on nixos I always need to go into a shell with gcc, something like this should work:

nix-shell -p 'gcc'

ericdallo 2021-06-19T17:38:30.161200Z

and then graalvm native-image compile works

ericdallo 2021-06-19T17:38:57.161400Z

this is because the gcc build input is missing from the graalvm nixpkgs derivation

kokada 2021-06-19T17:39:10.161600Z

> so, for graalvm works on nixos I always need to go into a shell with gcc, something like this should work: This may work with luck, but it is not necessary correct

kokada 2021-06-19T17:39:28.161800Z

Like I said, a rebuild on gcc may broke the binary

kokada 2021-06-19T17:41:39.162Z

Anyway, the root cause of the issue seems to be the fact that firn is not statically compiled

kokada 2021-06-19T17:42:04.162200Z

So maybe ask the maintainer if it could be static compiled :thinking_face: ? Or package it on nixpkgs

borkdude 2021-06-19T17:44:27.162400Z

probably a PR which makes musl the default on linux is the easiest route

borkdude 2021-06-19T17:51:59.162600Z

there's also this patch program for nixos right

borkdude 2021-06-19T17:52:08.162800Z

to make it work with the local glibc

kokada 2021-06-19T17:55:07.163100Z

Yeah, patchelf

kokada 2021-06-19T17:55:15.163300Z

But looking at the ldd, it is actually missing libz

kokada 2021-06-19T17:55:33.163500Z

$ ldd firn
ldd: warning: you do not have execution permission for `./firn'
	linux-vdso.so.1 (0x00007ffe6a9cb000)
	libpthread.so.0 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib/libpthread.so.0 (0x00007f2fb26f4000)
	libdl.so.2 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib/libdl.so.2 (0x00007f2fb26ef000)
	libz.so.1 =&gt; not found
	libc.so.6 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib/libc.so.6 (0x00007f2fb252e000)
	/lib64/ld-linux-x86-64.so.2 =&gt; /nix/store/ikl21vjfq900ccbqg1xasp83kadw6q8y-glibc-2.32-46/lib64/ld-linux-x86-64.so.2 (0x00007f2fb63d2000)

kokada 2021-06-19T17:55:42.163700Z

Only libz.so.1 is not found for firn

heyarne 2021-06-19T18:15:33.163900Z

I found a working nix derivation https://github.com/Emiller88/dotfiles/blob/master/packages/firn.nix

borkdude 2021-06-19T18:16:51.164200Z

nice

heyarne 2021-06-19T18:20:47.164400Z

Thanks for helping everyone ๐Ÿ™‚ That was very informative

heyarne 2021-06-19T18:29:40.164600Z

โ€ฆ static compilation with musl would still make the resulting binary significantly smaller, i guess?

borkdude 2021-06-19T18:30:27.164800Z

with babashka it's only a 5mb difference or so

heyarne 2021-06-19T18:33:59.165Z

ah yes, i mean vs using the patchelf'd version

heyarne 2021-06-19T18:34:28.165200Z

are you talking about dynamically linked babashka vs statically linked against musl?

borkdude 2021-06-19T18:34:57.165400Z

yes. you can see the binary sizes by going into the #babashka-circleci-buildss channel