Skip to content

Commit

Permalink
use GraalVM for JDK 17 & JDK 21
Browse files Browse the repository at this point in the history
  • Loading branch information
chirontt committed Dec 25, 2023
1 parent 0f624ff commit 20770a7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 89 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
java-version: [11, 17]
graalvm-version: ['22.3.3']
java-version: [17, 21]
graalvm-distribution: ['graalvm-community']
fail-fast: false

Expand All @@ -32,20 +31,10 @@ jobs:
restore-keys: ${{ runner.os }}-gradle-

- name: Set up GraalVM ${{ matrix.graalvm-distribution }} for Java ${{ matrix.java-version }}
if: matrix.java-version == 17
uses: graalvm/setup-graalvm@v1
with:
java-version: ${{ matrix.java-version }}
distribution: ${{ matrix.graalvm-distribution }}
components: 'native-image'

- name: Set up GraalVM ${{ matrix.graalvm-version }} for Java ${{ matrix.java-version }}
if: matrix.java-version == 11
uses: graalvm/setup-graalvm@v1
with:
java-version: ${{ matrix.java-version }}
version: ${{ matrix.graalvm-version }}
components: 'native-image'

- name: Report Java version
run: |
Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
java-version: [11, 17]
graalvm-version: ['22.3.3']
java-version: [17, 21]
graalvm-distribution: ['graalvm-community']
fail-fast: false

Expand All @@ -22,20 +21,10 @@ jobs:
uses: actions/checkout@v3

- name: Set up GraalVM ${{ matrix.graalvm-distribution }} for Java ${{ matrix.java-version }}
if: matrix.java-version == 17
uses: graalvm/setup-graalvm@v1
with:
java-version: ${{ matrix.java-version }}
distribution: ${{ matrix.graalvm-distribution }}
components: 'native-image'

- name: Set up GraalVM ${{ matrix.graalvm-version }} for Java ${{ matrix.java-version }}
if: matrix.java-version == 11
uses: graalvm/setup-graalvm@v1
with:
java-version: ${{ matrix.java-version }}
version: ${{ matrix.graalvm-version }}
components: 'native-image'

- name: Report Java version
run: |
Expand All @@ -52,22 +41,22 @@ jobs:

- name: Package Linux artifact
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lwjgl3-helloworld ${{ runner.os }} native image with SubstrateVM Java ${{ matrix.java-version }}
path: target/native-image-linux/lwjgl3-helloworld**
path: target/lwjgl3-helloworld

- name: Package MacOS artifact
if: runner.os == 'macOS'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lwjgl3-helloworld ${{ runner.os }} native image with SubstrateVM Java ${{ matrix.java-version }}
path: target/native-image-macos/lwjgl3-helloworld*
path: target/lwjgl3-helloworld

- name: Package Windows artifact
if: runner.os == 'Windows'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lwjgl3-helloworld ${{ runner.os }} native image with SubstrateVM Java ${{ matrix.java-version }}
path: target/native-image-windows/lwjgl3-helloworld.exe
path: target/lwjgl3-helloworld.exe

2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
33 changes: 3 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'application'
id 'org.graalvm.buildtools.native' version '0.9.25'
id 'org.graalvm.buildtools.native' version '0.9.28'
id 'com.google.osdetector' version '1.7.3'
}

tasks.wrapper {
gradleVersion = '8.3'
gradleVersion = '8.5'
distributionType = Wrapper.DistributionType.ALL
}

Expand Down Expand Up @@ -43,7 +43,6 @@ ext {

mainClassName = 'com.github.chirontt.lwjgl.demo.HelloWorld'
currentPlatform = getCurrentPlatform()
nativeImageDirName = "native-image-$currentPlatform"
}

repositories {
Expand Down Expand Up @@ -129,29 +128,6 @@ task uberJar(type: Jar) {
duplicatesStrategy 'exclude'
}

//remove unneeded .dll/.txt files
task removeUnneededDllFiles {
doLast {
if (file("$buildDir/$nativeImageDirName").exists()) {
ant.move(todir: "$buildDir/tmp/$nativeImageDirName") {
fileset(dir: "$buildDir/$nativeImageDirName") {
include name: '*.dll'
include name: '*.pdb'
include name: '*.txt'
}
}
}
if (file("$buildDir/$nativeImageDirName/reports").exists()) {
ant.move(file: "$buildDir/$nativeImageDirName/reports",
tofile: "$buildDir/tmp/$nativeImageDirName/reports")
}
if (file("$buildDir/$nativeImageDirName/sources").exists()) {
ant.move(file: "$buildDir/$nativeImageDirName/sources",
tofile: "$buildDir/tmp/$nativeImageDirName/sources")
}
}
}

graalvmNative {
toolchainDetection = false
binaries {
Expand All @@ -164,9 +140,7 @@ graalvmNative {

buildArgs.add('--initialize-at-run-time=org.lwjgl')
buildArgs.add('--native-image-info')
//buildArgs.add('-march=native') //only available in GraalVM for JDK 17+
buildArgs.add("-H:Path=$buildDir/$nativeImageDirName")
buildArgs.add("-H:TempDirectory=$buildDir/tmp/$nativeImageDirName")
buildArgs.add('-march=compatibility') //only available in GraalVM for JDK 17+
//buildArgs.add('-H:+TraceNativeToolUsage')

useFatJar = false
Expand All @@ -181,6 +155,5 @@ tasks.named("nativeCompile") {
//use the uber jar if long classpath becomes a problem in Windows:
//dependsOn uberJar
//classpathJar = uberJar.archiveFile
finalizedBy removeUnneededDllFiles
}

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
21 changes: 3 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
<maven.shade.plugin.version>3.5.0</maven.shade.plugin.version>
<lwjgl.version>3.3.3-SNAPSHOT</lwjgl.version>
<native.maven.plugin.version>0.9.25</native.maven.plugin.version>
<native.image.dir.name>native-image-${platform}</native.image.dir.name>
<native.maven.plugin.version>0.9.28</native.maven.plugin.version>
<exec.mainClass>com.github.chirontt.lwjgl.demo.HelloWorld</exec.mainClass>
<!-- system properties for the application when run by exec:exec command;
can be specified on the command line with -Dsys.props="..."
Expand Down Expand Up @@ -216,7 +215,6 @@
</execution>
</executions>
<configuration>
<!-- outputDir>${project.build.directory}/${native.image.dir.name}</outputDir -->
<imageName>${project.name}</imageName>
<mainClass>${exec.mainClass}</mainClass>
<metadataRepository>
Expand All @@ -227,10 +225,8 @@
<buildArg>--initialize-at-run-time=org.lwjgl</buildArg>
<buildArg>--native-image-info</buildArg>
<buildArg>--verbose</buildArg>
<!-- buildArg>-march=native</buildArg --> <!-- only available in GraalVM for JDK 17+ -->
<buildArg>-march=compatibility</buildArg> <!-- only available in GraalVM for JDK 17+ -->
<!-- buildArg>-H:+TraceNativeToolUsage</buildArg -->
<buildArg>-H:TempDirectory=${project.build.directory}/tmp/${native.image.dir.name}</buildArg>
<buildArg>-H:Path=${project.build.directory}/${native.image.dir.name}</buildArg>
</buildArgs>
<skip>false</skip>
<!-- use the uber jar for native image compiling
Expand All @@ -250,7 +246,7 @@
<version>3.1.0</version>
<executions>
<execution>
<id>remove-unneeded-dll-files</id>
<id>fix-uber-jar-manifest</id>
<phase>package</phase>
<goals>
<goal>run</goal>
Expand All @@ -269,17 +265,6 @@
<attribute name="Main-Class" value="${exec.mainClass}"/>
</manifest>
</jar>
<move todir="${project.build.directory}/tmp/${native.image.dir.name}"
failonerror="false" quiet="true">
<fileset dir="${project.build.directory}/${native.image.dir.name}">
<include name="*.dll"/>
<include name="*.pdb"/>
<include name="*.txt"/>
</fileset>
</move>
<move file="${project.build.directory}/${native.image.dir.name}/reports"
tofile="${project.build.directory}/tmp/${native.image.dir.name}/reports"
failonerror="false" quiet="true"/>
</target>
</configuration>
</plugin>
Expand Down

0 comments on commit 20770a7

Please sign in to comment.