diff --git a/build.sbt b/build.sbt index 4f6254607b00..82568ba5a9be 100644 --- a/build.sbt +++ b/build.sbt @@ -5202,25 +5202,23 @@ lazy val shouldBuildNativeImage = taskKey[Boolean]( ) ThisBuild / shouldBuildNativeImage := { - val prop = System.getenv("ENSO_LAUNCHER") - prop != null && prop.contains("native") + GraalVM.EnsoLauncher.native } ThisBuild / NativeImage.additionalOpts := { - val prop = System.getenv("ENSO_LAUNCHER") - if (prop == null) { + if (GraalVM.EnsoLauncher.shell) { Seq() } else { - var opts = if (prop == "native") { + var opts = if (GraalVM.EnsoLauncher.release) { Seq("-O3") } else { Seq("-Ob") } - if (prop.contains("debug")) { + if (GraalVM.EnsoLauncher.debug) { opts = opts ++ Seq("-H:GenerateDebugInfo=1") } - if (prop.contains("test")) { + if (GraalVM.EnsoLauncher.test) { opts = opts ++ Seq("-ea") } opts diff --git a/docs/infrastructure/native-image.md b/docs/infrastructure/native-image.md index fa66324447df..8f13af3d5f9f 100644 --- a/docs/infrastructure/native-image.md +++ b/docs/infrastructure/native-image.md @@ -208,16 +208,17 @@ one of the following: the native image. - `native`: `buildEngineDistribution` command builds native image in _release mode_ - e.g. turns on maximal optimizations increasing the build time. -- There are additional variants of `native` useful for _development_: - - anything that includes `native` substring turns on _native image_ build, but - disables optimizations - for example `fastnative` produces build similar to - _release mode_, but faster - - include `test` to _enable assertions_ - e.g. using `testnative` instructs +- There are additional variants of `native` useful for _development_. They are specified + as comma separated attributes following `native`: + - using `native,fast` turns on _native image_ build, but + disables optimizations - e.g. produces build similar to + _release mode_, but more quickly + - using `native,test` _enables assertions_ - e.g. it instructs `buildEngineDistribution` command to build native image with assertions - enabled (`-ea`). Useful for running tests on the CI. - - include `debug` to generate _debugging informations_ for VSCode _native + enabled (`-ea`). Useful for running Enso tests in the _native mode_. + - using `native,debug` generates _debugging informations_ for VSCode _native image debugger_ - - it is possible to combine all features - e.g. use `debugtestnative` + - it is possible to combine all features - e.g. use `debug,fast,test,native` To test _native image_ launcher choose one of the `native` configurations and invoke: diff --git a/project/DistributionPackage.scala b/project/DistributionPackage.scala index 42c68a3e77fe..4918881162d5 100644 --- a/project/DistributionPackage.scala +++ b/project/DistributionPackage.scala @@ -169,10 +169,9 @@ object DistributionPackage { log = log ) - var noCopyInNativeMode = System.getenv().get("ENSO_LAUNCHER") - if (noCopyInNativeMode != null && noCopyInNativeMode.contains("native")) { + if (!GraalVM.EnsoLauncher.shell) { log.info( - s"Not using shell launchers as ENSO_LAUNCHER env variable is $noCopyInNativeMode" + s"Not using shell launchers as ${GraalVM.EnsoLauncher.VAR_NAME} env variable is ${GraalVM.EnsoLauncher.toString}" ) } else { copyDirectoryIncremental( diff --git a/project/GraalVM.scala b/project/GraalVM.scala index cea30af89bbb..9cf08d790ab2 100644 --- a/project/GraalVM.scala +++ b/project/GraalVM.scala @@ -9,6 +9,53 @@ import scala.collection.immutable.Seq /** A collection of utility methods for everything related to the GraalVM and Truffle. */ object GraalVM { + object EnsoLauncher { + val VAR_NAME = "ENSO_LAUNCHER" + + override def toString(): String = { + val prop = System.getenv(VAR_NAME) + // default value is `shell` + return if (prop == null) "shell" else prop; + } + + private lazy val parsed: (Boolean, Boolean, Boolean, Boolean, Boolean) = { + var shell = false + var native = false + var test = false + var debug = false + var fast = false + toString().split(",").foreach { + case "shell" => shell = true + case "native" => native = true + case "test" => { + native = true + test = true + } + case "debug" => { + native = true + debug = true + } + case "fast" => { + native = true + fast = true + } + case v => + throw new IllegalStateException(s"Unexpected value of $VAR_NAME: $v") + } + if (shell && native) { + throw new IllegalStateException( + s"Cannot specify `shell` and other properties in $VAR_NAME env variable" + ) + } + (shell, native, test, debug, fast) + } + val shell = parsed._1 + val native = parsed._2 + val test = parsed._3 + val debug = parsed._4 + val fast = parsed._5 + val release = native && !test && !debug && !fast + } /** Has the user requested to use Espresso for Java interop? */ private def isEspressoMode(): Boolean =