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

Compiling a quarkus-cli to binary using native-sources breaks picocli #25762

Closed
andreaTP opened this issue May 24, 2022 · 8 comments · Fixed by #25803
Closed

Compiling a quarkus-cli to binary using native-sources breaks picocli #25762

andreaTP opened this issue May 24, 2022 · 8 comments · Fixed by #25803
Labels
area/cli Related to quarkus cli (not maven/gradle/etc.) area/native-image area/picocli kind/bug Something isn't working
Milestone

Comments

@andreaTP
Copy link
Contributor

andreaTP commented May 24, 2022

Describe the bug

Trying to compile a Quarkus Cli application to fully static binaries "breaks" picocli.

cc. @remkop

Expected behavior

The executable should run in the same way with Java and when compiled.

Actual behavior

__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2022-05-24 16:00:11,702 INFO  [io.quarkus] (main) code-with-quarkus 1.0.0-SNAPSHOT native (powered by Quarkus 2.9.1.Final) started in 0.012s. 
2022-05-24 16:00:11,705 INFO  [io.quarkus] (main) Profile prod activated. 
2022-05-24 16:00:11,705 INFO  [io.quarkus] (main) Installed features: [cdi, picocli]
2022-05-24 16:00:11,706 ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): picocli.CommandLine$InitializationException: picocli.CommandLine$AutoHelpMixin@483680e0 is not a command: it has no @Command, @Option, @Parameters or @Unmatched annotations
        at picocli.CommandLine$Model$CommandReflection.validateCommandSpec(CommandLine.java:11680)
        at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11510)
        at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6236)
        at picocli.CommandLine$Model$CommandSpec.mixinStandardHelpOptions(CommandLine.java:7220)
        at picocli.CommandLine$Model$CommandReflection.extractCommandSpec(CommandLine.java:11505)
        at picocli.CommandLine$Model$CommandSpec.forAnnotatedObject(CommandLine.java:6236)
        at picocli.CommandLine.<init>(CommandLine.java:227)
        at picocli.CommandLine.<init>(CommandLine.java:221)
        at io.quarkus.picocli.runtime.DefaultPicocliCommandLineFactory.create(DefaultPicocliCommandLineFactory.java:43)
        at io.quarkus.picocli.runtime.DefaultPicocliCommandLineFactory_ClientProxy.create(Unknown Source)
        at io.quarkus.picocli.runtime.PicocliCommandLineProducer.picocliCommandLine(PicocliCommandLineProducer.java:23)
        at io.quarkus.picocli.runtime.PicocliCommandLineProducer_ProducerMethod_picocliCommandLine_9215511af8bf79a5b9761758f9829960bca3fec0_Bean.create(Unknown Source)
        at io.quarkus.picocli.runtime.PicocliCommandLineProducer_ProducerMethod_picocliCommandLine_9215511af8bf79a5b9761758f9829960bca3fec0_Bean.get(Unknown Source)
        at io.quarkus.picocli.runtime.PicocliCommandLineProducer_ProducerMethod_picocliCommandLine_9215511af8bf79a5b9761758f9829960bca3fec0_Bean.get(Unknown Source)
        at io.quarkus.picocli.runtime.PicocliRunner_Bean.create(Unknown Source)
        at io.quarkus.picocli.runtime.PicocliRunner_Bean.get(Unknown Source)
        at io.quarkus.picocli.runtime.PicocliRunner_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:467)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:480)
        at io.quarkus.arc.impl.BeanManagerImpl.getReference(BeanManagerImpl.java:59)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:120)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)

2022-05-24 16:00:11,707 INFO  [io.quarkus] (main) code-with-quarkus stopped in 0.001s

How to Reproduce?

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

In the reproducer I'm using zig cc as a drop in replacement for the compiler to leverage the static binary features.

@andreaTP andreaTP added the kind/bug Something isn't working label May 24, 2022
@quarkus-bot quarkus-bot bot added area/cli Related to quarkus cli (not maven/gradle/etc.) area/picocli labels May 24, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented May 24, 2022

/cc @ebullient, @maxandersen

@geoand
Copy link
Contributor

geoand commented May 25, 2022

I am pretty sure this is not a Quarkus issue, because if you take the sample application and just build it with mvn package -Dnative on Linux and run it, everything works.

@andreaTP
Copy link
Contributor Author

andreaTP commented May 25, 2022

@geoand thanks for looking into it!
I went ahead and bisected the issue, you can find my results in this branch: https://github.com/andreaTP/test_graal_zig_cc/tree/quarkus-picocli-bisect

Using this Dockerfile : https://github.com/andreaTP/test_graal_zig_cc/blob/quarkus-picocli-bisect/Dockerfile.with.Maven

Running mvn clean package -Pnative everything works, but, running:

mvn clean package -Dquarkus.package.type=native-sources
cd target/native-sources && native-image $(cat native-image.args)

Breaks picocli with the error above. I'll update the title of this issue accordingly.

@andreaTP andreaTP changed the title Compiling a quarkus-cli application to a static binary breaks picocli Compiling a quarkus-cli to binary using native-sources breaks picocli May 25, 2022
@geoand
Copy link
Contributor

geoand commented May 25, 2022

Interesting!

I'll take another look soon

@andreaTP
Copy link
Contributor Author

More bisecting, the actual difference is in the jar used to build the native image.
Using mvn clean package -Pnative native-image command target this jar
code-with-quarkus-1.0.0-SNAPSHOT-runner_2.zip

instead using mvn clean package -Dquarkus.package.type=native-sources generates in the /target/native-sources folder this jar:
code-with-quarkus-1.0.0-SNAPSHOT-runner_1.zip

The file size is slightly different:

     93811 25 May 18:10 code-with-quarkus-1.0.0-SNAPSHOT-runner_1.zip
     94455 25 May 18:13 code-with-quarkus-1.0.0-SNAPSHOT-runner_2.zip

Looks like "something" is missing from the Jar generated with native-sources

@andreaTP
Copy link
Contributor Author

The diff shows that there is a difference in the generated io/quarkus/runner/AutoFeature.class.

Decompiling it shows a bunch of missing registerClass in the "not working" one.

But now debugging is a little too steep for my knowledge of Quarkus 🙂 I drop the ball in your court @geoand 🙂

@geoand
Copy link
Contributor

geoand commented May 25, 2022

Thanks a lot for the analysis!

That pretty much confirms what I suspected. It should be an easy fix, but I'll know more tomorrow

@geoand
Copy link
Contributor

geoand commented May 26, 2022

#25803 is the fix.

Thanks for reporting!

geoand added a commit to geoand/quarkus that referenced this issue May 26, 2022
geoand added a commit to geoand/quarkus that referenced this issue May 26, 2022
geoand added a commit that referenced this issue May 26, 2022
Take native-sources build into account for various extensions
@quarkus-bot quarkus-bot bot added this to the 2.10 - main milestone May 26, 2022
@gsmet gsmet modified the milestones: 2.10 - main, 2.7.6.Final May 28, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Related to quarkus cli (not maven/gradle/etc.) area/native-image area/picocli kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants