Skip to content

Commit

Permalink
Merge pull request #311 from graalvm/ni-demos-refactoring-8
Browse files Browse the repository at this point in the history
[GR-60094] Refactor fortune-demo and move under native-image/native-build-tools.
  • Loading branch information
olyagpl authored Dec 13, 2024
2 parents 1db1c68 + 531d93c commit 6bdb404
Show file tree
Hide file tree
Showing 27 changed files with 752 additions and 215 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: fortune-demo
name: native-build-tools-gradle
on:
push:
paths:
- 'fortune-demo/**'
- '.github/workflows/fortune-demo.yml'
- 'native-image/native-build-tools/gradle-plugin/**'
- '.github/workflows/native-build-tools-gradle.yml'
pull_request:
paths:
- 'fortune-demo/**'
- '.github/workflows/fortune-demo.yml'
- 'native-image/native-build-tools/gradle-plugin/**'
- '.github/workflows/native-build-tools-gradle.yml'
schedule:
- cron: "0 0 1 * *" # run every month
workflow_dispatch:
permissions:
contents: read
jobs:
run:
name: Run 'fortune-demo'
name: Run 'native-build-tools-gradle'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand All @@ -25,11 +25,7 @@ jobs:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run 'fortune'
- name: Run 'native-build-tools-gradle'
run: |
cd fortune-demo/fortune-maven
./build.sh
- name: Run 'fortune-gradle'
run: |
cd fortune-demo/fortune-gradle
./build.sh
cd native-image/native-build-tools/gradle-plugin
./run.sh
31 changes: 31 additions & 0 deletions .github/workflows/native-build-tools-maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: native-build-tools-maven
on:
push:
paths:
- 'native-image/native-build-tools/maven-plugin/**'
- '.github/workflows/native-build-tools-maven.yml'
pull_request:
paths:
- 'native-image/native-build-tools/maven-plugin/**'
- '.github/workflows/native-build-tools-maven.yml'
schedule:
- cron: "0 0 1 * *" # run every month
workflow_dispatch:
permissions:
contents: read
jobs:
run:
name: Run 'native-build-tools-maven'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '24-ea'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run 'native-build-tools-maven'
run: |
cd native-image/native-build-tools/maven-plugin
./run.sh
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ cd graalvm-demos
<td align="left" width="30%"><a href="/java-simple-stream-benchmark/">java-simple-stream-benchmark</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/java-simple-stream-benchmark.yml"><img alt="java-simple-stream-benchmark" src="https://github.com/graalvm/graalvm-demos/actions/workflows/java-simple-stream-benchmark.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how the Graal compiler can achieve better performance for highly abstracted programs like those using Streams, Lambdas<br><strong>Technologies: </strong>Graal compiler, C2<br><strong>Reference: </strong><a href="https://luna.oracle.com/lab/d502417b-df66-45be-9fed-a3ac8e3f09b1/steps#task-2-run-demos-java-microbenchmark-harness-jmh">Simple Java Stream Benchmark</a></td>
</tr>
<tr>
<td align="left" width="30%"><a href="/fortune-demo/">fortune-demo</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/fortune-demo.yml"><img alt="fortune-demo" src="https://github.com/graalvm/graalvm-demos/actions/workflows/fortune-demo.yml/badge.svg" /></a></td>
<td align="left" width="70%">A fortune teller Unix program. Build a native executable using Gradle or Maven Native Image plugins.<br><strong>Technologies: </strong>Native Image, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://graalvm.github.io/native-build-tools/latest/maven-plugin-quickstart.html">Getting Started with Maven Plugin for GraalVM Native Image</a></td>
</tr>
<tr>
<td align="left" width="30%"><a href="/multithreading-demo/">multithreading-demo</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml"><img alt="streams" src="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to optimize a Java application that does synchronous and asynchronous threads execution<br><strong>Technologies: </strong>Native Image Build Reports, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://medium.com/graalvm/making-sense-of-native-image-contents-741a688dab4d">Making sense of Native Image contents</a></td>
Expand Down
64 changes: 0 additions & 64 deletions fortune-demo/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions fortune-demo/fortune-gradle/build.sh

This file was deleted.

9 changes: 0 additions & 9 deletions fortune-demo/fortune-maven/build.sh

This file was deleted.

77 changes: 0 additions & 77 deletions fortune-demo/fortune-maven/pom.xml

This file was deleted.

23 changes: 23 additions & 0 deletions native-image/native-build-tools/gradle-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use Gradle to Build a Java Application from a Java Application

The demo application simulates the traditional [fortune](https://en.wikipedia.org/wiki/Fortune_(Unix)) Unix program.
The data for the fortune phrases is provided by [YourFortune](https://github.com/your-fortune).

The project uses the [Gradle plugin for GraalVM Native Image building](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html).

## Run the Demo

1. Run the application on JVM:
```bash
./gradlew run
```
2. Build a native executable:
```bash
./gradlew nativeRun
```
The `nativeRun` task compiles the application, invokes `nativeCompile`, and then runs the executable.
3. Re-run the application from the native executable:
```bash
./build/native/nativeCompile/fortune
```
Alternatively, you can execute `./run.sh` to build and run the application.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'org.graalvm.buildtools.native' version '0.10.2'
id 'org.graalvm.buildtools.native' version '0.10.3'
}

repositories {
Expand All @@ -36,6 +36,7 @@ graalvmNative {
binaries {
main {
imageName.set('fortune')
buildArgs.add("-Ob")
}
}
toolchainDetection = false
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions native-image/native-build-tools/gradle-plugin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -ex

# Run the application on the JVM
./gradlew clean run
# Build and run a native executable (`nativeRun` compiles the application, invokes `nativeCompile`, and then runs the executable)
./gradlew nativeRun
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# 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.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
8 changes: 8 additions & 0 deletions native-image/native-build-tools/maven-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Use Maven to Build a Java Application from a Java Application

The demo application simulates the traditional [fortune](https://en.wikipedia.org/wiki/Fortune_(Unix)) Unix program.
The data for the fortune phrases is provided by [YourFortune](https://github.com/your-fortune).

The project uses the [Maven plugin for GraalVM Native Image building](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html).

You can find the steps to run this demo in the [Optimize a Native Executable for File Size guide](https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-for-file-size/).
Loading

0 comments on commit 6bdb404

Please sign in to comment.