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 GraalVM distribution download on MacOS #7364

Merged
merged 6 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 5 additions & 7 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ on:

env:
# Please ensure that this is in sync with graalVersion in build.sbt
graalVersion: 22.3.1
# Please ensure that this is in sync with javaVersion in build.sbt
javaVersion: 11
javaVersion: 17.0.7
# Please ensure that this is in sync with project/build.properties
sbtVersion: 1.5.2
sbtVersion: 1.9.0

jobs:
test_formatting:
Expand All @@ -25,11 +23,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup GraalVM Environment
uses: ayltai/setup-graalvm@v1
uses: graalvm/setup-graalvm@v1
with:
graalvm-version: ${{ env.graalVersion }}
java-version: ${{ env.javaVersion }}
native-image: true
distribution: graalvm-community
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set Up SBT
shell: bash
run: |
Expand Down
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,9 @@ lazy val runtime = (project in file("engine/runtime"))
Test / envVars ++= distributionEnvironmentOverrides ++ Map(
"ENSO_TEST_DISABLE_IR_CACHE" -> "false"
),
Global / onLoad := GraalVersionCheck.addVersionCheck(
graalVersion
)((Global / onLoad).value),
bootstrap := CopyTruffleJAR.bootstrapJARs.value
)
.settings(
Expand Down
2 changes: 1 addition & 1 deletion build/build/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn new_repo_root(repo_root: impl Into<PathBuf>, triple: &TargetTriple) -> ge

pub fn pretty_print_arch(arch: Arch) -> &'static str {
match arch {
Arch::X86_64 => "amd64",
Arch::X86_64 => "x64",
Arch::AArch64 => "aarch64",
_ => panic!("Unrecognized architecture {arch}"),
}
Expand Down
2 changes: 1 addition & 1 deletion build/ci_utils/src/cache/goodie/graalvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl GraalVM {
let os_name = match *os {
OS::Linux => "linux",
OS::Windows => "windows",
OS::MacOS => "darwin",
OS::MacOS => "macos",
other_os => unimplemented!("System `{}` is not supported!", other_os),
};
let arch_name = match *arch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object GraalCEReleaseProvider {
def packageFileNameForCurrentOS(version: GraalVMVersion): String = {
val os = OS.operatingSystem match {
case OS.Linux => "linux"
case OS.MacOS => "darwin"
case OS.MacOS => if (version.graalMajorVersion < 23) "darwin" else "macos"
case OS.Windows => "windows"
}
val extension = OS.operatingSystem match {
Expand Down
12 changes: 5 additions & 7 deletions project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ object DistributionPackage {
sealed trait OS {
def name: String
def hasSupportForSulong: Boolean
def graalName: String = name
def executableName(base: String): String = base
def archiveExt: String = ".tar.gz"
def isUNIX: Boolean = true
Expand All @@ -435,7 +434,6 @@ object DistributionPackage {
case object MacOS extends OS {
override val name: String = "macos"
override val hasSupportForSulong: Boolean = true
override def graalName: String = "darwin"
}
case object Windows extends OS {
override val name: String = "windows"
Expand All @@ -461,7 +459,7 @@ object DistributionPackage {
}
object Architecture {
case object X64 extends Architecture {
override def name: String = "amd64"
override def name: String = "x64"
}

val archs = Seq(X64)
Expand Down Expand Up @@ -566,9 +564,9 @@ object DistributionPackage {
)
val graalUrl =
s"https://github.com/graalvm/graalvm-ce-builds/releases/download/" +
s"vm-$graalVersion/" +
s"graalvm-ce-java$graalJavaVersion-${os.graalName}-" +
s"${architecture.name}-$graalVersion${os.archiveExt}"
s"jdk-$graalJavaVersion/" +
s"graalvm-community-jdk-${graalJavaVersion}_${os.name}-" +
s"${architecture.name}_bin${os.archiveExt}"
val exitCode = (url(graalUrl) #> archive).!
if (exitCode != 0) {
throw new RuntimeException(s"Graal download from $graalUrl failed.")
Expand Down Expand Up @@ -614,7 +612,7 @@ object DistributionPackage {
extract(archive, packageDir)

log.info("Installing components")
gu(log, os, extractedGraalDir, "install", "python", "R")
gu(log, os, extractedGraalDir, "install", "python")

log.info(s"Re-creating $archive")
IO.delete(archive)
Expand Down
80 changes: 80 additions & 0 deletions project/GraalVersionCheck.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import java.io.IOException
import sbt.*
import sbt.internal.util.ManagedLogger

import scala.sys.process.*
import nl.gn0s1s.bump.SemVer

object GraalVersionCheck {

/** Compares the version of JVM running sbt with the GraalVM versions defined
* in project configuration and reports errors if the versions do not match.
*
* @param expectedGraalVersionRaw the GraalVM version that should be used for
* building this project
* @param log a logger used to report errors if the versions are mismatched
*/
def graalVersionOk(
expectedGraalVersionRaw: String,
log: ManagedLogger
): Boolean = {
val expectedGraalVersion = SemVer(expectedGraalVersionRaw)
require(expectedGraalVersion.isDefined, "Invalid version string")

val versionProperty = "java.vendor.version"
val rawGraalVersion = System.getProperty(versionProperty)

def graalVersion: Option[SemVer] = {
val versionRegex = """GraalVM (CE|EE) ([\d.]+.*)""".r
rawGraalVersion match {
case versionRegex(_, version) =>
SemVer(version)
case _ => None
}
}

if (rawGraalVersion == null) {
log.error(
s"Property $versionProperty is not defined. " +
s"Make sure your current JVM is set to " +
s"GraalVM $expectedGraalVersionRaw."
)
false
} else {
graalVersion match {
case Some(version)
if expectedGraalVersion.get.withoutBuildMetadata == version.withoutBuildMetadata =>
true
case _ =>
log.error(
s"GraalVM version mismatch - you are running $rawGraalVersion " +
s"but GraalVM $expectedGraalVersionRaw is expected."
)
false
}
}
}

/** Augments a state transition to do a Rust and GraalVM version check.
*
* @param graalVersion the GraalVM version that should be used for
* building this project
* @param oldTransition the state transition to be augmented
* @return an augmented state transition that does all the state changes of
* oldTransition but also runs the version checks
*/
def addVersionCheck(
graalVersion: String
)(
oldTransition: State => State
): State => State =
(state: State) => {
val newState = oldTransition(state)
val logger = newState.log
if (!graalVersionOk(graalVersion, logger)) {
logger.error("GraalVM version check failed.")
System.exit(1)
}
newState
}
}
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ addSbtPlugin("com.simplytyped" % "sbt-antlr4" % "0.8.3")

libraryDependencies += "io.circe" %% "circe-yaml" % "0.14.2"
libraryDependencies += "commons-io" % "commons-io" % "2.12.0"
libraryDependencies += "nl.gn0s1s" %% "bump" % "0.1.3"