Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM and Subcommands #372

Closed
hrothwell opened this issue Oct 4, 2022 · 3 comments
Closed

GraalVM and Subcommands #372

hrothwell opened this issue Oct 4, 2022 · 3 comments

Comments

@hrothwell
Copy link

Will start out by saying so far I love the library, my bigger qualms are with the combination of GraalVM and Windows....

I have a current working build of my application using Clikt found here. This works just fine and GraalVM is able to handle everything just fine to build a Windows native exe.

Exact GraalVM steps found in bat file here.

However, when trying to create subcommands off of Anime (example from old broken commit here), my reflect-config.json created by agentlib is no longer created and thus a native build no longer works. Everything works great in jvm (./gradlew run)

I have tried several work arounds such as manually parsing main args myself and trying to call different command classes based on args, but eventually that failed to build the reflect-config.json as well, which leads me to believe it is not just the subcommand function but perhaps a combination of a few factors which I have yet to look into.

Opening this issue up as a hopeful discussion topic around .subcommands() function and a place for others who may end up in my shoes to conjure to. Is .subcommands() known to have/have others had issues with this and GraalVM? I did see some not promising commits from trietsch/spotify-cli...

If I make any improvements I will make sure to update this thread

@hrothwell
Copy link
Author

hrothwell commented Oct 4, 2022

Additional findings 10/3/22:
Command().subcommands() (no subcommands) does not break the reflect-config.json built by agentlib
Command().subcommands(listOf(Subcommand()) breaks reflect-config.json build by agentlib

@hrothwell
Copy link
Author

Was indeed a user error on my part with GraalVM. I had read the agentlib doc a few times and for some reason this excerpt never really rang a lot of bells:

It can be necessary to run the target application more than once with different inputs to trigger separate execution paths for a better coverage of dynamic accesses. The agent supports this with the config-merge-dir option which adds the intercepted accesses to an existing set of configuration files

PR where I fixed this found here. Essentially when building the image try to hit all paths we can take (ie subcommands). Hope this might help someone in the future!

@ajalt
Copy link
Owner

ajalt commented Oct 4, 2022

Thanks for the info! There's a tech talk about running Clikt on Graal mentioned in #283. I'll add a section to the docs with some info on graal, and I'll make sure to include this gotcha.

FYI Clikt supports kotlin native, so if Graal keeps giving you trouble, you might consider building the native binaries directly. ktor has an http client that you could use with K/N if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants