Skip to content

Commit

Permalink
Support for --jvm option in Enso runner (#10374)
Browse files Browse the repository at this point in the history
Addresses one of two concerns of #5298 - adds support for `--jvm` argument to allow us to switch from _native image_ built Enso binary (as developed by #10126) to regular JVM based Enso execution. This change _doesn't affect production builds_. The _native executable_ continues to be only built by `engine-runner/buildNativeImage` which is tested on CI, but not in the production jobs.
  • Loading branch information
JaroslavTulach authored Jul 6, 2024
1 parent d653710 commit 515d823
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 110 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ build-cache/
##################

*.build_artifacts.txt
/runner

######################
## Enso-Development ##
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
[10353]: https://github.com/enso-org/enso/pull/10353
[10396]: https://github.com/enso-org/enso/pull/10396

#### Enso Language & Runtime

- Support for [explicit --jvm option][10374] when launching `enso` CLI

[10374]: https://github.com/enso-org/enso/pull/10374

#### Enso Standard Library

- [Added Statistic.Product][10122]
Expand Down
103 changes: 56 additions & 47 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2627,55 +2627,60 @@ lazy val `engine-runner` = project
assembly := assembly
.dependsOn(`runtime-fat-jar` / assembly)
.value,
rebuildNativeImage :=
NativeImage
.buildNativeImage(
"runner",
staticOnLinux = false,
additionalOptions = Seq(
"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog",
"-H:IncludeResources=.*Main.enso$",
"-H:+AddAllCharsets",
"-H:+IncludeAllLocales",
"-ea",
// useful perf & debug switches:
// "-g",
// "-H:+SourceLevelDebug",
// "-H:-DeleteLocalSymbols",
// you may need to set smallJdk := None to use following flags:
// "--trace-class-initialization=org.enso.syntax2.Parser",
"-Dnic=nic"
),
mainClass = Some("org.enso.runner.Main"),
initializeAtRuntime = Seq(
"org.jline.nativ.JLineLibrary",
"org.jline.terminal.impl.jna",
"io.methvin.watchservice.jna.CarbonAPI",
"zio.internal.ZScheduler$$anon$4",
"org.enso.runner.Main$",
"sun.awt",
"sun.java2d",
"sun.font",
"java.awt",
"com.sun.imageio",
"com.sun.jna.internal.Cleaner",
"com.sun.jna.Structure$FFIType",
"akka.http"
rebuildNativeImage := Def
.taskDyn {
NativeImage
.buildNativeImage(
"enso",
targetDir = engineDistributionRoot.value / "bin",
staticOnLinux = false,
additionalOptions = Seq(
"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog",
"-H:IncludeResources=.*Main.enso$",
"-H:+AddAllCharsets",
"-H:+IncludeAllLocales",
"-ea",
// useful perf & debug switches:
// "-g",
// "-H:+SourceLevelDebug",
// "-H:-DeleteLocalSymbols",
// you may need to set smallJdk := None to use following flags:
// "--trace-class-initialization=org.enso.syntax2.Parser",
"-Dnic=nic"
),
mainClass = Some("org.enso.runner.Main"),
initializeAtRuntime = Seq(
"org.jline.nativ.JLineLibrary",
"org.jline.terminal.impl.jna",
"io.methvin.watchservice.jna.CarbonAPI",
"zio.internal.ZScheduler$$anon$4",
"org.enso.runner.Main$",
"sun.awt",
"sun.java2d",
"sun.font",
"java.awt",
"com.sun.imageio",
"com.sun.jna.internal.Cleaner",
"com.sun.jna.Structure$FFIType",
"akka.http"
)
)
)
.dependsOn(NativeImage.additionalCp)
.dependsOn(NativeImage.smallJdk)
.dependsOn(assembly)
.dependsOn(
buildEngineDistribution
)
.value,
buildNativeImage := NativeImage
.incrementalNativeImageBuild(
rebuildNativeImage,
"runner"
}
.dependsOn(NativeImage.additionalCp)
.dependsOn(NativeImage.smallJdk)
.dependsOn(assembly)
.dependsOn(
buildEngineDistribution
)
.value
.value,
buildNativeImage := Def.taskDyn {
NativeImage
.incrementalNativeImageBuild(
rebuildNativeImage,
"enso",
targetDir = engineDistributionRoot.value / "bin"
)
}.value
)
.dependsOn(`version-output`)
.dependsOn(yaml)
Expand Down Expand Up @@ -3575,6 +3580,10 @@ ThisBuild / buildEngineDistribution := {
buildEngineDistribution.result.value
}

ThisBuild / engineDistributionRoot := {
engineDistributionRoot.value
}

lazy val buildEngineDistributionNoIndex =
taskKey[Unit]("Builds the engine distribution without generating indexes")
buildEngineDistributionNoIndex := {
Expand Down
1 change: 0 additions & 1 deletion build/build/paths.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
bench-report.xml:
build.sbt:
run:
runner: # The runner native image (Linux only).
CHANGELOG.md:

# Launcher Package
Expand Down
19 changes: 17 additions & 2 deletions build/build/src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,15 @@ impl RunContext {
if self.config.build_native_runner {
debug!("Building and testing native engine runners");
runner_sanity_test(&self.repo_root, None).await?;
ide_ci::fs::remove_file_if_exists(&self.repo_root.runner)?;
let enso = self
.repo_root
.built_distribution
.enso_engine_triple
.engine_package
.bin
.join("enso")
.with_executable_extension();
ide_ci::fs::remove_file_if_exists(&enso)?;
if self.config.build_espresso_runner {
let enso_java = "espresso";
sbt.command()?
Expand Down Expand Up @@ -636,7 +644,14 @@ pub async fn runner_sanity_test(
// The engine package is necessary for running the native runner.
ide_ci::fs::tokio::require_exist(engine_package).await?;
if enso_java.is_none() {
let test_base = Command::new(&repo_root.runner)
let enso = repo_root
.built_distribution
.enso_engine_triple
.engine_package
.bin
.join("enso")
.with_executable_extension();
let test_base = Command::new(&enso)
.args(["--run", repo_root.test.join("Base_Tests").as_str()])
.set_env_opt(ENSO_JAVA, enso_java)?
.set_env(ENSO_DATA_DIRECTORY, engine_package)?
Expand Down
16 changes: 13 additions & 3 deletions build/build/src/enso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ impl BuiltEnso {
}

pub async fn run_benchmarks(&self, opt: BenchmarkOptions) -> Result {
self.cmd()?
.with_args(["--run", self.paths.repo_root.test.benchmarks.as_str()])
let filename = format!("enso{}", if TARGET_OS == OS::Windows { ".exe" } else { "" });
let enso = self
.paths
.repo_root
.built_distribution
.enso_engine_triple
.engine_package
.bin
.join(filename);
let benchmarks = Command::new(&enso)
.args(["--jvm", "--run", self.paths.repo_root.test.benchmarks.as_str()])
.set_env(ENSO_BENCHMARK_TEST_DRY_RUN, &Boolean::from(opt.dry_run))?
.run_ok()
.await
.await;
benchmarks
}

pub fn run_test(&self, test_path: impl AsRef<Path>, ir_caches: IrCaches) -> Result<Command> {
Expand Down
2 changes: 1 addition & 1 deletion distribution/bin/enso
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ for opt in "$@"; do
done

JAVA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED $JAVA_OPTS"
exec java --module-path $COMP_PATH -Dorg.graalvm.language.enso.home=$COMP_PATH $EXTRA_OPTS $JAVA_OPTS -m org.enso.runtime/org.enso.EngineRunnerBootLoader "$@"
exec java --module-path $COMP_PATH $EXTRA_OPTS $JAVA_OPTS -m org.enso.runtime/org.enso.EngineRunnerBootLoader "$@"
exit
2 changes: 1 addition & 1 deletion distribution/bin/enso.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set EXTRA_OPTS=%EXTRA_OPTS% -Dgraal.Dump=Truffle:1
)
)
set JAVA_OPTS=%JAVA_OPTS% --add-opens=java.base/java.nio=ALL-UNNAMED
java --module-path %comp-dir% -Dorg.graalvm.language.enso.home=%comp-dir% -Dpolyglot.compiler.IterativePartialEscape=true %EXTRA_OPTS% %JAVA_OPTS% -m org.enso.runtime/org.enso.EngineRunnerBootLoader %*
java --module-path %comp-dir% -Dpolyglot.compiler.IterativePartialEscape=true %EXTRA_OPTS% %JAVA_OPTS% -m org.enso.runtime/org.enso.EngineRunnerBootLoader %*
exit /B %errorlevel%
12 changes: 6 additions & 6 deletions docs/infrastructure/native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ For example, to update settings for the Launcher:
java -agentlib:native-image-agent=config-merge-dir=engine/launcher/src/main/resources/META-INF/native-image/org/enso/launcher -jar launcher.jar <arguments>
```

Note that for convenience, you can run the launcher/engine runner via
Note that for convenience, you can run the launcher/engine runtime via
`bin/enso`, e.g.

```bash
Expand Down Expand Up @@ -210,7 +210,7 @@ sbt> engine-runner/buildNativeImage
and execute any program with that binary - for example `test/Base_Tests`

```bash
$ runner --run test/Base_Tests
$ ./built-distribution/enso-engine-*/enso-*/bin/enso --run test/Base_Tests
```

The task that generates the Native Image, along with all the necessary
Expand All @@ -224,7 +224,7 @@ Since [PR-6966](https://github.com/enso-org/enso/pull/6966) there is an
experimental support for including
[Espresso Java interpreter](https://www.graalvm.org/jdk17/reference-manual/java-on-truffle/)
to allow use of some library functions (like `IO.println`) in the _Native Image_
built runner.
built runtime.

The support can be enabled by setting environment variable `ENSO_JAVA=espresso`
and making sure Espresso is installed in the Enso engine `component` directory:
Expand Down Expand Up @@ -278,7 +278,7 @@ Espresso support works also with
`ENSO_JAVA=espresso` is specified when building the `runner` executable:

```bash
enso$ rm runner
enso$ rm ./built-distribution/enso-engine-*/enso-*/bin/enso
enso$ ENSO_JAVA=espresso sbt --java-home /graalvm
sbt> engine-runner/buildNativeImage
```
Expand All @@ -288,7 +288,7 @@ build script detects presence of Espresso and automatically adds
`--language:java` when creating the image. Then you can use

```bash
$ ENSO_JAVA=espresso ./runner --run hello.enso
$ ENSO_JAVA=espresso ./built-distribution/enso-engine-*/enso-*/bin/enso --run hello.enso
```

to execute native image `runner` build of Enso together with Espresso.
to execute native image build of Enso together with Espresso.
Loading

0 comments on commit 515d823

Please sign in to comment.