-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Native libraries are searched in lib/polyglot project dir (#11874)
* Update java.md docs * Add docs * Separate instance of HostClassLoader per project * Insert default HostClassLoader for builtin lib * Revert "Insert default HostClassLoader for builtin lib" This reverts commit 84be175. * Revert "Separate instance of HostClassLoader per project" This reverts commit c98bdaf. * Add NativeLibraryFinder * OpenCV native lib is not copied to a temporary directory, but loaded from a dll * std-image/compile does not copy opencv.jar * Add JARUtils to sbt project * Add *.dylib to gitignore * Add error recovery to JARUtils * std-image/compile extract native libraries from OpenCV.jar * fmt * JAR extraction uses sbt cache. So that no extraction is done unnecessarily. * Move extractNativeLibs task to StdBits * NativeLibraryFinder strips version from os.arch * fmt * NativeLibFinder simplifies os name * Extracted native lib dir conforms to the hierarchy naming convention * Move NativeLibraryFinder to pkg and make it generic. * Package has nativeLibraryDir method * Fix typo in NativeLibraryFinder * Fix path to nativeLibDir in pkg * Fix build * Add NativeLibraryFinder.listAllNativeLibraries * Gather native libraries in EnsoLibraryFeature * Stack of exception in EnsoLibraryFeature is printed to System.err. The current printing is not visible on CI * Update docs * Update docs * Add unit test for searching native lib * Add printing system info to NativeLibraryFinderTest * Always replace x86_64 by amd64 * Add list of supported names in docs * Update changelog * fmt docs * EnsoLibraryFeature copies native libs next to the generated binary * Flatten hierarchy of native libs in opencv * native libs must have the correct platform-specific suffix --------- Co-authored-by: Jaroslav Tulach <[email protected]>
- Loading branch information
1 parent
b759d75
commit 7658faf
Showing
19 changed files
with
577 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,7 @@ bench-report*.xml | |
/enso.lib | ||
|
||
*.dll | ||
*.dylib | ||
*.exe | ||
*.pdb | ||
*.so | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...me-integration-tests/src/test/java/org/enso/interpreter/test/NativeLibraryFinderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.enso.interpreter.test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import com.oracle.truffle.api.TruffleFile; | ||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.enso.editions.LibraryName; | ||
import org.enso.interpreter.runtime.util.TruffleFileSystem; | ||
import org.enso.pkg.NativeLibraryFinder; | ||
import org.enso.pkg.Package; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
public class NativeLibraryFinderTest { | ||
|
||
@Rule public final TestRule printContextRule = new PrintSystemInfoRule(); | ||
private Package<TruffleFile> stdImgPkg; | ||
|
||
@Test | ||
public void standardImageShouldHaveNativeLib() { | ||
try (var ctx = ContextUtils.createDefaultContext()) { | ||
// Evaluate dummy sources to force loading Standard.Image | ||
ContextUtils.evalModule( | ||
ctx, """ | ||
from Standard.Image import all | ||
main = 42 | ||
"""); | ||
var ensoCtx = ContextUtils.leakContext(ctx); | ||
var stdImg = | ||
ensoCtx | ||
.getPackageRepository() | ||
.getPackageForLibraryJava(LibraryName.apply("Standard", "Image")); | ||
assertThat(stdImg.isPresent(), is(true)); | ||
this.stdImgPkg = stdImg.get(); | ||
var nativeLibs = | ||
NativeLibraryFinder.listAllNativeLibraries(stdImg.get(), TruffleFileSystem.INSTANCE); | ||
assertThat( | ||
"There should be just single native lib in Standard.Image", nativeLibs.size(), is(1)); | ||
} | ||
} | ||
|
||
public final class PrintSystemInfoRule implements TestRule { | ||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() { | ||
try { | ||
base.evaluate(); | ||
} catch (Throwable e) { | ||
var sb = new StringBuilder(); | ||
sb.append(System.lineSeparator()); | ||
sb.append(" os.name: ") | ||
.append(System.getProperty("os.name")) | ||
.append(System.lineSeparator()); | ||
sb.append(" os.arch: ") | ||
.append(System.getProperty("os.arch")) | ||
.append(System.lineSeparator()); | ||
var mappedLibName = System.mapLibraryName("opencv_java470"); | ||
sb.append(" Mapped library name: ") | ||
.append(mappedLibName) | ||
.append(System.lineSeparator()); | ||
if (stdImgPkg != null) { | ||
sb.append(" Contents of Standard.Image native library dir:") | ||
.append(System.lineSeparator()); | ||
var nativeLibDir = stdImgPkg.nativeLibraryDir(); | ||
var nativeLibPath = Path.of(nativeLibDir.getAbsoluteFile().getPath()); | ||
var contents = contentsOfDir(nativeLibPath); | ||
contents.forEach( | ||
path -> sb.append(" ").append(path).append(System.lineSeparator())); | ||
} | ||
throw new AssertionError(sb.toString(), e); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
private static List<String> contentsOfDir(Path dir) { | ||
var contents = new ArrayList<String>(); | ||
var fileVisitor = | ||
new SimpleFileVisitor<Path>() { | ||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { | ||
contents.add(file.toAbsolutePath().toString()); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
}; | ||
try { | ||
Files.walkFileTree(dir, fileVisitor); | ||
} catch (IOException e) { | ||
throw new AssertionError(e); | ||
} | ||
return contents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.