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

Building native executables when using deps that does not have native binaries on arm platform not working #37455

Closed
edeandrea opened this issue Dec 1, 2023 · 9 comments
Labels
area/native-image env/m1 Impacts Apple M1 machines kind/bug Something isn't working

Comments

@edeandrea
Copy link
Contributor

edeandrea commented Dec 1, 2023

Describe the bug

Reporting this per @maxandersen. This is to report that the changes made in #36628 do not seem to work.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

Follow these steps to reproduce on a Mac M1 (or any other ARM machine):

  1. Clone the Quarkus Superheroes locally
  2. cd into rest-fights.
    • Currently this app uses Quarkus community 3.6.0
  3. Update the pom.xml by adding the Red Hat Maven repo:
 <repositories>
    <repository>
      <id>red-hat-enterprise-maven-repository</id>
      <url>https://maven.repository.redhat.com/ga/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>red-hat-enterprise-maven-repository</id>
      <url>https://maven.repository.redhat.com/ga/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
  1. Update the pom.xml by adding the following dependency:
    <dependency>
      <groupId>com.github.luben</groupId>
      <artifactId>zstd-jni</artifactId>
      <version>1.5.2.3-redhat-00002</version>
    </dependency>
  1. Run ./mvnw clean package -DskipTests -Pnative
  2. Native build will fail with something like this (you can also see something similar in https://github.com/quarkusio/quarkus-super-heroes/actions/runs/7060779473/job/19221013171#step:9:3996):
Error: Class specified as onlyWith for io.quarkus.netty.runtime.graal.HttpContentCompressorSubstitutions$ZstdEncoderFactorySubstitution cannot be loaded or instantiated: io.quarkus.netty.runtime.graal.HttpContentCompressorSubstitutions$IsZstdAbsent
com.oracle.svm.core.util.UserError$UserException: Class specified as onlyWith for io.quarkus.netty.runtime.graal.HttpContentCompressorSubstitutions$ZstdEncoderFactorySubstitution cannot be loaded or instantiated: io.quarkus.netty.runtime.graal.HttpContentCompressorSubstitutions$IsZstdAbsent
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:85)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.findTargetClass(AnnotationSubstitutionProcessor.java:1052)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:373)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:351)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.createAnnotationSubstitutionProcessor(NativeImageGenerator.java:1029)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:907)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:590)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:550)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:538)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:720)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:142)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:97)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
        at org.graalvm.nativeimage.base/com.oracle.svm.util.ReflectionUtil.newInstance(ReflectionUtil.java:106)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.findTargetClass(AnnotationSubstitutionProcessor.java:1050)
        ... 10 more
Caused by: java.lang.UnsatisfiedLinkError: no zstd-jni-1.5.2.3-redhat-00002 in java.library.path: /Users/edeandre/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Unsupported OS/arch, cannot find /darwin/aarch64/libzstd-jni-1.5.2.3-redhat-00002.dylib or load zstd-jni-1.5.2.3-redhat-00002 from system libraries. Please try building from source the jar or providing libzstd-jni-1.5.2.3-redhat-00002 in your system.
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2458)
        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:916)
        at java.base/java.lang.System.loadLibrary(System.java:2059)
        at com.github.luben.zstd.util.Native.load(Native.java:87)
        at com.github.luben.zstd.util.Native.load(Native.java:55)
        at com.github.luben.zstd.Zstd.<clinit>(Zstd.java:13)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:421)
        at java.base/java.lang.Class.forName(Class.java:412)
        at io.quarkus.netty.runtime.graal.HttpContentCompressorSubstitutions$IsZstdAbsent.<init>(HttpContentCompressorSubstitutions.java:38)
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
        ... 14 more

Output of uname -a or ver

Darwin edeandrea-m1pro 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment Temurin-17.0.9+9 (build 17.0.9+9)
OpenJDK 64-Bit Server VM Temurin-17.0.9+9 (build 17.0.9+9, mixed mode)

Mandrel or GraalVM version (if different from Java)

openjdk 21.0.1 2023-10-17
OpenJDK Runtime Environment GraalVM CE 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19)
OpenJDK 64-Bit Server VM GraalVM CE 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)

Quarkus version or git rev

3.6.0

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

Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /Users/edeandre/.m2/wrapper/dists/apache-maven-3.9.5-bin/32db9c34/apache-maven-3.9.5
Java version: 17.0.9, vendor: Eclipse Adoptium, runtime: /Users/edeandre/.sdkman/candidates/java/17.0.9-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "14.1.1", arch: "aarch64", family: "mac"

Additional information

No response

@edeandrea edeandrea added area/native-image kind/bug Something isn't working labels Dec 1, 2023
@quarkus-bot quarkus-bot bot added the env/m1 Impacts Apple M1 machines label Dec 1, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 1, 2023

/cc @Karm (mandrel), @galderz (mandrel), @gastaldi (m1), @zakkak (mandrel,native-image)

@maxandersen maxandersen changed the title Building native executables using RHBQ on arm platform not working Building native executables when using deps that does not have native binaries on arm platform not working Dec 1, 2023
@cescoffier
Copy link
Member

This is a product issue - the artifact does not contains the libraries. It works with the upstream.

@cescoffier cescoffier closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2023
@edeandrea
Copy link
Contributor Author

Changing the version of the zstd-jni library can cause this failure on community. At least thats what @maxandersen said.

@cescoffier
Copy link
Member

What do you mean by changing the version? Is their a pure upstream reproducer?

@cescoffier
Copy link
Member

zstd-jni is the artifact that has the missing native libs.

@maxandersen
Copy link
Contributor

@cescoffier the issue is that our unit code fail on optional feature. You already did one attempt on avoiding this.

Yes the jar that triggers this is in product but the code that is not lenient is in quarkus community core.

@maxandersen maxandersen reopened this Dec 1, 2023
@cescoffier
Copy link
Member

Not really, we check the presence or absence of the jar already. Fixing this would mean that every time we touch a resource or a class we need to check the existence of that resource. That is feasible in theory, but would require massive substitutions, and not only - we would need to change many things in the Quarkus extensions (because what's happen here, could happen anywhere).

Trying to load the native lib in the substitution is somewhat possible but some applications will break because of this tainted jar (that will be the case for Kafka for example, as the upstream code also check the optionality, code we cannot change or substitute).

The only sane fixes are: get a product jar containing at least the same native libs than the upstream, or exclude that jar and use the upstream one instead.

@cescoffier
Copy link
Member

Also, loading the native lib at build time would require that the system contains all the dependant libs at the right location (replicating the prod file system). (Zlib is standalone enough if I remember correctly, but if we do something for this one we need to do it everywhere)

@edeandrea
Copy link
Contributor Author

Looks like this has been resolved as of 3.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image env/m1 Impacts Apple M1 machines kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants