Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable std-database in native image #12068

Merged
merged 19 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
23 changes: 18 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,8 @@ lazy val `ydoc-polyfill` = project
"com.github.sbt" % "junit-interface" % junitIfVersion % Test
),
libraryDependencies ++= {
GraalVM.modules ++ GraalVM.jsPkgs ++ GraalVM.chromeInspectorPkgs ++ helidon
GraalVM.modules ++ GraalVM.jsPkgs
.map(_ % "provided") ++ GraalVM.chromeInspectorPkgs ++ helidon
}
)
.dependsOn(`syntax-rust-definition`)
Expand Down Expand Up @@ -3707,7 +3708,8 @@ lazy val `engine-runner` = project
val stdLibsJars =
`base-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath()) ++
`image-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath()) ++
`table-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath())
`table-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath()) ++
`database-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath())
core ++ stdLibsJars
},
buildSmallJdk := {
Expand All @@ -3718,7 +3720,7 @@ lazy val `engine-runner` = project
val NI_MODULES =
"org.graalvm.nativeimage,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.base,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto,com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise"
val JDK_MODULES =
"jdk.localedata,jdk.httpserver,java.naming,java.net.http"
"jdk.localedata,jdk.httpserver,java.naming,java.net.http,java.desktop"
Copy link
Member

Choose a reason for hiding this comment

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

Including java.desktop is undesirable. What can we do to remove it?

  • Use quarkus version?
  • Replace java.awt.Color usage with a substitution?
  • Report a bug for later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would prefer the last option. Configuration is rather fragile and it is easier to improve it incrementally than push it in one go.

Copy link
Member

Choose a reason for hiding this comment

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

Go on, get this in. Otherwise we need to deal #12073 (comment) forever. Once this change is in, we can polish it more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

quarkus-poi doesn't work out-of-the-box. It seems it relies on the fact that one builds it for redhat base image:
https://github.com/quarkiverse/quarkus-poi?tab=readme-ov-file#docker

val DEBUG_MODULES = "jdk.jdwp.agent"
val PYTHON_MODULES = "jdk.security.auth,java.naming"

Expand Down Expand Up @@ -3781,6 +3783,12 @@ lazy val `engine-runner` = project
"enso",
targetDir = engineDistributionRoot.value / "bin",
staticOnLinux = false,
// sqlite-jdbc includes `--enable-url-protocols=jar` in its native-image.properites file,
// which breaks all our class loading. We still want to run `SqliteJdbcFeature` which extracts a proper
// native library from the jar.
excludeConfigs = Seq(
s".*sqlite-jdbc-.*\\.jar,META-INF/native-image/org\\.xerial/sqlite-jdbc/native-image\\.properties"
),
additionalOptions = Seq(
"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog",
"-H:IncludeResources=.*Main.enso$",
Expand All @@ -3793,8 +3801,11 @@ lazy val `engine-runner` = project
// "-H:-DeleteLocalSymbols",
// you may need to set smallJdk := None to use following flags:
// "--trace-class-initialization=org.enso.syntax2.Parser",
// "--diagnostics-mode",
// "--verbose",
"-Dnic=nic",
"-Dorg.enso.feature.native.lib.output=" + (engineDistributionRoot.value / "bin")
"-Dorg.enso.feature.native.lib.output=" + (engineDistributionRoot.value / "bin"),
"-Dorg.sqlite.lib.exportPath=" + (engineDistributionRoot.value / "bin")
),
mainClass = Some("org.enso.runner.Main"),
initializeAtRuntime = Seq(
Expand All @@ -3816,6 +3827,7 @@ lazy val `engine-runner` = project
"org.enso.base",
"org.enso.image",
"org.enso.table",
"org.enso.database",
"org.eclipse.jgit"
)
)
Expand Down Expand Up @@ -4725,7 +4737,8 @@ lazy val `std-table` = project
"org.apache.poi" % "poi-ooxml" % poiOoxmlVersion,
"org.apache.xmlbeans" % "xmlbeans" % xmlbeansVersion,
"org.antlr" % "antlr4-runtime" % antlrVersion,
"org.apache.logging.log4j" % "log4j-to-slf4j" % "2.18.0" // org.apache.poi uses log4j
"org.apache.logging.log4j" % "log4j" % "2.24.3",
"org.apache.logging.log4j" % "log4j-to-slf4j" % "2.24.3" // org.apache.poi uses log4j
),
Compile / packageBin := Def.task {
val result = (Compile / packageBin).value
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Args=--features=org.enso.runner.EnsoLibraryFeature
Args=--features=org.enso.runner.EnsoLibraryFeature,org.sqlite.nativeimage.SqliteJdbcFeature
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@
},
{
"name":"java.lang.Integer",
"fields":[{"name":"TYPE"}]
"fields":[{"name":"TYPE"}, {"name": "MAX_VALUE"}]
},
{
"name":"java.lang.Long",
"fields":[{"name":"TYPE"}]
"fields":[{"name":"TYPE"}, {"name": "MAX_VALUE"}]
},
{
"name":"java.lang.Math"
Expand Down Expand Up @@ -441,7 +441,7 @@
},
{
"name":"java.lang.Short",
"fields":[{"name":"TYPE"}]
"fields":[{"name":"TYPE"}, {"name": "MAX_VALUE"}]
},
{
"name":"java.lang.StackTraceElement",
Expand Down Expand Up @@ -1090,15 +1090,6 @@
"name":"org.apache.commons.compress.archivers.zip.Zip64ExtendedInformationExtraField",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.apache.poi.UnsupportedFileFormatException"
},
{
"name":"org.apache.poi.poifs.filesystem.NotOLE2FileException"
},
{
"name":"org.apache.poi.ss.usermodel.Workbook"
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.COMPOSITE$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand Down
9 changes: 8 additions & 1 deletion project/NativeImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ object NativeImage {
* of its resources directory. More information can be found at
* [[https://github.com/oracle/graal/blob/master/substratevm/BuildConfiguration.md]].
*
* @param artifactName name of the artifact to create
* @param name name of the artifact to create
* @param staticOnLinux specifies whether to link statically (applies only
* on Linux)
* @param excludeConfigs comma-separated list of jar-/file-patterns to exclude undesired NI configs
* @param additionalOptions additional options for the Native Image build
* tool
* @param buildMemoryLimitMegabytes a memory limit for the build tool, in
Expand All @@ -87,6 +88,7 @@ object NativeImage {
name: String,
staticOnLinux: Boolean,
targetDir: File = null,
excludeConfigs: Seq[String] = Seq.empty,
additionalOptions: Seq[String] = Seq.empty,
buildMemoryLimitMegabytes: Option[Int] = Some(15608),
runtimeThreadStackMegabytes: Option[Int] = Some(2),
Expand Down Expand Up @@ -199,8 +201,13 @@ object NativeImage {
log.debug("Class-path: " + cpStr)

val verboseOpt = if (verbose) Seq("--verbose") else Seq()
val excludeConfigsOpt =
if (excludeConfigs.nonEmpty)
excludeConfigs.flatMap(ex => Seq("--exclude-config") ++ ex.split(","))
else Seq.empty

var args: Seq[String] =
excludeConfigsOpt ++
Seq("-cp", cpStr) ++
quickBuildOption ++
debugParameters ++ staticParameters ++ configs ++
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name":"org.enso.table.util.NamingProperties"
},
{
"name":"java.sql.ParameterMetaData",
"methods":[
{
"name":"getParameterCount",
"parameterTypes":[]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"name":"java.awt.Color",
"fields":[{"name":"value"}]
},
{
"name":"java.awt.GraphicsEnvironment",
hubertp marked this conversation as resolved.
Show resolved Hide resolved
"methods":[{"name":"isHeadless","parameterTypes":[] }]
},
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.Class",
"methods":[{"name":"getClassLoader","parameterTypes":[] }]
},
{
"name":"java.lang.ClassLoader",
"methods":[{"name":"loadClass","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.System",
"methods":[{"name":"load","parameterTypes":["java.lang.String"] }]
},
{
"name":"jdk.internal.loader.ClassLoaders$AppClassLoader"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"interfaces":["org.enso.table.util.NamingProperties"]
},
{
"interfaces":["java.util.function.BiFunction"]
},
{
"interfaces":["org.enso.table.data.mask.SliceRange"]
},
{
"interfaces":["org.enso.table.data.table.join.lookup.LookupColumnDescription"]
},
{
"interfaces":["org.enso.table.util.FunctionWithException"]
}
]

Loading
Loading