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

Fix bundled GraalVM path #7948

Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import java.io.File
// ============================================================================

val scalacVersion = "2.13.11"
// Since the release of GraalVM 23.0.0, the versioning is the same for Graal and OpenJDK.
val graalVersion = "17.0.7"
val graalVersion = "17.0.7"
Copy link
Member

Choose a reason for hiding this comment

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

Note that the newest Graal (PR is at #7991) does not have minor or patch version. It is just 21:

> java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)
OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

// Version used for the Graal/Truffle related Maven packages
val graalMavenPackagesVersion = "23.0.0"
val targetJavaVersion = graalVersion.split("\\.")(0)
Expand Down
12 changes: 12 additions & 0 deletions build/build/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::prelude::*;

use crate::get_graal_packages_version;
use crate::get_graal_version;
use crate::paths::generated;

Expand All @@ -26,6 +27,7 @@ pub mod env;
pub mod package;
pub mod sbt;

use crate::engine::bundle::GraalVmVersion;
pub use context::RunContext;


Expand Down Expand Up @@ -310,3 +312,13 @@ pub async fn deduce_graal(
arch: TARGET_ARCH,
})
}

pub async fn deduce_graal_bundle(
build_sbt: &generated::RepoRootBuildSbt,
) -> Result<GraalVmVersion> {
let build_sbt_content = ide_ci::fs::tokio::read_to_string(build_sbt).await?;
Ok(GraalVmVersion {
graal: get_graal_version(&build_sbt_content)?,
packages: get_graal_packages_version(&build_sbt_content)?,
})
}
26 changes: 22 additions & 4 deletions build/build/src/engine/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ use ide_ci::cache::goodie::graalvm::locate_graal;



/// Version of the bundled GraalVM.
#[derive(Clone, Debug)]
pub struct GraalVmVersion {
/// Version of the GraalVM runtime. Corresponds to the `graalVersion` in build.sbt.
pub graal: Version,
/// Version of the Maven packages. Corresponds to the `graalMavenPackagesVersion` in build.sbt.
pub packages: Version,
4e6 marked this conversation as resolved.
Show resolved Hide resolved
}

/// Bundle is like a [package][crate::paths::IsPackage] but with additional components bundled to
/// make it redistributable.
///
Expand Down Expand Up @@ -42,14 +51,19 @@ pub trait IsBundle: AsRef<Path> + IsArtifact {
/// ```text
/// H:\NBO\enso\built-distribution\enso-engine-0.0.0-SNAPSHOT.2022-01-19-windows-amd64\enso-0.0.0-SNAPSHOT.2022-01-19
/// ```
fn create(&self, repo_root: &RepoRoot) -> BoxFuture<'static, Result> {
fn create(
&self,
repo_root: &RepoRoot,
graal_version: &GraalVmVersion,
) -> BoxFuture<'static, Result> {
let bundle_dir = self.as_ref().to_path_buf();
let base_component = self.base_component(repo_root);
let engine_src_path =
repo_root.built_distribution.enso_engine_triple.engine_package.clone();
let engine_target_dir = self.engine_dir();
let graalvm_dir = self.graalvm_dir();
let distribution_marker = self.distribution_marker();
let graalvm_version = graal_version.clone();

async move {
ide_ci::fs::tokio::remove_dir_if_exists(&bundle_dir).await?;
Expand All @@ -58,7 +72,7 @@ pub trait IsBundle: AsRef<Path> + IsArtifact {
// Add engine.
ide_ci::fs::mirror_directory(&engine_src_path, &engine_target_dir).await?;
// Add GraalVM runtime.
place_graal_under(graalvm_dir).await?;
place_graal_under(graalvm_dir, &graalvm_version).await?;
// Add portable distribution marker.
ide_ci::fs::create(distribution_marker)?;
Ok(())
Expand Down Expand Up @@ -111,8 +125,12 @@ impl IsBundle for crate::paths::generated::LauncherBundle {
///
/// The GraalVM installation will be located using [`locate_graal`] function.
#[context("Failed to place a GraalVM package under {}.", target_directory.as_ref().display())]
pub async fn place_graal_under(target_directory: impl AsRef<Path>) -> Result {
pub async fn place_graal_under(
target_directory: impl AsRef<Path>,
graal_version: &GraalVmVersion,
) -> Result {
let graal_path = locate_graal()?;
let graal_dirname = graal_path.try_file_name()?;
let graal_dirname =
format!("graalvm-ce-java{}-{}", graal_version.graal, graal_version.packages);
ide_ci::fs::mirror_directory(&graal_path, target_directory.as_ref().join(graal_dirname)).await
}
3 changes: 2 additions & 1 deletion build/build/src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,9 @@ impl RunContext {
}
}

let graal_version = crate::engine::deduce_graal_bundle(&self.repo_root.build_sbt).await?;
for bundle in ret.bundles() {
bundle.create(&self.repo_root).await?;
bundle.create(&self.repo_root, &graal_version).await?;
}

Ok(ret)
Expand Down
5 changes: 5 additions & 0 deletions build/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ pub fn get_graal_version(build_sbt_contents: &str) -> Result<Version> {
get_string_assignment_value(build_sbt_contents, "graalVersion")?.parse2()
}

/// Get version of GraalVM packages from the `build.sbt` file contents.
pub fn get_graal_packages_version(build_sbt_contents: &str) -> Result<Version> {
get_string_assignment_value(build_sbt_contents, "graalMavenPackagesVersion")?.parse2()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 4 additions & 3 deletions build/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use anyhow::Context;
use arg::BuildDescription;
use clap::Parser;
use derivative::Derivative;
use enso_build::config::Config;
use enso_build::context::BuildContext;
use enso_build::engine::context::EnginePackageProvider;
use enso_build::engine::Benchmarks;
Expand Down Expand Up @@ -795,11 +796,11 @@ impl WatchResolvable for Gui {
}

#[tracing::instrument(err, skip(config))]
pub async fn main_internal(config: Option<enso_build::config::Config>) -> Result {
pub async fn main_internal(config: Option<Config>) -> Result {
trace!("Starting the build process.");
let config = config.unwrap_or_else(|| {
warn!("No config provided, using default config.");
enso_build::config::Config::default()
Config::default()
});

trace!("Creating the build context.");
Expand Down Expand Up @@ -958,7 +959,7 @@ pub async fn main_internal(config: Option<enso_build::config::Config>) -> Result
Ok(())
}

pub fn lib_main(config: Option<enso_build::config::Config>) -> Result {
pub fn lib_main(config: Option<Config>) -> Result {
trace!("Starting the tokio runtime.");
let rt = tokio::runtime::Runtime::new()?;
trace!("Entering main.");
Expand Down
16 changes: 12 additions & 4 deletions project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ object DistributionPackage {
if (!packageDir.exists()) {
IO.createDirectory(packageDir)
}
val archiveName = s"graalvm-${os.name}-${architecture.name}-" +
s"$graalVersion-$graalJavaVersion"
val archiveName =
s"graalvm-${os.name}-${architecture.name}-$graalVersion-$graalJavaVersion"
packageDir / (archiveName + os.archiveExt)
}

Expand Down Expand Up @@ -848,7 +848,11 @@ object DistributionPackage {
if (launcher.exists()) {
fixLauncher(launcher, os)
copyEngine(os, arch, launcher / "enso" / "dist")
copyGraal(os, arch, launcher / "enso" / "runtime")
copyGraal(
os,
arch,
launcher / "enso" / "runtime" / s"graalvm-ce-java$graalJavaVersion-$graalVersion/"
)

val archive = builtArchive("bundle", os, arch)
makeArchive(launcher, "enso", archive)
Expand All @@ -866,7 +870,11 @@ object DistributionPackage {
}

copyEngine(os, arch, pm / "enso" / "dist")
copyGraal(os, arch, pm / "enso" / "runtime")
copyGraal(
os,
arch,
pm / "enso" / "runtime" / s"graalvm-ce-java$graalJavaVersion-$graalVersion/"
)

IO.copyFile(
file("distribution/enso.bundle.template"),
Expand Down