diff --git a/.github/workflows/job.test.yml b/.github/workflows/job.test.yml index c078ce3f9..ca23c0f12 100644 --- a/.github/workflows/job.test.yml +++ b/.github/workflows/job.test.yml @@ -273,16 +273,16 @@ jobs: koverXmlReport koverBinaryReport koverVerify - -x wasmJsTest - -x wasmWasiTest - -x wasmWasiNodeTest - -x detekt + detekt --scan --build-cache --no-daemon --warning-mode=none --dependency-verification=lenient -x apiCheck + -x wasmJsTest + -x wasmWasiTest + -x wasmWasiNodeTest -Pelide.ci=true -PbuildSamples=false -PbuildDocs=false @@ -309,18 +309,16 @@ jobs: wrapper yarn arguments: | - detekt sonar - -x wasmJsTest - -x wasmWasiTest - -x wasmWasiNodeTest - -x detekt --scan --build-cache --no-daemon --warning-mode=none --dependency-verification=lenient -x apiCheck + -x wasmJsTest + -x wasmWasiTest + -x wasmWasiNodeTest -Pelide.ci=true -PbuildSamples=false -PbuildDocs=false diff --git a/gradle.properties b/gradle.properties index 5214330db..56e671063 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ elide.pluginMode = inert elide.stamp = false elide.atomicFu = true elide.lockDeps = false -elide.graalvm.variant = ENTERPRISE +elide.graalvm.variant = COMMUNITY elide.vm.inspect = false elide.kotlin.k2 = true publishMainHostLock = false diff --git a/gradle/elide.versions.toml b/gradle/elide.versions.toml index 503337f82..93a14f97f 100644 --- a/gradle/elide.versions.toml +++ b/gradle/elide.versions.toml @@ -835,4 +835,6 @@ graalvm-python = ["graalvm-polyglot-python", "graalvm-python-resources"] graalvm-ruby = ["graalvm-ruby-annotations", "graalvm-ruby-language", "graalvm-ruby-resources"] -graalvm-js = ["graalvm-js-isolate", "graalvm-js-language", "graalvm-polyglot-js", "graalvm-polyglot-js-isolate"] +graalvm-js = ["graalvm-js-language", "graalvm-polyglot-js"] + +graalvm-js-isolate = ["graalvm-js-isolate", "graalvm-polyglot-js-isolate"] diff --git a/packages/cli/build.gradle.kts b/packages/cli/build.gradle.kts index 6b5e20ca3..b036528bb 100644 --- a/packages/cli/build.gradle.kts +++ b/packages/cli/build.gradle.kts @@ -94,20 +94,20 @@ val isRelease = !quickbuild && ( val entrypoint = "elide.tool.cli.ElideTool" -val oracleGvm = true +val oracleGvm = false val enableEdge = true val enableWasm = true -val enablePython = true -val enableRuby = true -val enableTools = true +val enablePython = false +val enableRuby = false +val enableTools = false val enableMosaic = true val enableProguard = false val enableLlvm = false -val enableEspresso = true +val enableEspresso = false val enableExperimental = false val enableEmbeddedResources = false -val enableResourceFilter = true -val enableAuxCache = true +val enableResourceFilter = false +val enableAuxCache = false val enableJpms = false val enableEmbeddedBuilder = false val enableDashboard = false @@ -122,7 +122,6 @@ val enableSbomStrict = false val enableTruffleJson = enableEdge val encloseSdk = !System.getProperty("java.vm.version").contains("jvmci") val globalExclusions = emptyList>() - val moduleExclusions = listOf( "io.micronaut" to "micronaut-core-processor", ) @@ -147,6 +146,7 @@ buildscript { } // @TODO(sgammon): mosaic is broken on kotlin v2 + if (enableMosaic) apply(plugin = "com.jakewharton.mosaic") val nativesRootTemplate: (String) -> String = { version -> @@ -219,19 +219,6 @@ java { if (enableJpms) modularity.inferModulePath = true } -//ktlint { -// debug = false -// verbose = false -// android = false -// outputToConsole = false -// ignoreFailures = true -// enableExperimentalRules = true -// -// filter { -// exclude("elide/tool/cli/ToolTypealiases.kt") -// } -//} - kapt { useBuildCache = true includeCompileClasspath = false @@ -242,7 +229,7 @@ kapt { kotlin { target.compilations.all { kotlinOptions { - allWarningsAsErrors = true + allWarningsAsErrors = false freeCompilerArgs = freeCompilerArgs.plus(ktCompilerArgs).toSortedSet().toList() // @TODO(sgammon): v2.0 support in this package (currently breaks mosaic) @@ -291,6 +278,10 @@ val classpathExtras: Configuration by configurations.creating { dependencies { implementation(platform(libs.netty.bom)) + // Fix: Missing Types + implementation(libs.jetty.npn) + implementation(libs.jetty.alpn) + kapt(mn.micronaut.inject.java) kapt(libs.picocli.codegen) classpathExtras(mn.micronaut.core.processor) @@ -351,6 +342,7 @@ dependencies { implementation(libs.jline.console) implementation(libs.jline.terminal.core) implementation(libs.jline.terminal.jansi) + implementation(libs.jline.terminal.jna) implementation(libs.jline.builtins) implementation(libs.jline.graal) { exclude(group = "org.slf4j", module = "slf4j-jdk14") @@ -443,17 +435,7 @@ dependencies { api(libs.graalvm.polyglot) api(libs.graalvm.js.language) - api(libs.bundles.graalvm.tools) - api(libs.graalvm.regex) - compileOnly(libs.graalvm.svm) - - if (enableEspresso) { - api(libs.bundles.graalvm.espresso) - } - - api(libs.graalvm.truffle.nfi) - api(libs.graalvm.truffle.nfi.libffi) -// api(libs.graalvm.truffle.nfi.panama) + api(libs.graalvm.truffle.api) runtimeOnly(mn.micronaut.runtime) testImplementation(kotlin("test")) @@ -646,10 +628,12 @@ tasks.withType(Test::class).configureEach { * Build: CLI Native Image */ -val commonGvmArgs = listOf( - "-H:+UseCompressedReferences", +val commonGvmArgs = listOfNotNull( + if (!oracleGvm) null else "-H:+UseCompressedReferences", ).plus(if (enableBuildReport) listOf("-H:+BuildReport") else emptyList()) +val nativeImageBuildDebug = properties["nativeImageBuildDebug"] == "true" + val commonNativeArgs = listOfNotNull( "--no-fallback", "--enable-preview", @@ -665,7 +649,6 @@ val commonNativeArgs = listOfNotNull( "-H:+AddAllCharsets", "-H:DeadlockWatchdogInterval=15", "-H:CLibraryPath=$nativesPath", - "--trace-object-instantiation=java.nio.DirectByteBuffer", if (enableEspresso) "-H:+AllowJRTFileSystem" else null, if (enableEspresso) "-J-Djdk.image.use.jvm.map=false" else null, if (enableEspresso) "-J-Despresso.finalization.UnsafeOverride=true" else null, @@ -686,6 +669,8 @@ val commonNativeArgs = listOfNotNull( if (oracleGvm) commonGvmArgs else emptyList() ).plus(if (enableStrictHeap) listOf( "--strict-image-heap", +) else emptyList()).plus(if (nativeImageBuildDebug) listOf( + "--debug-attach", ) else emptyList()).toList() val dashboardFlags: List = listOf( @@ -772,7 +757,7 @@ val releaseFlags: List = listOf( "--pgo=${profiles.joinToString(",")}", "-H:CodeSectionLayoutOptimization=ClusterByEdges", ) else emptyList()).plus(listOf( - if (enableSbom) listOf( + if (oracleGvm && enableSbom) listOf( if (enableSbomStrict) "--enable-sbom=cyclonedx,export,strict" else "--enable-sbom=cyclonedx,export" ) else emptyList(), if (enableDashboard) dashboardFlags else emptyList(), @@ -870,37 +855,12 @@ val initializeAtBuildTime = listOf( "com.google.common.collect.MapMakerInternalMap${'$'}1", "com.google.common.base.Equivalence${'$'}Equals", - // SLF4J + Logback - "ch.qos.logback", - "org.slf4j.MarkerFactory", - "org.slf4j.simple.SimpleLogger", - "org.slf4j.impl.StaticLoggerBinder", - - // Encodings, Parsers, Cryptography - "com.sun.tools.doclint", - "org.codehaus.stax2.typed.Base64Variants", - "org.bouncycastle.util.Properties", - "org.bouncycastle.util.Strings", - "org.bouncycastle.crypto.macs.HMac", - "org.bouncycastle.crypto.prng.drbg.Utils", - "org.bouncycastle.jcajce.provider.drbg.DRBG", - "org.bouncycastle.jcajce.provider.drbg.EntropyDaemon", - "org.xml.sax.helpers.LocatorImpl", - "org.xml.sax.helpers.AttributesImpl", - "jdk.jshell.Snippet${'$'}SubKind", - "com.sun.tools.javac.parser.Tokens${'$'}TokenKind", - // Databasing "org.sqlite.util.ProcessRunner", - // Micronaut - "io.micronaut.http.util.HttpTypeInformationProvider", - "io.micronaut.inject.provider.ProviderTypeInformationProvider", - "io.micronaut.core.async.ReactiveStreamsTypeInformationProvider", - "io.micronaut.inject.beans.visitor.MapperAnnotationMapper", - "io.micronaut.inject.beans.visitor.JsonCreatorAnnotationMapper", - "io.micronaut.inject.beans.visitor.IntrospectedToBeanPropertiesTransformer", - "io.micronaut.inject.beans.visitor.persistence.JakartaMappedSuperClassIntrospectionMapper", + // Logging + "ch.qos.logback", + "org.slf4j.MarkerFactory", // --- Netty ------ @@ -1100,10 +1060,13 @@ val defaultPlatformArgs = listOf( val windowsOnlyArgs = defaultPlatformArgs.plus(listOf( "-march=native", "--gc=serial", - "-Delide.vm.engine.preinitialize=true", "-H:InitialCollectionPolicy=Adaptive", "-R:MaximumHeapSizePercent=80", -).plus(if (project.properties["elide.ci"] == "true") listOf( +).plus(if (oracleGvm) listOf( + "-Delide.vm.engine.preinitialize=true", +) else listOf( + "-Delide.vm.engine.preinitialize=false", +)).plus(if (project.properties["elide.ci"] == "true") listOf( "-J-Xmx12g", ) else emptyList())).plus(if (oracleGvm && enableAuxCache) listOf( "-H:-AuxiliaryEngineCache", @@ -1112,10 +1075,13 @@ val windowsOnlyArgs = defaultPlatformArgs.plus(listOf( val darwinOnlyArgs = defaultPlatformArgs.plus(listOf( "-march=native", "--gc=serial", - "-Delide.vm.engine.preinitialize=true", "-H:InitialCollectionPolicy=Adaptive", "-R:MaximumHeapSizePercent=80", -).plus(if (project.properties["elide.ci"] == "true") listOf( +).plus(if (oracleGvm) listOf( + "-Delide.vm.engine.preinitialize=true", +) else listOf( + "-Delide.vm.engine.preinitialize=false", +)).plus(if (project.properties["elide.ci"] == "true") listOf( "-J-Xmx12g", ) else listOf( "-J-Xmx24g", @@ -1162,11 +1128,11 @@ val linuxOnlyArgs = defaultPlatformArgs.plus( "-Delide.vm.engine.preinitialize=false", ) else listOf( "--gc=serial", - "-Delide.vm.engine.preinitialize=true", "-R:MaximumHeapSizePercent=80", "-H:InitialCollectionPolicy=Adaptive", ).plus(if (oracleGvm && enableAuxCache) listOf( "-H:+AuxiliaryEngineCache", + "-Delide.vm.engine.preinitialize=true", ) else emptyList()) ).plus(if (project.properties["elide.ci"] == "true") listOf( "-J-Xmx12g", @@ -1191,8 +1157,6 @@ val muslArgs = listOf( val testOnlyArgs: List = emptyList() -val isEnterprise: Boolean = properties["elide.graalvm.variant"] == "ENTERPRISE" - fun nativeCliImageArgs( platform: String = "generic", target: String = "glibc", diff --git a/packages/cli/src/main/kotlin/elide/tool/cli/cmd/repl/ToolShellCommand.kt b/packages/cli/src/main/kotlin/elide/tool/cli/cmd/repl/ToolShellCommand.kt index 2f1fbf1a8..e8bfb0046 100644 --- a/packages/cli/src/main/kotlin/elide/tool/cli/cmd/repl/ToolShellCommand.kt +++ b/packages/cli/src/main/kotlin/elide/tool/cli/cmd/repl/ToolShellCommand.kt @@ -1442,6 +1442,7 @@ import elide.tool.project.ProjectManager } // Resolve the primary interactive language for the provided `file`. + @Suppress("UNUSED_VARIABLE") private fun primaryFromFile(file: File): GuestLanguage? { return when (val engine = scriptEngineManager.getEngineByExtension(file.extension)) { null -> null @@ -1546,40 +1547,40 @@ import elide.tool.project.ProjectManager jsSettings.apply(this) } - PYTHON -> install(elide.runtime.plugins.python.Python) { - logging.debug("Configuring Python VM") - installIntrinsics(intrinsics, GraalVMGuest.PYTHON, versionProp) - } - - RUBY -> install(elide.runtime.plugins.ruby.Ruby) { - logging.debug("Configuring Ruby VM") - installIntrinsics(intrinsics, GraalVMGuest.RUBY, versionProp) - } - - // Secondary Engines: JVM - JVM -> { - install(elide.runtime.plugins.jvm.Jvm) { - logging.debug("Configuring JVM") - multithreading = false - } - - install(elide.runtime.plugins.java.Java) { - logging.debug("Configuring Java") - } - } - - GROOVY -> logging.warn("Groovy runtime plugin is not yet implemented") - - KOTLIN -> install(elide.runtime.plugins.kotlin.Kotlin) { - val classpathDir = workdir.cacheDirectory() - .resolve("elide-kotlin-runtime") - .absolutePath - - logging.debug("Configuring Kotlin with classpath root $classpathDir") - guestClasspathRoot = classpathDir - } - - SCALA -> logging.warn("Scala runtime plugin is not yet implemented") +// PYTHON -> install(elide.runtime.plugins.python.Python) { +// logging.debug("Configuring Python VM") +// installIntrinsics(intrinsics, GraalVMGuest.PYTHON, versionProp) +// } + +// RUBY -> install(elide.runtime.plugins.ruby.Ruby) { +// logging.debug("Configuring Ruby VM") +// installIntrinsics(intrinsics, GraalVMGuest.RUBY, versionProp) +// } + +// // Secondary Engines: JVM +// JVM -> { +// install(elide.runtime.plugins.jvm.Jvm) { +// logging.debug("Configuring JVM") +// multithreading = false +// } +// +// install(elide.runtime.plugins.java.Java) { +// logging.debug("Configuring Java") +// } +// } +// +// GROOVY -> logging.warn("Groovy runtime plugin is not yet implemented") +// +// KOTLIN -> install(elide.runtime.plugins.kotlin.Kotlin) { +// val classpathDir = workdir.cacheDirectory() +// .resolve("elide-kotlin-runtime") +// .absolutePath +// +// logging.debug("Configuring Kotlin with classpath root $classpathDir") +// guestClasspathRoot = classpathDir +// } +// +// SCALA -> logging.warn("Scala runtime plugin is not yet implemented") else -> {} } } diff --git a/packages/cli/src/main/kotlin/elide/tool/control/AbstractScriptEngineFactory.kt b/packages/cli/src/main/kotlin/elide/tool/control/AbstractScriptEngineFactory.kt index 2b2e6d273..86486e0a5 100644 --- a/packages/cli/src/main/kotlin/elide/tool/control/AbstractScriptEngineFactory.kt +++ b/packages/cli/src/main/kotlin/elide/tool/control/AbstractScriptEngineFactory.kt @@ -452,8 +452,8 @@ abstract class AbstractScriptEngineFactory protected constructor (val engine: Gr object : MutableEntry { override val key: String get() = s override val value: Any get() = get(s)!! - override fun setValue(value: Any): Any { - return put(s, value)!! + override fun setValue(newValue: Any): Any { + return put(s, newValue)!! } }, ) @@ -461,14 +461,14 @@ abstract class AbstractScriptEngineFactory protected constructor (val engine: Gr return values } - override fun put(name: String, value: Any): Any? { - val previous = get(name) - languageBindings.putMember(name, value) + override fun put(key: String, value: Any): Any? { + val previous = get(key) + languageBindings.putMember(key, value) return previous } - override fun putAll(toMerge: Map) { - for ((key, value) in toMerge) { + override fun putAll(from: Map) { + for ((key, value) in from) { put(key, value) } } diff --git a/packages/cli/src/main/resources/logback.scmo b/packages/cli/src/main/resources/logback.scmo index c3e6391ea..5d5fe9ee4 100644 Binary files a/packages/cli/src/main/resources/logback.scmo and b/packages/cli/src/main/resources/logback.scmo differ diff --git a/packages/embedded/build.gradle.kts b/packages/embedded/build.gradle.kts index fedb7d817..351d664e2 100644 --- a/packages/embedded/build.gradle.kts +++ b/packages/embedded/build.gradle.kts @@ -117,7 +117,7 @@ val jvmCompileArgs = listOfNotNull( "--add-modules=jdk.incubator.vector", "-Delide.embedded.headerPath=$nativeHeaderPath", "--enable-native-access=" + listOfNotNull( - "ALL-UNNAMED", +// "ALL-UNNAMED", "org.graalvm.polyglot", "org.graalvm.js", if (enableRuby) "org.graalvm.ruby" else null, @@ -210,6 +210,7 @@ val commonNativeArgs = listOfNotNull( "-H:+UseContainerSupport", "-H:+ReportExceptionStackTraces", "-H:+AddAllCharsets", + "-H:DeadlockWatchdogInterval=15", "-H:TempDirectory=${layout.buildDirectory.dir("native/tmp").get().asFile.path}", "--trace-class-initialization=io.netty.channel.DefaultFileRegion,io.netty.util.AbstractReferenceCounted", if (enableEspresso) "-H:+AllowJRTFileSystem" else null, @@ -442,6 +443,12 @@ val initializeAtBuildTime = listOf( "org.slf4j.helpers.NOPLoggerFactory", "org.slf4j.helpers.NOP_FallbackServiceProvider", + // JANSI + "org.fusesource.jansi.AnsiConsole", + "org.fusesource.jansi.internal.OSInfo", + "org.fusesource.jansi.io.AnsiOutputStream", + "org.fusesource.jansi.internal.CLibrary", + // Encodings, Parsers, Cryptography "com.sun.tools.doclint", "org.codehaus.stax2.typed.Base64Variants", @@ -625,7 +632,7 @@ val darwinOnlyArgs = defaultPlatformArgs.plus(listOf( ).plus(if (project.properties["elide.ci"] == "true") listOf( "-J-Xmx12g", ) else listOf( - "-J-Xmx24g", + "-J-Xmx32g", ))).plus(if (oracleGvm && enableAuxCache) listOf( "-H:+AuxiliaryEngineCache", ) else emptyList()) @@ -895,55 +902,47 @@ dependencies { // Dependencies: GraalVM modules(libs.graalvm.polyglot) - modules(libs.graalvm.polyglot.tools.coverage) - modules(libs.graalvm.polyglot.tools.dap) - modules(libs.graalvm.polyglot.tools.inspect) - modules(libs.graalvm.polyglot.tools.insight) - modules(libs.graalvm.polyglot.tools.heap) - modules(libs.graalvm.polyglot.tools.profiler) - modules(libs.graalvm.regex) // GraalVM: JavaScript + WASM modules(libs.graalvm.polyglot.js) modules(libs.graalvm.polyglot.wasm) modules(libs.graalvm.js.language) - modules(libs.graalvm.js.isolate) - - // GraalVM: Python - modules(libs.graalvm.polyglot.python) - modules(libs.graalvm.python.language) - modules(libs.graalvm.python.resources) - - // GraalVM: Ruby - modules(libs.graalvm.polyglot.ruby) - modules(libs.graalvm.ruby.language) - modules(libs.graalvm.ruby.resources) - - // GraalVM: Espresso - modules(libs.graalvm.polyglot.java) - modules(libs.graalvm.espresso.polyglot) - modules(libs.graalvm.espresso.language) - modules(libs.graalvm.espresso.hotswap) - - // GraalVM: LLVM - modules(libs.graalvm.polyglot.llvm) - modules(libs.graalvm.llvm.api) - modules(libs.graalvm.llvm.language) - modules(libs.graalvm.llvm.language.enterprise) - modules(libs.graalvm.llvm.language.nfi) - modules(libs.graalvm.llvm.language.native) - modules(libs.graalvm.llvm.language.native.resources) - modules(libs.graalvm.llvm.language.managed) - modules(libs.graalvm.llvm.language.managed.resources) + + if (oracleGvm) { + modules(libs.graalvm.js.isolate) + } + + if (enableExperimental) { + // GraalVM: Python + modules(libs.graalvm.polyglot.python) + modules(libs.graalvm.python.language) + modules(libs.graalvm.python.resources) + + // GraalVM: Ruby + modules(libs.graalvm.polyglot.ruby) + modules(libs.graalvm.ruby.language) + modules(libs.graalvm.ruby.resources) + + // GraalVM: Espresso + modules(libs.graalvm.polyglot.java) + modules(libs.graalvm.espresso.polyglot) + modules(libs.graalvm.espresso.language) + modules(libs.graalvm.espresso.hotswap) + + // GraalVM: LLVM + modules(libs.graalvm.polyglot.llvm) + modules(libs.graalvm.llvm.api) + modules(libs.graalvm.llvm.language) + modules(libs.graalvm.llvm.language.enterprise) + modules(libs.graalvm.llvm.language.nfi) + modules(libs.graalvm.llvm.language.native) + modules(libs.graalvm.llvm.language.native.resources) + modules(libs.graalvm.llvm.language.managed) + modules(libs.graalvm.llvm.language.managed.resources) + } // GraalVM: Truffle modules(libs.graalvm.truffle.api) - modules(libs.graalvm.truffle.processor) - modules(libs.graalvm.truffle.nfi) - modules(libs.graalvm.truffle.nfi.panama) - modules(libs.graalvm.truffle.nfi.libffi) - modules(libs.graalvm.truffle.nfi.native.linux.amd64) - modules(libs.graalvm.truffle.nfi.native.darwin.aarch64) // General implementation(libs.snakeyaml) @@ -953,7 +952,6 @@ dependencies { implementation(libs.jline.terminal.jansi) implementation(libs.jline.terminal.jni) implementation(libs.jline.terminal.jna) - implementation(libs.jline.terminal.ffm) // GraalVM: SVM compileOnly(libs.graalvm.svm) @@ -968,6 +966,7 @@ dependencies { runtimeOnly(mn.logback.classic) // Crypto + implementation(libs.bouncycastle) runtimeOnly(libs.bouncycastle.tls) runtimeOnly(libs.bouncycastle.pkix) runtimeOnly(libs.bouncycastle.util) diff --git a/packages/embedded/src/main/kotlin/elide/embedded/ElideEmbedded.kt b/packages/embedded/src/main/kotlin/elide/embedded/ElideEmbedded.kt index 651944fe6..30fabc265 100644 --- a/packages/embedded/src/main/kotlin/elide/embedded/ElideEmbedded.kt +++ b/packages/embedded/src/main/kotlin/elide/embedded/ElideEmbedded.kt @@ -63,7 +63,7 @@ import elide.embedded.err.InitializationError * Calls are submitted to endpoints (TCP, Unix socket, etc.), and routed to the appropriate application. Methods are * provided in the Host Control API for resolving an application ID. */ -public class ElideEmbedded private constructor () { +@Suppress("UNUSED_PARAMETER") public class ElideEmbedded private constructor () { public companion object { @JvmStatic public fun main(args: Array) { ElideEmbedded().entry(args) diff --git a/packages/embedded/src/main/resources/logback.scmo b/packages/embedded/src/main/resources/logback.scmo index 69cc6af40..b260870c1 100644 Binary files a/packages/embedded/src/main/resources/logback.scmo and b/packages/embedded/src/main/resources/logback.scmo differ diff --git a/packages/graalvm/api/graalvm.api b/packages/graalvm/api/graalvm.api index 0c1bd6491..3dfc77712 100644 --- a/packages/graalvm/api/graalvm.api +++ b/packages/graalvm/api/graalvm.api @@ -2460,6 +2460,7 @@ public final class elide/runtime/plugins/js/ExtensionsKt { public final class elide/runtime/plugins/js/JavaScript { public static final field Plugin Lelide/runtime/plugins/js/JavaScript$Plugin; public synthetic fun (Lelide/runtime/plugins/js/JavaScriptConfig;Lelide/runtime/plugins/AbstractLanguagePlugin$LanguagePluginManifest;Lelide/runtime/plugins/env/Environment;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public static final fun getWasmSupported$graalvm ()Z } public final class elide/runtime/plugins/js/JavaScript$Plugin : elide/runtime/plugins/AbstractLanguagePlugin { diff --git a/packages/graalvm/build.gradle.kts b/packages/graalvm/build.gradle.kts index d546b7668..89a1adabd 100644 --- a/packages/graalvm/build.gradle.kts +++ b/packages/graalvm/build.gradle.kts @@ -257,32 +257,10 @@ dependencies { implementation(libs.capnproto.runtime) implementation(libs.capnproto.runtime.rpc) - api("org.graalvm.polyglot:polyglot:${libs.versions.graalvm.pin.get()}") { - exclude(group = "org.graalvm.sdk", module = "collections") - exclude(group = "org.graalvm.sdk", module = "nativeimage") - exclude(group = "org.graalvm.sdk", module = "word") - } - - api(libs.graalvm.regex) - api(libs.graalvm.polyglot.js) { - exclude(group = "org.graalvm.sdk", module = "collections") - exclude(group = "org.graalvm.sdk", module = "nativeimage") - exclude(group = "org.graalvm.sdk", module = "word") - } - + api(libs.graalvm.polyglot) + api(libs.graalvm.polyglot.js) compileOnly(libs.graalvm.svm) - testImplementation(libs.bundles.graalvm.tools) { - exclude(group = "org.graalvm.sdk", module = "collections") - exclude(group = "org.graalvm.sdk", module = "nativeimage") - exclude(group = "org.graalvm.sdk", module = "word") - } - testImplementation(libs.bundles.graalvm.polyglot) { - exclude(group = "org.graalvm.sdk", module = "collections") - exclude(group = "org.graalvm.sdk", module = "nativeimage") - exclude(group = "org.graalvm.sdk", module = "word") - } - // Testing testImplementation(projects.packages.test) testImplementation(libs.kotlinx.coroutines.test) diff --git a/packages/graalvm/src/main/kotlin/elide/runtime/core/internals/graalvm/GraalVMEngine.kt b/packages/graalvm/src/main/kotlin/elide/runtime/core/internals/graalvm/GraalVMEngine.kt index b13e83ce9..fd55a9b0c 100644 --- a/packages/graalvm/src/main/kotlin/elide/runtime/core/internals/graalvm/GraalVMEngine.kt +++ b/packages/graalvm/src/main/kotlin/elide/runtime/core/internals/graalvm/GraalVMEngine.kt @@ -155,12 +155,14 @@ import org.graalvm.polyglot.HostAccess as PolyglotHostAccess override fun close() = Unit } + /** Whether to enable Enterprise features. */ + private const val ENABLE_ENTERPRISE = false /** Whether to enable VM isolates. */ - private const val ENABLE_ISOLATES = false + private const val ENABLE_ISOLATES = ENABLE_ENTERPRISE /** Whether to enable the auxiliary cache. */ - private const val ENABLE_AUX_CACHE = true + private const val ENABLE_AUX_CACHE = false /** Whether the runtime is built as a native image. */ private val isNativeImage = ImageInfo.inImageCode() @@ -207,12 +209,12 @@ import org.graalvm.polyglot.HostAccess as PolyglotHostAccess "engine.Compilation", "engine.MultiTier", "engine.Splitting", - "engine.InlineAcrossTruffleBoundary", "engine.OSR", ) - // TODO(@darvld): swap for throughput in server mode - option("engine.Mode", "latency") + configuration.hostRuntime.on(GVM_23.andLower()) { + enableOptions("engine.InlineAcrossTruffleBoundary") + } configuration.hostRuntime.on(GVM_23.andLower()) { enableOptions( @@ -242,12 +244,16 @@ import org.graalvm.polyglot.HostAccess as PolyglotHostAccess // if we're running in a native image, enabled the code compile cache if (useAuxCache) { - enableOption("engine.CachePreinitializeContext") option("engine.PreinitializeContexts", "js") option("engine.CacheCompile", "hot") + if (ENABLE_ENTERPRISE) { + enableOption("engine.CachePreinitializeContext") + } + + val pid = ProcessHandle.current().pid() option( "engine.Cache", - Path("/", "tmp", "elide-${ProcessHandle.current().pid()}.vmcache").toAbsolutePath().toString(), + Path("/", "tmp", "elide-$pid.vmcache").toAbsolutePath().toString(), ) } } diff --git a/packages/graalvm/src/main/kotlin/elide/runtime/gvm/internals/js/JsRuntime.kt b/packages/graalvm/src/main/kotlin/elide/runtime/gvm/internals/js/JsRuntime.kt index 1833bcf20..b71dd2814 100644 --- a/packages/graalvm/src/main/kotlin/elide/runtime/gvm/internals/js/JsRuntime.kt +++ b/packages/graalvm/src/main/kotlin/elide/runtime/gvm/internals/js/JsRuntime.kt @@ -142,40 +142,39 @@ internal class JsRuntime @Inject constructor ( StaticProperty.active("js.import-assertions"), StaticProperty.active("js.intl-402"), StaticProperty.active("js.json-modules"), + StaticProperty.active("js.nashorn-compat"), // @TODO(sgammon): disable after oracle/graaljs/issues/119 StaticProperty.active("js.performance"), + StaticProperty.active("js.shadow-realm"), StaticProperty.active("js.shared-array-buffer"), StaticProperty.active("js.strict"), StaticProperty.active("js.temporal"), StaticProperty.active("js.top-level-await"), - StaticProperty.active("js.shadow-realm"), - // @TODO(sgammon): disable once https://github.com/oracle/graaljs/issues/119 is resolved. - StaticProperty.active("js.nashorn-compat"), - StaticProperty.inactive("js.operator-overloading"), StaticProperty.inactive("js.annex-b"), StaticProperty.inactive("js.console"), StaticProperty.inactive("js.graal-builtin"), StaticProperty.inactive("js.interop-complete-promises"), StaticProperty.inactive("js.java-package-globals"), StaticProperty.inactive("js.load"), - StaticProperty.inactive("js.print"), + StaticProperty.inactive("js.operator-overloading"), StaticProperty.inactive("js.polyglot-builtin"), StaticProperty.inactive("js.polyglot-evalfile"), + StaticProperty.inactive("js.print"), StaticProperty.inactive("js.regex-static-result"), StaticProperty.inactive("js.scripting"), StaticProperty.inactive("js.syntax-extensions"), - StaticProperty.of("js.unhandled-rejections", UNHANDLED_REJECTIONS), StaticProperty.of("js.debug-property-name", DEBUG_GLOBAL), StaticProperty.of("js.function-constructor-cache-size", FUNCTION_CONSTRUCTOR_CACHE_SIZE), + StaticProperty.of("js.unhandled-rejections", UNHANDLED_REJECTIONS), ) // Hard-coded WASM VM options. val wasmOptions : List = listOf( + StaticProperty.active("wasm.BulkMemoryAndRefTypes"), StaticProperty.active("wasm.Memory64"), + StaticProperty.active("wasm.MultiMemory"), StaticProperty.active("wasm.MultiValue"), + StaticProperty.active("wasm.Threads"), StaticProperty.active("wasm.UseUnsafeMemory"), -// StaticProperty.active("wasm.MultiMemory"), - StaticProperty.active("wasm.BulkMemoryAndRefTypes"), -// StaticProperty.active("wasm.Threads"), StaticProperty.of("wasm.Builtins", WASI_STD), ) @@ -311,11 +310,7 @@ internal class JsRuntime @Inject constructor ( config.v8 ?: false }, )).plus( - if (config.wasm == true) { - wasmOptions - } else { - emptyList() - } + if (config.wasm == true && engine.languages.containsKey("wasm")) wasmOptions else emptyList() ).stream() /** @inheritDoc */ diff --git a/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScript.kt b/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScript.kt index 22ce5c8c7..25e5d14ae 100644 --- a/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScript.kt +++ b/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScript.kt @@ -13,6 +13,7 @@ package elide.runtime.plugins.js +import org.graalvm.polyglot.Engine import elide.runtime.core.DelicateElideApi import elide.runtime.core.EngineLifecycleEvent.ContextCreated import elide.runtime.core.EngineLifecycleEvent.ContextInitialized @@ -37,7 +38,6 @@ import elide.runtime.plugins.js.JavaScriptVersion.* private val resources: LanguagePluginManifest, private val environment: Environment? = null, ) { - private fun initializeContext(context: PolyglotContext) { // if applicable, install the env plugin bindings environment?.install(context, JavaScript) @@ -64,61 +64,55 @@ import elide.runtime.plugins.js.JavaScriptVersion.* "js.import-assertions", "js.intl-402", "js.json-modules", + "js.nashorn-compat", // @TODO(sgammon): disable once https://github.com/oracle/graaljs/issues/119 is resolved. "js.performance", + "js.shadow-realm", "js.shared-array-buffer", "js.strict", "js.temporal", "js.top-level-await", - "js.shadow-realm", - // @TODO(sgammon): disable once https://github.com/oracle/graaljs/issues/119 is resolved. - "js.nashorn-compat", ) disableOptions( - "js.operator-overloading", "js.annex-b", "js.console", "js.graal-builtin", "js.interop-complete-promises", "js.java-package-globals", "js.load", - "js.print", + "js.operator-overloading", "js.polyglot-builtin", "js.polyglot-evalfile", + "js.print", "js.regexp-static-result", "js.scripting", "js.syntax-extensions", ) setOptions( - "js.unhandled-rejections" to UNHANDLED_REJECTIONS, + "js.charset" to config.charset.name(), + "js.commonjs-require-cwd" to config.npmConfig.modulesPath, "js.debug-property-name" to DEBUG_GLOBAL, + "js.ecmascript-version" to config.language.symbol(), "js.function-constructor-cache-size" to FUNCTION_CONSTRUCTOR_CACHE_SIZE, - ) - - setOptions( "js.locale" to config.locale.toString(), - "js.charset" to config.charset.name(), - "js.ecmascript-version" to config.language.symbol(), - "js.commonjs-require-cwd" to config.npmConfig.modulesPath, + "js.unhandled-rejections" to UNHANDLED_REJECTIONS, ) setOptions( - "js.shell" to config.interactive, - "js.esm-eval-returns-exports" to config.esm, - "js.esm-bare-specifier-relative-lookup" to config.esm, "js.commonjs-require" to config.npmConfig.enabled, + "js.esm-bare-specifier-relative-lookup" to config.esm, + "js.esm-eval-returns-exports" to config.esm, + "js.shell" to config.interactive, "js.v8-compat" to config.v8, ) - if (config.wasm) { - enableOptions( - "wasm.Memory64", - "wasm.MultiValue", - "wasm.UseUnsafeMemory", - "wasm.BulkMemoryAndRefTypes", - ) - + if (config.wasm && wasmSupported) enableOptions( + "wasm.BulkMemoryAndRefTypes", + "wasm.Memory64", + "wasm.MultiValue", + "wasm.UseUnsafeMemory", + ).also { option("wasm.Builtins", WASI_STD) } @@ -147,6 +141,10 @@ import elide.runtime.plugins.js.JavaScriptVersion.* override val languageId: String = JS_LANGUAGE_ID override val key: Key = Key(JS_PLUGIN_ID) + @JvmStatic internal val wasmSupported by lazy { + Engine.create().languages.containsKey("wasm") + } + override fun install(scope: InstallationScope, configuration: JavaScriptConfig.() -> Unit): JavaScript { configureLanguageSupport(scope) diff --git a/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScriptConfig.kt b/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScriptConfig.kt index 4a2fb659f..5443382f9 100644 --- a/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScriptConfig.kt +++ b/packages/graalvm/src/main/kotlin/elide/runtime/plugins/js/JavaScriptConfig.kt @@ -43,9 +43,9 @@ import elide.runtime.plugins.js.JavaScriptVersion.ES2022 /** Core module replacement map. */ private val moduleReplacements: MutableMap = mutableMapOf( "buffer" to "/__runtime__/buffer/buffer.cjs", - "util" to "/__runtime__/util/util.cjs", - "fs" to "/__runtime__/fs/fs.cjs", "express" to "/__runtime__/express/express.cjs", + "fs" to "/__runtime__/fs/fs.cjs", + "util" to "/__runtime__/util/util.cjs", ) internal fun replacements(): Map { diff --git a/packages/graalvm/src/test/kotlin/elide/runtime/core/ContextTest.kt b/packages/graalvm/src/test/kotlin/elide/runtime/core/ContextTest.kt index 5df2aed04..abec71c51 100644 --- a/packages/graalvm/src/test/kotlin/elide/runtime/core/ContextTest.kt +++ b/packages/graalvm/src/test/kotlin/elide/runtime/core/ContextTest.kt @@ -18,6 +18,7 @@ import org.graalvm.polyglot.Source import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import kotlin.random.Random +import kotlin.test.Ignore import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -34,7 +35,7 @@ internal class ContextTest { override val languageId: String = "python" } - @Test fun testIntrinsicBindings() { + @Test @Ignore fun testIntrinsicBindings() { val context = PolyglotEngine { enableLanguage(Python) enableLanguage(JavaScript) @@ -55,6 +56,34 @@ internal class ContextTest { } } + @Test fun testIntrinsicBindingsJs() { + val context = PolyglotEngine { + enableLanguage(JavaScript) + }.acquire() + + val (jsKey, jsValue) = "jsTestBinding" to Random.nextInt() + + // set a language-scoped binding + context.bindings(language = JavaScript).putMember(jsKey, jsValue) + + assertEquals( + expected = jsValue, + actual = context.evaluate(language = JavaScript, source = jsKey).asInt(), + message = "language-scoped binding should be accessible in target language", + ) + } + + @Test @Ignore fun testIntrinsicBindingsPy() { + val context = PolyglotEngine { + enableLanguage(Python) + }.acquire() + val (jsKey, _) = "jsTestBinding" to Random.nextInt() + + assertThrows("language-scoped binding should not be accessible to other languages") { + context.evaluate(language = Python, source = jsKey) + } + } + @Test fun testEnableLanguage() { val context = PolyglotEngine { // explicitly enable Python, but not JS diff --git a/tools/elide-build/src/main/kotlin/elide/internal/conventions/dependencies/DependencyResolutionConventions.kt b/tools/elide-build/src/main/kotlin/elide/internal/conventions/dependencies/DependencyResolutionConventions.kt index 6ae7ad5ec..83ebf4a0f 100644 --- a/tools/elide-build/src/main/kotlin/elide/internal/conventions/dependencies/DependencyResolutionConventions.kt +++ b/tools/elide-build/src/main/kotlin/elide/internal/conventions/dependencies/DependencyResolutionConventions.kt @@ -19,6 +19,19 @@ import org.gradle.kotlin.dsl.exclude import elide.internal.conventions.Constants.Versions import elide.internal.conventions.ElideBuildExtension +// Determine whether enterprise features are enabled. +private val isEnterprise: Project.() -> Boolean = { + findProperty("elide.graalvm.variant") == "ENTERPRISE" +} + +// Truffle Enterprise artifacts which must be omitted when building against GraalVM CE. +private val nonEnterpriseExclusions = listOf( + "org.graalvm.truffle" to "truffle-enterprise", + "org.graalvm.llvm" to "llvm-language-enterprise", + "org.graalvm.llvm" to "llvm-language-native-enterprise", + "org.graalvm.python" to "python-language-enterprise", +) + // Configurations which are exempt from locking checks. private val lockingExemptConfigurations = sortedSetOf( "nativeMainImplementationDependenciesMetadata", @@ -33,13 +46,6 @@ private val nettyExemptions = sortedSetOf( "boringssl", ) -// GraalVM Java modules which are included in the distribution, so should be omitted from the classpath. -private val gvmDistModules = sortedSetOf( - "org.graalvm.sdk:collections", - "org.graalvm.sdk:nativeimage", - "org.graalvm.sdk:word", -) - // Configurations from which to omit distributed GraalVM modules. private val gvmConfigurations = sortedSetOf( "compileClasspath", @@ -116,7 +122,7 @@ internal fun Project.configureDependencyResolution(conventions: ElideBuildExtens } // process dependency pins: bouncycastle - if (requested.group == "org.bouncycastle") { + if (requested.group == "org.bouncycastle" && requested.name == "bcprov-jdk18on") { useVersion(Versions.BOUNCYCASTLE) because("pin bouncycastle") } @@ -146,12 +152,9 @@ internal fun Project.configureDependencyResolution(conventions: ElideBuildExtens } } - if (gvmConfigurations.contains(this@all.name) && isGraalVm) { - gvmDistModules.forEach { - exclude( - group = it.substringBefore(':'), - module = it.substringAfter(':'), - ) + if (isGraalVm && !isEnterprise.invoke(this@configureDependencyResolution)) nonEnterpriseExclusions.forEach { + if (gvmConfigurations.contains(this@all.name)) { + exclude(group = it.first, module = it.second) } } }