Skip to content

Commit

Permalink
Merge pull request quarkusio#33368 from zakkak/2023-05-15-fix-33161
Browse files Browse the repository at this point in the history
Do not attempt to detect container runtime in native-sources build
  • Loading branch information
gsmet authored May 17, 2023
2 parents f6cf227 + 4bd0553 commit aad9ce5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private String getResultingExecutableName(String nativeImageName, boolean isCont
/**
* Resolves the runner factory. Happens quite early, *before* the build.
*/
@BuildStep
@BuildStep(onlyIf = NativeBuild.class)
public NativeImageRunnerBuildItem resolveNativeImageBuildRunner(NativeConfig nativeConfig) {
boolean isExplicitContainerBuild = nativeConfig.containerBuild()
.orElse(nativeConfig.containerRuntime().isPresent() || nativeConfig.remoteContainerBuild());
Expand All @@ -353,6 +353,16 @@ public NativeImageRunnerBuildItem resolveNativeImageBuildRunner(NativeConfig nat
return new NativeImageRunnerBuildItem(new NativeImageBuildLocalContainerRunner(nativeConfig));
}

/**
* Creates a dummy runner for native-sources builds. This allows the creation of native-source jars without
* requiring podman/docker or a local native-image installation.
*/
@BuildStep(onlyIf = NativeSourcesBuild.class)
public NativeImageRunnerBuildItem dummyNativeImageBuildRunner(NativeConfig nativeConfig) {
boolean explicitContainerBuild = nativeConfig.isExplicitContainerBuild();
return new NativeImageRunnerBuildItem(new NoopNativeImageBuildRunner(explicitContainerBuild));
}

private void copyJarSourcesToLib(OutputTargetBuildItem outputTargetBuildItem,
CurateOutcomeBuildItem curateOutcomeBuildItem) {
Path targetDirectory = outputTargetBuildItem.getOutputDirectory()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.deployment.pkg.steps;

import java.nio.file.Path;
import java.util.List;

public class NoopNativeImageBuildRunner extends NativeImageBuildRunner {

private static final String MESSAGE = "NoopNativeImageBuildRunner is not meant to be used to perform an actual build.";
private final boolean isContainer;

public NoopNativeImageBuildRunner(boolean isContainer) {
this.isContainer = isContainer;
}

@Override
public boolean isContainer() {
return isContainer;
}

@Override
protected String[] getGraalVMVersionCommand(List<String> args) {
throw new UnsupportedOperationException(MESSAGE);
}

@Override
protected String[] getBuildCommand(Path outputDir, List<String> args) {
throw new UnsupportedOperationException(MESSAGE);
}

@Override
protected void objcopy(Path outputDir, String... args) {
throw new UnsupportedOperationException(MESSAGE);
}
}
5 changes: 3 additions & 2 deletions docs/src/main/asciidoc/building-native-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,11 @@ $ ./mvnw clean package -Dquarkus.package.type=native-sources -Dquarkus.native.co
cd target/native-sources
docker run \
-it \
--user $(id -ur):$(id -gr) \
--rm \
--v $(pwd):/work \# <1>
-v $(pwd):/work \# <1>
-w /work \# <2>
--entrypoint bin/sh \
--entrypoint /bin/sh \
$(cat native-builder.image) \# <3>
-c "native-image $(cat native-image.args) -J-Xmx4g"# <4>
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.kafka.streams.runtime.KafkaStreamsProducer;
import io.quarkus.kafka.streams.runtime.KafkaStreamsRecorder;
import io.quarkus.kafka.streams.runtime.KafkaStreamsRuntimeConfig;
Expand All @@ -42,7 +43,7 @@ class KafkaStreamsProcessor {

public static final String DEFAULT_PARTITION_GROUPER = "org.apache.kafka.streams.processor.DefaultPartitionGrouper";

@BuildStep
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
void build(BuildProducer<FeatureBuildItem> feature,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<JniRuntimeAccessBuildItem> jniRuntimeAccessibleClasses,
Expand Down

0 comments on commit aad9ce5

Please sign in to comment.