Skip to content

Commit

Permalink
Packs libraries alongside executable in function.zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Karm committed Sep 4, 2023
1 parent fea2cef commit 190f57d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ private void handleAdditionalProperties(List<String> command) {
+ CONTAINER_BUILD_VOLUME_PATH + "/" + MOVED_TRUST_STORE_NAME);
} catch (IOException e) {
throw new UncheckedIOException("Unable to copy trustStore file '" + configuredTrustStorePath
+ "' to volume root directory '" + outputDir.toAbsolutePath().toString() + "'", e);
+ "' to volume root directory '" + outputDir.toAbsolutePath() + "'", e);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -21,8 +23,10 @@
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem;
import io.quarkus.deployment.pkg.steps.GraalVM;
import io.quarkus.deployment.pkg.steps.NativeBuild;

/**
Expand Down Expand Up @@ -106,7 +110,8 @@ public void jvmZip(OutputTargetBuildItem target,
public void nativeZip(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) throws Exception {
NativeImageBuildItem nativeImage,
NativeImageRunnerBuildItem nativeImageRunner) throws Exception {
Path zipDir = findNativeZipDir(target.getOutputDirectory());

Path zipPath = target.getOutputDirectory().resolve("function.zip");
Expand Down Expand Up @@ -137,8 +142,26 @@ public void nativeZip(OutputTargetBuildItem target,
}
}
addZipEntry(zip, nativeImage.getPath(), executableName, 0755);

final GraalVM.Version graalVMVersion = nativeImageRunner.getBuildRunner().getGraalVMVersion();
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(),
"*.{so,dll}")) {
sharedLibs.forEach(src -> {
try {
// In this use case, we can force all libs to be non-executable.
addZipEntry(zip, src, src.getFileName().toString(), 0644);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
log.errorf("Could not list files in directory %s. Continuing. Error: %s", nativeImage.getPath().getParent(),
e);
}
}
}
;
}

private void copyZipEntry(ZipArchiveOutputStream zip, InputStream zinput, ZipArchiveEntry from) throws Exception {
Expand Down

0 comments on commit 190f57d

Please sign in to comment.