Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ public abstract class AbstractStaticNativeLibraryFeature : NativeLibraryFeature
if (it.registerJni) (access as BeforeAnalysisAccessImpl).nativeLibraries.let { nativeLibraries ->
when (it.type) {
STATIC -> nativeLibraries.addStaticJniLibrary(it.name)
SHARED -> error("Dynamic native libraries not supported yet: $it")
SHARED -> if (it.registerJni) { /* Dynamic JNI libraries use JNI to load. */ } else {
nativeLibraries.addDynamicNonJniLibrary(it.name)
}
Comment on lines +174 to +176
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a point to having the empty if branch? why not invert the condition and keep the comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darvld good point -- should get compiled out since it.registerJni is known at compile time (this is all build time code anyway) but will catch in the next PR. there is going to be logic in that other branch eventually, i think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the compiler will optimize it out, I was just checking if you had forgotten to add some logic there 👍

}
}
if (it.eager) {
Expand Down
14 changes: 12 additions & 2 deletions packages/runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ val enablePgo = false
val enablePgoSampling = false
val enablePgoInstrumentation = false
val enablePgoReport = true
val enableJna = false
val enableJna = true
val enableSbom = oracleGvm
val enableSbomStrict = false
val glibcTarget = "glibc"
Expand Down Expand Up @@ -649,7 +649,7 @@ val commonNativeArgs = listOfNotNull(
"--install-exit-handlers",
"--enable-url-protocols=jar",
"--macro:truffle-svm",
"--enable-native-access=ALL-UNNAMED",
"--enable-native-access=com.sun.jna,ALL-UNNAMED",
"-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED",
"-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.hosted=ALL-UNNAMED",
"-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c=ALL-UNNAMED",
Expand All @@ -668,6 +668,10 @@ val commonNativeArgs = listOfNotNull(
"-J-Delide.staticJni=$enableStaticJni",
"-Delide.natives=$nativesPath",
"-J-Delide.natives=$nativesPath",
"-Djna.library.path=$nativesPath",
"-J-Djna.library.path=$nativesPath",
"-Djna.boot.library.path=$nativesPath",
"-J-Djna.boot.library.path=$nativesPath",
"-Dorg.sqlite.lib.path=$nativesPath",
"-J-Dorg.sqlite.lib.path=$nativesPath",
"-Dorg.sqlite.lib.exportPath=$nativesPath",
Expand Down Expand Up @@ -799,6 +803,8 @@ val releaseFlags: List<String> = listOf(

val jvmDefs = mapOf(
"elide.natives" to nativesPath,
"jna.library.path" to nativesPath,
"jna.boot.library.path" to nativesPath,
"elide.nativeTransport.v2" to enableNativeTransportV2.toString(),
"io.netty.allocator.type" to "unpooled",
"io.netty.native.deleteLibAfterLoading" to "false",
Expand Down Expand Up @@ -857,10 +863,12 @@ val initializeAtRuntime: List<String> = listOfNotNull(

// --- JNA -----

"com.sun.jna.Native",
"com.sun.jna.Structure${'$'}FFIType",
"com.sun.jna.platform.mac.IOKit",
"com.sun.jna.platform.mac.IOKitUtil",
"com.sun.jna.platform.mac.SystemB",
"com.sun.jna.platform.linux.Udev",

// --- JLine -----

Expand All @@ -886,6 +894,8 @@ val initializeAtRuntime: List<String> = listOfNotNull(
"oshi.jna.platform.mac.IOKit",
"oshi.jna.platform.mac.SystemB",
"oshi.jna.platform.mac.SystemConfiguration",
"oshi.jna.platform.linux.LinuxLibc",
"com.sun.jna.platform.linux.LibC",
"oshi.software.os",
"oshi.software.os.linux",
"oshi.software.os.linux.LinuxOperatingSystem",
Expand Down
5 changes: 1 addition & 4 deletions packages/runtime/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ID>CyclomaticComplexMethod:ToolShellCommand.kt$ToolShellCommand$override fun PolyglotEngineConfiguration.configureEngine()</ID>
<ID>CyclomaticComplexMethod:ToolShellCommand.kt$ToolShellCommand$override suspend fun CommandContext.invoke(state: ToolContext&lt;ToolState>): CommandResult</ID>
<ID>CyclomaticComplexMethod:ToolShellCommand.kt$ToolShellCommand$private fun beginInteractiveSession( languages: EnumSet&lt;GuestLanguage>, primaryLanguage: GuestLanguage, engine: PolyglotEngine, ctx: PolyglotContext, )</ID>
<ID>CyclomaticComplexMethod:ToolShellCommand.kt$ToolShellCommand$private fun displayFormattedError( exc: Throwable, message: String, advice: String? = null, internal: Boolean = false, stacktrace: Boolean = internal, )</ID>
<ID>CyclomaticComplexMethod:ToolShellCommand.kt$ToolShellCommand$private fun displayFormattedError( exc: Throwable, message: String, advice: String? = null, internal: Boolean = false, stacktrace: Boolean = internal, withCause: Boolean = true, )</ID>
<ID>FunctionParameterNaming:Statics.kt$Statics$`in`: InputStream</ID>
<ID>LargeClass:ToolShellCommand.kt$ToolShellCommand : AbstractSubcommand</ID>
<ID>LoopWithTooManyJumpStatements:ToolShellCommand.kt$ToolShellCommand$while</ID>
Expand All @@ -29,12 +29,9 @@
<ID>NestedBlockDepth:SelfTestCommand.kt$SelfTestCommand$override suspend fun CommandContext.invoke(state: ToolContext&lt;ToolState>): CommandResult</ID>
<ID>ObjectPropertyNaming:Statics.kt$Statics$val `in`: InputStream get() = delegatedInStream.get() ?: System.`in`</ID>
<ID>ReturnCount:ExecutionController.kt$ExecutionController$private fun toHost(polyglotException: PolyglotException): Throwable</ID>
<ID>ReturnCount:NativeSQLiteFeature.kt$NativeSQLiteFeature$override fun unpackNatives(access: BeforeAnalysisAccess): List&lt;UnpackedNative></ID>
<ID>ReturnCount:NativeUtil.kt$NativeUtil$@JvmStatic internal fun loadOrCopy( workdir: File, path: String, libName: String, loader: ClassLoader, forceCopy: Boolean = false, forceLoad: Boolean = false, loadFromPath: Boolean = true, ): Pair&lt;Boolean, Boolean></ID>
<ID>ReturnCount:RuntimeWorkdirManager.kt$RuntimeWorkdirManager$private fun nearestDirectoryWithAnyOfTheseFiles( files: SortedSet&lt;String>, base: File? = null, depth: Int? = null, ): File?</ID>
<ID>SpreadOperator:Elide.kt$Elide.Companion$(*args)</ID>
<ID>SpreadOperator:NativeSQLiteFeature.kt$NativeSQLiteFeature$(*fields( NativeDB::class.java, "pointer", "busyHandler", "commitListener", "updateListener", "progressHandler", ))</ID>
<ID>SpreadOperator:NativeSQLiteFeature.kt$NativeSQLiteFeature$(*this.fields(Function::class.java, "context", "value", "args"))</ID>
<ID>SwallowedException:DefaultProjectManager.kt$DefaultProjectManager.Companion$ioe: IOException</ID>
<ID>SwallowedException:DefaultProjectManager.kt$DefaultProjectManager.Companion$thr: Throwable</ID>
<ID>SwallowedException:Elide.kt$Elide.Companion$uoe: UnsupportedOperationException</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,10 +1107,11 @@ import elide.tool.project.ProjectManager
advice: String? = null,
internal: Boolean = false,
stacktrace: Boolean = internal,
withCause: Boolean = true,
) {
if (exc !is PolyglotException) return
val term = terminal.get()
val reader = lineReader.get()
if (exc !is PolyglotException) return

// begin calculating with source context
val middlePrefix = "║ "
Expand Down Expand Up @@ -1146,6 +1147,16 @@ import elide.tool.project.ProjectManager
val stackString = StringWriter()
val stackPrinter = PrintWriter(stackString)
exc.printStackTrace(stackPrinter)
when (val cause = exc.cause ?: if (exc.isHostException) exc.asHostException() else null) {
null -> {}
else -> if (withCause) {
stackString.append("\nCause stacktrace: ")
cause.printStackTrace(stackPrinter)
} else if (exc.isHostException) {
stackString.append("\nCause: ${cause.message}")
stackString.append(" Failed to gather stacktrace for host exception of type ${cause::class.simpleName}.")
}
}
stackPrinter.flush()
stackString.toString()
} else {
Expand Down Expand Up @@ -1275,7 +1286,7 @@ import elide.tool.project.ProjectManager

exc.isHostException || exc.message?.contains("HostException: ") == true -> displayFormattedError(
exc,
exc.message ?: "An runtime error was thrown",
exc.message ?: "A runtime error was thrown",
advice = "This is an error in Elide. Please report this to the Elide Team with `elide bug`",
stacktrace = true,
internal = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@
"allPublicMethods":true,
"allDeclaredConstructors":true,
"allPublicConstructors":true,
"methods":[{"name":"dispose","parameterTypes":[] }, {"name":"fromNative","parameterTypes":["com.sun.jna.FromNativeConverter","java.lang.Object","java.lang.reflect.Method"] }, {"name":"fromNative","parameterTypes":["java.lang.Class","java.lang.Object"] }, {"name":"fromNative","parameterTypes":["java.lang.reflect.Method","java.lang.Object"] }, {"name":"nativeType","parameterTypes":["java.lang.Class"] }, {"name":"toNative","parameterTypes":["com.sun.jna.ToNativeConverter","java.lang.Object"] }]
"methods":[
{"name":"dispose","parameterTypes":[] },
{"name":"fromNative","parameterTypes":["com.sun.jna.FromNativeConverter","java.lang.Object","java.lang.reflect.Method"] },
{"name":"fromNative","parameterTypes":["java.lang.Class","java.lang.Object"] },
{"name":"fromNative","parameterTypes":["java.lang.reflect.Method","java.lang.Object"] },
{"name":"nativeType","parameterTypes":["java.lang.Class"] },
{"name":"toNative","parameterTypes":["com.sun.jna.ToNativeConverter","java.lang.Object"]},
{"name":"open","parameterTypes":["java.lang.String","java.lang.Integer"]},
{"name":"close","parameterTypes":["java.lang.Long"]},
{"name":"findSymbol","parameterTypes":["java.lang.Long","java.lang.String"]}
]
},
{
"name":"com.sun.jna.Native$ffi_callback",
Expand Down Expand Up @@ -159,6 +169,13 @@
"allDeclaredConstructors":true,
"allPublicConstructors":true
},
{
"name":"com.sun.jna.platform.mac.CoreFoundation$CFStringRef",
"allDeclaredMethods":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
"allPublicConstructors":true
},
{
"name":"com.sun.management.internal.DiagnosticCommandArgumentInfo",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","java.lang.String","java.lang.String","java.lang.String","boolean","boolean","boolean","int"] }]
Expand Down Expand Up @@ -405,6 +422,10 @@
"name":"java.lang.Throwable",
"methods":[{"name":"toString","parameterTypes":[] }]
},
{
"name":"java.lang.UnsatisfiedLinkError",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.Void",
"allDeclaredMethods":true,
Expand Down Expand Up @@ -557,4 +578,4 @@
"name":"sun.nio.ch.FileChannelImpl",
"fields":[{"name":"fd"}]
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@
{
"interfaces":["com.github.ajalt.mordant.internal.jna.MacosLibC"]
},
{
"interfaces":["com.github.ajalt.mordant.internal.jna.PosixLibC"]
},
{
"interfaces":["com.sun.jna.Callback"]
},
{
"interfaces":["com.sun.jna.Library"]
},
{
"interfaces":["com.sun.jna.platform.linux.Udev"]
},
{
"interfaces":["oshi.jna.platform.linux.LinuxLibc"]
},
{
"interfaces":["com.sun.jna.platform.mac.SystemB"]
},
{
"interfaces":["oshi.jna.platform.mac.SystemB"]
},
{
"interfaces":["com.sun.jna.platform.mac.IOKit"]
},
{
"interfaces":["com.sun.jna.platform.mac.CoreFoundation"]
}
]
]
Loading