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

Importing (some of) Standard.Base works from NI runner #9866

Merged
merged 23 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dbd5253
Adjust path to engine/runner
JaroslavTulach May 6, 2024
8cc1b2d
Regenerated with env JAVA_OPTS="-agentlib:native-image-agent=config-m…
JaroslavTulach May 6, 2024
a62f747
Include all Standard/Base JARs on classpath when building NI of engin…
JaroslavTulach May 6, 2024
b9f8fec
Importing from Standard.Base works in NI mode again
JaroslavTulach May 6, 2024
46b48d6
base-polyglot-root may not exist
JaroslavTulach May 7, 2024
2556a2c
Compute additional path at invocation of the buildNativeImage task
JaroslavTulach May 7, 2024
0d24b3e
Useful perf and debug switches
JaroslavTulach May 7, 2024
0d7a11b
Merging removal of java.desktop to this branch
JaroslavTulach May 8, 2024
9d75c72
Configuration for NI debugging of the runner
JaroslavTulach May 13, 2024
c507a47
NI is built from -cp - we need other method of detecting presence of …
JaroslavTulach May 13, 2024
2473812
Script to generate 'small JDK' with native-image in jdk directory
JaroslavTulach May 13, 2024
1933c77
Exclude Graal.js and Graal Python when using Espresso, as they don't …
JaroslavTulach May 14, 2024
593e9b0
Avoid special Graal.js settings
JaroslavTulach May 15, 2024
e20308b
Patching SnakeYaml to run without java.desktop
JaroslavTulach May 15, 2024
38fca73
Copy all JARs to polyglot/java directory in Espresso mode
JaroslavTulach May 15, 2024
87a15e0
Shelve SnakeYaml patches into a single project
JaroslavTulach May 15, 2024
d29c9a1
Build smalljdk before buildNativeImage
JaroslavTulach May 15, 2024
e4cb551
Merge remote-tracking branch 'origin/develop' into wip/jtulach/NIwith…
JaroslavTulach May 15, 2024
2e3b0ed
Hide access to various Pkgs constants
JaroslavTulach May 15, 2024
4d90834
Rewrite SBT support
hubertp May 16, 2024
9cf1543
fix NPE
hubertp May 16, 2024
c627c0f
Correctly detect new javaHome for NI
hubertp May 16, 2024
58ed0bc
nit
hubertp May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 58 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import src.main.scala.licenses.{
import JPMSPlugin.autoImport._

import java.io.File
import java.nio.file.Paths

// ============================================================================
// === Global Configuration ===================================================
Expand Down Expand Up @@ -1029,6 +1030,7 @@ lazy val `project-manager` = (project in file("lib/scala/project-manager"))
Test / javaOptions ++= testLogProviderOptions
)
.settings(
NativeImage.smallJdk := None,
rebuildNativeImage := NativeImage
.buildNativeImage(
"project-manager",
Expand Down Expand Up @@ -2350,6 +2352,55 @@ lazy val `engine-runner` = project
run / connectInput := true
)
.settings(
NativeImage.smallJdk := Some(buildSmallJdk.value),
buildSmallJdk := {
val smallJdkDirectory = (target.value / "jdk").getAbsoluteFile()
val JS_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,jdk.compiler.graal,jdk.httpserver,java.naming,java.net.http"
val DEBUG_MODULES = "jdk.jdwp.agent"
val PYTHON_MODULES = "jdk.security.auth,java.naming"

val javaHome = Option(System.getProperty("java.home")).map(Paths.get(_))
val (jlink, modules, libDirs) = javaHome match {
case None =>
throw new RuntimeException("Missing java.home variable")
case Some(jh) =>
val exec = jh.resolve("bin").resolve("jlink")
val moduleJars = List(
"lib/svm/bin/../../graalvm/svm-driver.jar",
"lib/svm/bin/../builder/native-image-base.jar",
"lib/svm/bin/../builder/objectfile.jar",
"lib/svm/bin/../builder/pointsto.jar",
"lib/svm/bin/../builder/svm-enterprise.jar",
"lib/svm/bin/../builder/svm.jar",
"lib/svm/bin/../library-support.jar"
)
val targetLibDirs = List("graalvm", "svm", "static", "truffle")
(
exec,
moduleJars.map(jar => jh.resolve(jar).toString),
targetLibDirs.map(d => jh.resolve("lib").resolve("d"))
)
}

val exec =
Copy link
Member Author

Choose a reason for hiding this comment

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

Exec in Scala! Amazing, thank you @hubertp!

s"$jlink --module-path ${modules.mkString(":")} --output $smallJdkDirectory --add-modules $JS_MODULES,$DEBUG_MODULES,$PYTHON_MODULES"
val exitCode = scala.sys.process.Process(exec).!
libDirs.foreach(libDir =>
IO.copyDirectory(
libDir.toFile,
smallJdkDirectory.toPath.resolve("lib").toFile
)
)
if (exitCode != 0) {
throw new RuntimeException(s"Cannot execute smalljdk.sh")
}
assert(
smallJdkDirectory.exists(),
"Directory of small JDK " + smallJdkDirectory + " is not present"
)
smallJdkDirectory
},
assembly := assembly
.dependsOn(`runtime-fat-jar` / assembly)
.value,
Expand All @@ -2368,33 +2419,14 @@ lazy val `engine-runner` = project
"-Dnic=nic"
),
mainClass = Some("org.enso.runner.Main"),
additionalCp = () => {
additionalCp = {
val core = Seq(
"runtime.jar",
"runner.jar"
)
val jars = `base-polyglot-root`.listFiles("*.jar")
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
if (jars == null) {
core
} else {
core ++ jars.map(_.getAbsolutePath())
}
core ++ jars.map(_.getAbsolutePath())
},
localJdk = Some(() => {
var smalljdk = (new File("target") / "jdk").getAbsoluteFile()
val exitCode = scala.sys.process
.Process(
"bash project/smalljdk.sh " + smalljdk,
None,
"JAVA_HOME" -> System.getProperty("java.home")
)
.!
if (exitCode != 0) {
throw new RuntimeException(s"Cannot execute jdk.sh.")
}
assert(smalljdk.exists(), "Dir created " + smalljdk)
smalljdk
}),
initializeAtRuntime = Seq(
"org.jline.nativ.JLineLibrary",
"org.jline.terminal.impl.jna",
Expand All @@ -2412,6 +2444,7 @@ lazy val `engine-runner` = project
"akka.http"
)
)
.dependsOn(`std-base` / Compile / packageBin)
.dependsOn(assembly)
.dependsOn(
buildEngineDistribution
Expand All @@ -2435,6 +2468,9 @@ lazy val `engine-runner` = project
.dependsOn(`logging-service-logback` % Runtime)
.dependsOn(`polyglot-api`)

lazy val buildSmallJdk =
taskKey[File]("Build a minimal JDK used for native image generation")

lazy val launcher = project
.in(file("engine/launcher"))
.configs(Test)
Expand All @@ -2449,6 +2485,7 @@ lazy val launcher = project
)
)
.settings(
NativeImage.smallJdk := None,
rebuildNativeImage := NativeImage
.buildNativeImage(
"enso",
Expand Down
15 changes: 8 additions & 7 deletions project/NativeImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ object NativeImage {
*/
private val includeDebugInfo: Boolean = false

lazy val smallJdk = taskKey[Option[File]]("Location of a minimal JDK")

/** List of classes that should be initialized at build time by the native image.
* Note that we strive to initialize as much classes during the native image build
* time as possible, as this reduces the time needed to start the native image.
Expand Down Expand Up @@ -86,10 +88,9 @@ object NativeImage {
initializeAtRuntime: Seq[String] = Seq.empty,
initializeAtBuildtime: Seq[String] = defaultBuildTimeInitClasses,
mainClass: Option[String] = None,
additionalCp: () => Seq[String] = () => Seq(),
additionalCp: Seq[String] = Seq(),
verbose: Boolean = false,
includeRuntime: Boolean = true,
localJdk: Option[() => File] = None
includeRuntime: Boolean = true
): Def.Initialize[Task[Unit]] = Def
.task {
val log = state.value.log
Expand All @@ -100,8 +101,8 @@ object NativeImage {
else s"$path/bin/native-image"

val javaHome =
localJdk
.map(f => f().getPath())
smallJdk.value
.map(f => f.getPath())
.filter(p => file(nativeImagePath(p)).exists())
.getOrElse(System.getProperty("java.home"))

Expand Down Expand Up @@ -194,9 +195,9 @@ object NativeImage {

val fullCp =
if (includeRuntime) {
componentModules ++ additionalCp()
componentModules ++ additionalCp
} else {
ourCp.map(_.data.getAbsolutePath) ++ additionalCp()
ourCp.map(_.data.getAbsolutePath) ++ additionalCp
}
val cpStr = fullCp.mkString(File.pathSeparator)
log.debug("Class-path: " + cpStr)
Expand Down
21 changes: 0 additions & 21 deletions project/smalljdk.sh

This file was deleted.