Skip to content

Commit

Permalink
Separating value of ENSO_LAUNCHER variable by comma
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jan 23, 2025
1 parent 9579bff commit 598c287
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
12 changes: 5 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions docs/infrastructure/native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
47 changes: 47 additions & 0 deletions project/GraalVM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 598c287

Please sign in to comment.