Skip to content

Commit

Permalink
WIP: Support custom mandrel versions passed through a property
Browse files Browse the repository at this point in the history
Not working!
  • Loading branch information
zakkak committed Nov 23, 2023
1 parent 63ff7b0 commit ecb4237
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ default String getEffectiveImage() {
@WithDefault("false")
boolean reuseExisting();

/**
* Explicitly set GraalVM version.
* This is usefull when testing a Mandrel/Graal build that is not yet supported.
*/
Optional<String> mandrelVersion();

/**
* Build time configuration options for resources inclusion in the native executable.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.commons.lang3.SystemUtils;
import org.jboss.logging.Logger;

import io.quarkus.deployment.pkg.NativeConfig;
import io.quarkus.deployment.util.ProcessUtil;

public abstract class NativeImageBuildRunner {
Expand All @@ -23,18 +24,23 @@ public abstract class NativeImageBuildRunner {

private static GraalVM.Version graalVMVersion = null;

public GraalVM.Version getGraalVMVersion() {
public GraalVM.Version getGraalVMVersion(NativeConfig nativeConfig) {
if (graalVMVersion == null) {
try {
final String[] versionCommand = getGraalVMVersionCommand(Collections.singletonList("--version"));
log.debugf(String.join(" ", versionCommand).replace("$", "\\$"));
final Process versionProcess = new ProcessBuilder(versionCommand)
.redirectErrorStream(true)
.start();
versionProcess.waitFor();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(versionProcess.getInputStream(), StandardCharsets.UTF_8))) {
graalVMVersion = GraalVM.Version.of(reader.lines());
if (nativeConfig.mandrelVersion().isPresent()) {
String version = nativeConfig.mandrelVersion().get();
graalVMVersion = new GraalVM.Version(version, version, GraalVM.Distribution.MANDREL);
} else {
final String[] versionCommand = getGraalVMVersionCommand(Collections.singletonList("--version"));
log.debugf(String.join(" ", versionCommand).replace("$", "\\$"));
final Process versionProcess = new ProcessBuilder(versionCommand)
.redirectErrorStream(true)
.start();
versionProcess.waitFor();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(versionProcess.getInputStream(), StandardCharsets.UTF_8))) {
graalVMVersion = GraalVM.Version.of(reader.lines());
}
}
} catch (Exception e) {
throw new RuntimeException("Failed to get GraalVM version", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon
NativeImageBuildRunner buildRunner = nativeImageRunner.getBuildRunner();

buildRunner.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion();
final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion(nativeConfig);
checkGraalVMVersion(graalVMVersion);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public boolean reuseExisting() {
return false;
}

@Override
public Optional<String> mandrelVersion() {
return Optional.empty();
}

@Override
public ResourcesConfig resources() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.NativeConfig;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem;
Expand Down Expand Up @@ -107,7 +108,8 @@ public void jvmZip(OutputTargetBuildItem target,
* @throws Exception
*/
@BuildStep(onlyIf = { IsNormal.class, NativeBuild.class })
public void nativeZip(OutputTargetBuildItem target,
public void nativeZip(NativeConfig nativeConfig,
OutputTargetBuildItem target,
Optional<UpxCompressedBuildItem> upxCompressed, // used to ensure that we work with the compressed native binary if compression was enabled
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
NativeImageBuildItem nativeImage,
Expand Down Expand Up @@ -143,7 +145,7 @@ public void nativeZip(OutputTargetBuildItem target,
}
addZipEntry(zip, nativeImage.getPath(), executableName, 0755);

final GraalVM.Version graalVMVersion = nativeImageRunner.getBuildRunner().getGraalVMVersion();
final GraalVM.Version graalVMVersion = nativeImageRunner.getBuildRunner().getGraalVMVersion(nativeConfig);
if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) {
// See https://github.com/oracle/graal/issues/4921
try (DirectoryStream<Path> sharedLibs = Files.newDirectoryStream(nativeImage.getPath().getParent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem;
import io.quarkus.deployment.builditem.nativeimage.UnsupportedOSBuildItem;
import io.quarkus.deployment.pkg.NativeConfig;
import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem;
import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled;
import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabledBuildItem;
Expand Down Expand Up @@ -95,15 +96,16 @@ ReflectiveClassBuildItem setupReflectionClassesWithMethods() {
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
void setupAWTInit(BuildProducer<JniRuntimeAccessBuildItem> jc,
void setupAWTInit(NativeConfig nativeConfig,
BuildProducer<JniRuntimeAccessBuildItem> jc,
BuildProducer<JniRuntimeAccessMethodBuildItem> jm,
BuildProducer<JniRuntimeAccessFieldBuildItem> jf,
NativeImageRunnerBuildItem nativeImageRunnerBuildItem,
Optional<ProcessInheritIODisabled> processInheritIODisabled,
Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
nativeImageRunnerBuildItem.getBuildRunner()
.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion(nativeConfig);
// Dynamically loading shared objects instead
// of baking in static libs: https://github.com/oracle/graal/issues/4921
if (v.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) {
Expand All @@ -125,12 +127,13 @@ void setupAWTInit(BuildProducer<JniRuntimeAccessBuildItem> jc,
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
JniRuntimeAccessBuildItem setupJava2DClasses(NativeImageRunnerBuildItem nativeImageRunnerBuildItem,
JniRuntimeAccessBuildItem setupJava2DClasses(NativeConfig nativeConfig,
NativeImageRunnerBuildItem nativeImageRunnerBuildItem,
Optional<ProcessInheritIODisabled> processInheritIODisabled,
Optional<ProcessInheritIODisabledBuildItem> processInheritIODisabledBuildItem) {
nativeImageRunnerBuildItem.getBuildRunner()
.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion();
final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion(nativeConfig);
final List<String> classes = new ArrayList<>();
classes.add("com.sun.imageio.plugins.jpeg.JPEGImageReader");
classes.add("com.sun.imageio.plugins.jpeg.JPEGImageWriter");
Expand Down

0 comments on commit ecb4237

Please sign in to comment.