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

AwtProcessor use the default native-image version if necessary #37629

Merged
merged 1 commit into from
Dec 9, 2023

Conversation

Karm
Copy link
Member

@Karm Karm commented Dec 8, 2023

fixes #35746

There is a warning displayed that the default version was used:

karm@laptop:~/workspaceRH/quarkus-quickstarts (main *=)
$ ./mvnw clean package -Dquarkus.package.type=native-sources -pl awt-graphics-rest-quickstart
[INFO] --- quarkus-maven-plugin:999-SNAPSHOT:build (default) @ awt-graphics-rest-quickstart ---
[WARNING] [io.quarkus.awt.deployment.AwtProcessor]
 native-image is not installed. Using the default 23.1.0 version as a reference to build native-sources step.
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: /home/karm/workspaceRH/quarkus-quickstarts/awt-graphics-rest-quickstart/target/awt-graphics-rest-quickstart-1.0.0-SNAPSHOT-native-image-source-jar/awt-graphics-rest-quickstart-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] The sources for a subsequent native-image run along with the necessary arguments can be found in /home/karm/workspaceRH/quarkus-quickstarts/awt-graphics-rest-quickstart/target/native-sources
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 1376ms

I originally parsed the builder image link:

diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java
index 9b193308ec9..aaf5196f49f 100644
--- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java
+++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java
...
     String DEFAULT_GRAALVM_BUILDER_IMAGE = "quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:jdk-21";
     String DEFAULT_MANDREL_BUILDER_IMAGE = "quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21";
+    Pattern DEFAULT_BUILDER_IMAGE_PATTERN = Pattern.compile(
+            "[^:]*:(?:(?<mver>[^-]+)-java(?<mverjver>[0-9]+)|jdk-(?<jver>[1-9]+[0-9]*))");
... 
diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java
index d711928b67b..1f9a046f8a5 100644
--- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java
+++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java
@@ -1,5 +1,9 @@
 ...
@@ -129,7 +134,9 @@ private static String graalVersion(String buildInfo, int jdkFeature) {
     // Temporarily work around https://github.com/quarkusio/quarkus/issues/36246,
     // till we have a consensus on how to move forward in
     // https://github.com/quarkusio/quarkus/issues/34161
-    private static final Map<Integer, String> GRAAL_MAPPING = Map.of(22, "24.0",
+    public static final Map<Integer, String> GRAAL_MAPPING = Map.of(
+            21, "23.1",
+            22, "24.0",
             23, "24.1",
             24, "25.0",
             25, "25.1");
@@ -313,8 +320,35 @@ public boolean isJava17() {
         }
     }
 
+    /**
+     * @return default version of Mandrel builder image
+     */
+    public static Version getDefault() {
+        final Matcher m = DEFAULT_BUILDER_IMAGE_PATTERN.matcher(DEFAULT_MANDREL_BUILDER_IMAGE);
+        if (m.matches()) {
+            final String jver = m.group("jver");
+            final String mver = m.group("mver");
+            final String mverjver = m.group("mverjver");
+            if (!StringUtil.isNullOrEmpty(jver)) {
+                final int jverKey = Integer.parseInt(jver);
+                if (GRAAL_MAPPING.containsKey(jverKey)) {
+                    return new GraalVM.Version("native-image " + GRAAL_MAPPING.get(jverKey), GRAAL_MAPPING.get(jverKey), jver,
+                            Distribution.MANDREL);
+                } else {
+                    throw new RuntimeException("Unknown mapping between JDK version and native-image version.");
+                }
+            } else if (!StringUtil.isNullOrEmpty(mver) && !StringUtil.isNullOrEmpty(mverjver)) {
+                return new GraalVM.Version("native-image " + mver, mver, mverjver, Distribution.MANDREL);
+            } else {
+                throw new RuntimeException("Failed to parse Mandrel builder image name: " + DEFAULT_MANDREL_BUILDER_IMAGE);
+            }
+        } else {
+            throw new RuntimeException("Failed to parse Mandrel builder image name: " + DEFAULT_MANDREL_BUILDER_IMAGE);
+        }
+    }
+
     enum Distribution {
         GRAALVM,
-        MANDREL;
+        MANDREL
     }
 }
diff --git a/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java b/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
index a3b4d06c212..47d16fe8679 100644
--- a/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
+++ b/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java
@@ -7,6 +7,8 @@
...
@@ -103,7 +109,14 @@ void setupAWTInit(BuildProducer<JniRuntimeAccessBuildItem> jc,
             Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
         nativeImageRunnerBuildItem.getBuildRunner()
                 .setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
-        final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
+        final GraalVM.Version v;
+        if (nativeImageRunnerBuildItem.getBuildRunner() instanceof NoopNativeImageBuildRunner) {
+            v = GraalVM.getDefault();
+            log.warnf("native-image is not installed. Using default %s version as a reference to build native-sources step.",
+                    v);
+        } else {
+            v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
+        }
...

But that seems unnecessary and over-complicated. The current PR just picks the "CURRENT".

@Karm Karm self-assigned this Dec 8, 2023
Copy link

quarkus-bot bot commented Dec 8, 2023

/cc @galderz (awt)

@Karm Karm changed the title Makes AwtProcessor, the default native-image version AwtProcessor use the default native-image version if necessary Dec 8, 2023
@Karm Karm requested a review from geoand December 8, 2023 22:02
Copy link

quarkus-bot bot commented Dec 8, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@geoand geoand merged commit d0c390e into quarkusio:main Dec 9, 2023
18 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.7 - main milestone Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWT needs native-image installed to do native-source build
2 participants