Skip to content

Commit

Permalink
Including opencv native libraries as a resource in enso runner binary (
Browse files Browse the repository at this point in the history
…#11807)

(cherry picked from commit e879a27)
  • Loading branch information
JaroslavTulach authored and jdunkerley committed Dec 10, 2024
1 parent 04b683b commit a41184d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3621,6 +3621,7 @@ lazy val `engine-runner` = project
).distinct
val stdLibsJars =
`base-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath()) ++
`image-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath()) ++
`table-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath())
core ++ stdLibsJars
},
Expand Down
8 changes: 7 additions & 1 deletion build/build/src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,13 @@ pub async fn runner_sanity_test(
.run_ok()
.await;

let all_cmds = test_base.and(test_internal_base).and(test_geo);
let test_image = Command::new(&enso)
.args(["--run", repo_root.test.join("Image_Tests").as_str()])
.set_env(ENSO_DATA_DIRECTORY, engine_package)?
.run_ok()
.await;

let all_cmds = test_base.and(test_internal_base).and(test_geo).and(test_image);

// The following test does not actually run anything, it just checks if the engine
// can accept `--jvm` argument and evaluates something.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeProxyCreation;
import org.graalvm.nativeimage.hosted.RuntimeReflection;
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess;

public final class EnsoLibraryFeature implements Feature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
try {
registerOpenCV(access.getApplicationClassLoader());
} catch (ReflectiveOperationException ex) {
ex.printStackTrace();
throw new IllegalStateException(ex);
}
var libs = new LinkedHashSet<Path>();
for (var p : access.getApplicationClassPath()) {
var p1 = p.getParent();
Expand Down Expand Up @@ -95,4 +102,34 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
}
System.err.println("Registered " + classes.size() + " classes for reflection");
}

private static void registerOpenCV(ClassLoader cl) throws ReflectiveOperationException {
var moduleOpenCV = cl.getUnnamedModule();
var currentOS = System.getProperty("os.name").toUpperCase().replaceAll(" .*$", "");

var libOpenCV =
switch (currentOS) {
case "LINUX" -> "nu/pattern/opencv/linux/x86_64/libopencv_java470.so";
case "WINDOWS" -> "nu/pattern/opencv/windows/x86_64/opencv_java470.dll";
case "MAC" -> {
var arch = System.getProperty("os.arch").toUpperCase();
yield switch (arch) {
case "X86_64" -> "nu/pattern/opencv/osx/x86_64/libopencv_java470.dylib";
case "AARCH64" -> "nu/pattern/opencv/osx/ARMv8/libopencv_java470.dylib";
default -> null;
};
}
default -> null;
};

if (libOpenCV != null) {
var verify = cl.getResource(libOpenCV);
if (verify == null) {
throw new IllegalStateException("Cannot find " + libOpenCV + " resource in " + cl);
}
RuntimeResourceAccess.addResource(moduleOpenCV, libOpenCV);
} else {
throw new IllegalStateException("No resource suggested for " + currentOS);
}
}
}

0 comments on commit a41184d

Please sign in to comment.