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

Unable to build native image on Macbook Pro M4 Pro #45842

Closed
jcuero opened this issue Jan 24, 2025 · 4 comments · Fixed by #45876
Closed

Unable to build native image on Macbook Pro M4 Pro #45842

jcuero opened this issue Jan 24, 2025 · 4 comments · Fixed by #45876
Labels
area/native-image kind/bug Something isn't working
Milestone

Comments

@jcuero
Copy link
Contributor

jcuero commented Jan 24, 2025

Describe the bug

I'm trying to create a native image using Apple M4 Pro but I haven't been able to do it due to an error when getting the graalvm version.

./gradlew -Dquarkus.package.type=native -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true clean build

> There was a failure while executing work items
   > A failure occurred while executing io.quarkus.gradle.tasks.worker.BuildWorker
      > io.quarkus.builder.BuildException: Build failure: Build failed due to errors
                [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: java.lang.RuntimeException: Failed to get GraalVM version
                at io.quarkus.deployment.pkg.steps.NativeImageBuildRunner.getGraalVMVersion(NativeImageBuildRunner.java:41)
                at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:236)
                at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
                at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
                at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
                at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
                at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
                at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
                at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
                at java.base/java.lang.Thread.run(Thread.java:833)
                at org.jboss.threads.JBossThread.run(JBossThread.java:483)
        Caused by: java.lang.IllegalArgumentException: Cannot parse version from output:
        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        #  SIGILL (0x4) at pc=0x0000ffff6bd3fc5c, pid=1, tid=15
        #
        # JRE version:  (21.0.5+11) (build )
        # Java VM: OpenJDK 64-Bit Server VM (21.0.5+11-LTS, mixed mode, tiered, jvmci, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)
        # Problematic frame:
        # j  java.lang.System.registerNatives()V+0 java.base
        #
        # No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
        #
        # An error report file with more information is saved as:
        # /project/hs_err_pid1.log
        [0.011s][warning][os] Loading hsdis library failed
        #
        # The crash happened outside the Java Virtual Machine in native code.
        # See problematic frame for where to report the bug.
        #

        [error occurred during error reporting (), id 0x5, SIGTRAP (0x5) at pc=0x0000ffff84783afc]
                at io.quarkus.deployment.pkg.steps.GraalVM$Version.of(GraalVM.java:327)
                at io.quarkus.deployment.pkg.steps.NativeImageBuildRunner.getGraalVMVersion(NativeImageBuildRunner.java:38)
                ... 10 more

Expected behavior

I expect to be able to include custom parameters that are passed to "docker run" when I want to generate a native image.

docker run --env LANG=C --env _JAVA_OPTIONS=-XX:UseSVE=0 --rm --user 1000:1000 -i quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 --version

Actual behavior

Under the hood Quarkus executes this command

docker run --env LANG=C --rm --user 1000:1000 -i quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 --version

I know that the solution for this is to add _JAVA_OPTIONS=-XX:UseSVE=0 but it is not possible to do so because NativeImageBuildRunner.getGraalVMVersion/NativeImageBuildContainerRunner.buildCommand does not receive additional parameters through environment variables.

This method has the problem

@Override
protected String[] getGraalVMVersionCommand(List<String> args) {
return buildCommand("run", Collections.singletonList("--rm"), args);
}

This method is already working well

@Override
protected String[] getBuildCommand(Path outputDir, List<String> args) {
List<String> containerRuntimeBuildArgs = getContainerRuntimeBuildArgs(outputDir);
List<String> effectiveContainerRuntimeBuildArgs = new ArrayList<>(containerRuntimeBuildArgs.size() + 2);
effectiveContainerRuntimeBuildArgs.addAll(containerRuntimeBuildArgs);
effectiveContainerRuntimeBuildArgs.add("--name");
effectiveContainerRuntimeBuildArgs.add(containerName);
return buildCommand("run", effectiveContainerRuntimeBuildArgs, args);

How to Reproduce?

Can be reproduced by running this command

./gradlew -Dquarkus.package.type=native -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true clean build

Output of uname -a or ver

No response

Output of java -version

No response

Mandrel or 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

No response

@jcuero jcuero added area/native-image kind/bug Something isn't working labels Jan 24, 2025
Copy link

quarkus-bot bot commented Jan 24, 2025

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

@zakkak
Copy link
Contributor

zakkak commented Jan 25, 2025

Hi @jcuero,

I asssume

docker run --env LANG=C --env _JAVA_OPTIONS=-XX:UseSVE=0 --rm --user 1000:1000 -i quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 --version 

is working as expected.

Could you please try using -Dquarkus.native.container-runtime-options="--env _JAVA_OPTIONS=-XX:UseSVE=0"?

@jcuero
Copy link
Contributor Author

jcuero commented Jan 25, 2025

Hi @zakkak, I'm getting the same error.

In order to understand, and subsequently be able to generate the native image, I renamed the docker binary and replaced it with a script.

After adding the parameter you indicate, I still get the same error

 Caused by: java.lang.IllegalArgumentException: Cannot parse version from output: 
        Running the command: run --env LANG=C --rm --user 0 --rm quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 --version
        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        #  SIGILL (0x4) at pc=0x0000ffff87d3fc5c, pid=1, tid=15
        #
        # JRE version:  (21.0.5+11) (build )
        # Java VM: OpenJDK 64-Bit Server VM (21.0.5+11-LTS, mixed mode, tiered, jvmci, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)
        # Problematic frame:
        # j  java.lang.System.registerNatives()V+0 java.base

/usr/local/bin/docker

#!/bin/bash

if [[ "$1" == "run" ]]; then
  echo "Running the command: "$1" "${@:2}""

  # this fails
  /usr/local/bin/docker_original "$1" "${@:2}"

  # this allows me to generate the native image.
  #/usr/local/bin/docker_original "$1" --env _JAVA_OPTIONS=-XX:UseSVE=0 "${@:2}"
elif [[ "$1" == "build" ]]; then
  /usr/local/bin/docker_original "$1" "${@:2}"
else
  /usr/local/bin/docker_original "$@"
fi```

@zakkak
Copy link
Contributor

zakkak commented Jan 27, 2025

Thanks for checking @jcuero unfortunately quarkus.native.container-runtime-options are not applied when getting the version. I will prepare a patch for this.

zakkak added a commit to zakkak/quarkus that referenced this issue Jan 27, 2025
`quarkus.native.container-runtime-options` should be respected when
invoking the builder image to get its version.

Closes: quarkusio#45842
@gsmet gsmet closed this as completed in 726ba17 Jan 27, 2025
@quarkus-bot quarkus-bot bot added this to the 3.19 - main milestone Jan 27, 2025
@gsmet gsmet modified the milestones: 3.19 - main, 3.18.1 Jan 28, 2025
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jan 28, 2025
`quarkus.native.container-runtime-options` should be respected when
invoking the builder image to get its version.

Closes: quarkusio#45842
(cherry picked from commit 726ba17)
carlesarnal pushed a commit to carlesarnal/quarkus that referenced this issue Feb 6, 2025
`quarkus.native.container-runtime-options` should be respected when
invoking the builder image to get its version.

Closes: quarkusio#45842
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants