Skip to content

Commit

Permalink
fix: native compilation in cli, embedded
Browse files Browse the repository at this point in the history
- fix: native compilation of `cli` entrypoint
- fix: errant logging for main entrypoints
- fix: native optimized compilation of `embedded` module
- fix: ability to build against GraalVM CE
- fix: only apply wasm flags if language is supported
- fix: double `detekt` call in ci jobs
- fix: various warning cleanups

Signed-off-by: Sam Gammon <sam@elide.ventures>
  • Loading branch information
sgammon committed Feb 17, 2024
1 parent 2d5480f commit 0ffbec6
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 255 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/job.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion gradle/elide.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
108 changes: 36 additions & 72 deletions packages/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -122,7 +122,6 @@ val enableSbomStrict = false
val enableTruffleJson = enableEdge
val encloseSdk = !System.getProperty("java.vm.version").contains("jvmci")
val globalExclusions = emptyList<Pair<String, String>>()

val moduleExclusions = listOf(
"io.micronaut" to "micronaut-core-processor",
)
Expand All @@ -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 ->
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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<String> = listOf(
Expand Down Expand Up @@ -772,7 +757,7 @@ val releaseFlags: List<String> = 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(),
Expand Down Expand Up @@ -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 ------

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -1191,8 +1157,6 @@ val muslArgs = listOf(

val testOnlyArgs: List<String> = emptyList()

val isEnterprise: Boolean = properties["elide.graalvm.variant"] == "ENTERPRISE"

fun nativeCliImageArgs(
platform: String = "generic",
target: String = "glibc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -> {}
}
}
Expand Down
Loading

0 comments on commit 0ffbec6

Please sign in to comment.