Skip to content

Commit

Permalink
Try to support automatic Windows installation.
Browse files Browse the repository at this point in the history
This commits moves to using `gu install native-image` instead of
`coursier launch --jvm graalvm svm`. The second approach doesn't appear
to work well with Java 11.
  • Loading branch information
Olafur Pall Geirsson committed Sep 9, 2020
1 parent decc2b6 commit 566a471
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 76 deletions.
31 changes: 7 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,27 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
java: [8]
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v7
with:
java-version: "adopt@1.${{ matrix.java }}"
- shell: bash
- name: sbt test plugin/scripted
if: ${{ matrix.os }} != windows-latest
shell: bash
run: |
export JABBA=/home/runner/bin/jabba
$JABBA install graalvm@20.1.0
export GRAALVM_HOME=$($JABBA which --home graalvm@20.1.0)
$GRAALVM_HOME/bin/gu install native-image
export NATIVE_IMAGE_COMMAND=$GRAALVM_HOME/bin/native-image
sbt test plugin/scripted
windows:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
steps:
- uses: actions/checkout@v2
- name: Configure Pagefile
uses: al-cheb/configure-pagefile-action@v1.2
- name: Refresh Pagefile
run: |
(Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize
- uses: olafurpg/setup-scala@v7
with:
java-version: graalvm-ce-java11@20.1.0
- name: gu install native-image
shell: bash
run: |
echo $JAVA_HOME
"$JAVA_HOME\bin\gu.cmd" install native-image
- name: sbt test
shell: cmd
if: ${{ matrix.os }} == windows-latest
run: >-
"C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && sbt test
Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && sbt
example/nativeImage
46 changes: 6 additions & 40 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macOS-latest, ubuntu-latest]
os: [macOS-latest, ubuntu-latest, windows-latest]
include:
# Replace "example" with the name your binary
- os: macOS-latest
Expand All @@ -21,53 +21,19 @@ jobs:
- os: ubuntu-latest
artifact: example-x86_64-pc-linux
binary: example/target/native-image/example
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v6
- run: git fetch --tags || true
- run: sbt example/nativeImage
- uses: actions/upload-artifact@master
with:
path: ${{ matrix.binary }}
name: ${{ matrix.artifact }}
- name: Upload release
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ matrix.binary }}
asset_name: ${{ matrix.artifact }}
asset_content_type: application/zip
windows:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
include:
# Replace "example" with the name your binary
- os: windows-latest
artifact: example-x86_64-pc-win32.exe
binary: example\target\native-image\example.exe
steps:
- uses: actions/checkout@v2
- name: Configure Pagefile
uses: al-cheb/configure-pagefile-action@v1.2
- name: Refresh Pagefile
run: |
(Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize
- uses: olafurpg/setup-scala@v7
with:
java-version: graalvm-ce-java11@20.1.0
- name: gu install native-image
- uses: olafurpg/setup-scala@v6
- run: git fetch --tags || true
- run: sbt example/nativeImage
shell: bash
run: |
echo $JAVA_HOME
"$JAVA_HOME\bin\gu.cmd" install native-image
if: ${{ matrix.os }} != windows-latest
- name: sbt test
shell: cmd
if: ${{ matrix.os }} == windows-latest
run: >-
"C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && sbt
Expand Down
37 changes: 25 additions & 12 deletions plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ object NativeImagePlugin extends AutoPlugin {
{ () => this.alertUser(s, "Native image ready!") }
},
mainClass.in(NativeImage) := mainClass.in(Compile).value,
nativeImageJvm := "graalvm",
nativeImageVersion := "19.3.2",
name.in(NativeImage) := name.value,
nativeImageJvm := "graalvm-java11",
nativeImageVersion := "20.1.0",
name.in(NativeImage) := {
val exe = if (Properties.isWin) ".exe" else ""
name.value + exe
},
mainClass.in(NativeImage) := mainClass.in(Compile).value,
nativeImageOptions := List(),
nativeImageCoursier := {
Expand All @@ -109,7 +112,6 @@ object NativeImagePlugin extends AutoPlugin {
},
nativeImageCommand := Def.taskDyn {
if (
Properties.isWin ||
"true".equalsIgnoreCase(System.getProperty("native-image-installed")) ||
"true".equalsIgnoreCase(System.getenv("NATIVE_IMAGE_INSTALLED"))
) {
Expand All @@ -120,15 +122,26 @@ object NativeImagePlugin extends AutoPlugin {
Def.task(List[String](path.toString()))
} else {
Def.task {
val svmVersion = nativeImageVersion.value
List(
nativeImageCoursier.value.absolutePath,
"launch",
"--jvm",
s"${nativeImageJvm.value}:$svmVersion",
s"org.graalvm.nativeimage:svm-driver:$svmVersion",
"--"
val coursier = nativeImageCoursier.value.absolutePath
val svm = nativeImageVersion.value
val jvm = nativeImageJvm.value
val javaHome = Paths.get(
Process(List(coursier, "java-home", "--jvm", s"$jvm:$svm")).!!.trim
)
val cmd = if (Properties.isWin) ".cmd" else ""
val ni = javaHome.resolve("bin").resolve(s"native-image$cmd")
if (!Files.isExecutable(ni)) {
val gu = ni.resolveSibling(s"gu$cmd")
Process(List(gu.toString, "install", "native-image")).!
}
if (!Files.isExecutable(ni)) {
throw new MessageOnlyException(
"Failed to automatically install native-image. " +
"To fix this problem, install native-image manually and start sbt with " +
"the environment variable 'NATIVE_IMAGE_INSTALLED=true'"
)
}
List(ni.toString())
}
}
}.value,
Expand Down

0 comments on commit 566a471

Please sign in to comment.