mirror of
https://github.com/enso-org/enso.git
synced 2024-12-18 19:41:32 +03:00
Including opencv native libraries as a resource in enso runner binary (#11807)
This commit is contained in:
parent
3ad09a1537
commit
e879a274fd
@ -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
|
||||
},
|
||||
|
@ -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.
|
||||
|
@ -12,10 +12,17 @@ import org.enso.pkg.PackageManager$;
|
||||
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();
|
||||
@ -95,4 +102,34 @@ public final class EnsoLibraryFeature implements Feature {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user