diff --git a/packages/graalvm-jvm/src/main/kotlin/elide/runtime/plugins/jvm/JvmConfig.kt b/packages/graalvm-jvm/src/main/kotlin/elide/runtime/plugins/jvm/JvmConfig.kt index 6f8c708a47..faf7c92321 100644 --- a/packages/graalvm-jvm/src/main/kotlin/elide/runtime/plugins/jvm/JvmConfig.kt +++ b/packages/graalvm-jvm/src/main/kotlin/elide/runtime/plugins/jvm/JvmConfig.kt @@ -34,6 +34,11 @@ import elide.runtime.plugins.AbstractLanguageConfig classpathEntries.addAll(paths) } + /** Add new entries to the guest classpath used by the engine. */ + public fun classpath(paths: Iterable) { + classpathEntries.addAll(paths) + } + /** Apply init-time settings to a new [context]. */ internal fun applyTo(context: PolyglotContext) { // register intrinsics diff --git a/packages/graalvm-kt/src/main/kotlin/elide/runtime/plugins/kotlin/Kotlin.kt b/packages/graalvm-kt/src/main/kotlin/elide/runtime/plugins/kotlin/Kotlin.kt index 834e4f3970..8cf597232f 100644 --- a/packages/graalvm-kt/src/main/kotlin/elide/runtime/plugins/kotlin/Kotlin.kt +++ b/packages/graalvm-kt/src/main/kotlin/elide/runtime/plugins/kotlin/Kotlin.kt @@ -14,50 +14,41 @@ package elide.runtime.plugins.kotlin import elide.runtime.core.DelicateElideApi -import elide.runtime.core.EngineLifecycleEvent.ContextCreated import elide.runtime.core.EnginePlugin.InstallationScope import elide.runtime.core.EnginePlugin.Key -import elide.runtime.core.PolyglotContext -import elide.runtime.core.PolyglotContextBuilder import elide.runtime.core.getOrInstall import elide.runtime.plugins.AbstractLanguagePlugin -import elide.runtime.plugins.AbstractLanguagePlugin.LanguagePluginManifest import elide.runtime.plugins.jvm.Jvm -@Suppress("unused") @DelicateElideApi public class Kotlin private constructor( - private val config: KotlinConfig, - private val resources: LanguagePluginManifest, -) { - private fun initializeContext(context: PolyglotContext) { - // apply init-time settings - config.applyTo(context) - - // run embedded initialization code - initializeEmbeddedScripts(context, resources) - } - - private fun configureContext(builder: PolyglotContextBuilder) { - // nothing to do here - } - +@DelicateElideApi public class Kotlin private constructor(public val config: KotlinConfig) { public companion object Plugin : AbstractLanguagePlugin() { + private const val GUEST_CLASSPATH_KEY = "classpath" + private const val KOTLIN_LANGUAGE_ID = "kt" private const val KOTLIN_PLUGIN_ID = "Kotlin" - + override val languageId: String = KOTLIN_LANGUAGE_ID override val key: Key = Key(KOTLIN_PLUGIN_ID) - + + private fun resolveGuestClasspathEntries(manifest: LanguagePluginManifest): List { + return manifest.resources[GUEST_CLASSPATH_KEY]?.map { + Kotlin::class.java.getResource("${manifest.root}/$it")?.toString() ?: error( + "Failed to resolve embedded classpath element: $it", + ) + } ?: emptyList() + } + override fun install(scope: InstallationScope, configuration: KotlinConfig.() -> Unit): Kotlin { - // apply the JVM plugin first - scope.configuration.getOrInstall(Jvm) - - // apply the configuration and create the plugin instance - val config = KotlinConfig().apply(configuration) val resources = resolveEmbeddedManifest(scope) - val instance = Kotlin(config, resources) - // subscribe to lifecycle events - scope.lifecycle.on(ContextCreated, instance::configureContext) + // apply the JVM plugin first, and register the custom classpath entries + scope.configuration.getOrInstall(Jvm).config.apply { + classpath(resolveGuestClasspathEntries(resources)) + } + + // apply the configuration and create the plugin instance + val config = KotlinConfig().apply(configuration) + val instance = Kotlin(config) // register resources with the VFS installEmbeddedBundles(scope, resources) diff --git a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/elide-kotlin-runtime.jar b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/elide-kotlin-runtime.jar new file mode 100644 index 0000000000..9ad8a5a36f Binary files /dev/null and b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/elide-kotlin-runtime.jar differ diff --git a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/kotlin-script-runtime-1.9.20-Beta2.jar b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/kotlin-script-runtime-1.9.20-Beta2.jar new file mode 100644 index 0000000000..646faac851 Binary files /dev/null and b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/kotlin-script-runtime-1.9.20-Beta2.jar differ diff --git a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/kotlin-stdlib-1.9.20-Beta2.jar b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/kotlin-stdlib-1.9.20-Beta2.jar new file mode 100644 index 0000000000..5e8f6dab4c Binary files /dev/null and b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/classpath/kotlin-stdlib-1.9.20-Beta2.jar differ diff --git a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.current.json b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.current.json index 954c001398..fc4d078d9c 100644 --- a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.current.json +++ b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.current.json @@ -1,4 +1,11 @@ { "engine": "v4", - "language": "Kotlin" + "language": "Kotlin", + "resources": { + "classpath": [ + "classpath/elide-kotlin-runtime.jar", + "classpath/kotlin-script-runtime-1.9.20-Beta2.jar", + "classpath/kotlin-stdlib-1.9.20-Beta2.jar" + ] + } } diff --git a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.json.gz b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.json.gz index d53ad73447..50c4ac08f0 100644 Binary files a/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.json.gz and b/packages/graalvm-kt/src/main/resources/META-INF/elide/embedded/runtime/kt/runtime.json.gz differ