Skip to content

Commit 237f72d

Browse files
committed
Refactor Build a Shared Library Native Image demo
1 parent 9bbbc1e commit 237f72d

File tree

13 files changed

+34
-137
lines changed

13 files changed

+34
-137
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
name: native-shared-library
1+
name: native-image/build-shared-library
22
on:
33
push:
44
paths:
5-
- 'native-shared-library/**'
6-
- '.github/workflows/native-shared-library.yml'
5+
- 'native-image/build-shared-library/**'
6+
- '.github/workflows/native-image-build-shared-library.yml'
77
pull_request:
88
paths:
9-
- 'native-shared-library/**'
10-
- '.github/workflows/native-shared-library.yml'
9+
- 'native-image/build-shared-library/**'
10+
- '.github/workflows/native-image-build-shared-library.yml'
1111
schedule:
1212
- cron: "0 0 1 * *" # run every month
1313
workflow_dispatch:
1414
permissions:
1515
contents: read
1616
jobs:
1717
run:
18-
name: Run 'native-shared-library'
18+
name: Run 'native-image/build-shared-library'
1919
runs-on: ubuntu-latest
2020
timeout-minutes: 15
2121
strategy:
@@ -29,10 +29,7 @@ jobs:
2929
distribution: 'graalvm'
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
3131
native-image-job-reports: 'true'
32-
- name: Run 'native-shared-library'
32+
- name: Run 'native-image/build-shared-library'
3333
run: |
34-
cd native-shared-library
35-
javac LibEnvMap.java
36-
native-image -o libenvmap --shared
37-
clang -I ./ -L ./ -l envmap -Wl,-rpath ./ -o main main.c
38-
./main USER
34+
cd native-image/build-shared-library
35+
./run.sh

native-image/access-environment-variables/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
$JAVA_HOME/bin/javac EnvMap.java
5-
$JAVA_HOME/bin/native-image -Ob EnvMap
4+
javac EnvMap.java
5+
native-image -Ob EnvMap
66

77
./envmap HELLO
88
export HELLOWORLD='Hello World!'

native-image/add-jfr-support/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
$JAVA_HOME/bin/javac JFRDemo.java
5-
$JAVA_HOME/bin/native-image -Ob --enable-monitoring=jfr JFRDemo
4+
javac JFRDemo.java
5+
native-image -Ob --enable-monitoring=jfr JFRDemo
66
./jfrdemo -XX:StartFlightRecording=filename=recording.jfr
77
jfr print recording.jfr

native-image/add-jmx-support/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
$JAVA_HOME/bin/javac SimpleJmx.java
5-
$JAVA_HOME/bin/native-image -Ob --enable-monitoring=jmxserver,jmxclient,jvmstat -H:DynamicProxyConfigurationFiles=proxy-config.json SimpleJmx
4+
javac SimpleJmx.java
5+
native-image -Ob --enable-monitoring=jmxserver,jmxclient,jvmstat -H:DynamicProxyConfigurationFiles=proxy-config.json SimpleJmx
66
./simplejmx -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=9996 -Dcom.sun.management.jmxremote.ssl=false

native-image/add-logging/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
set -ex
33

44
# Initialize a Logger at Build Time
5-
$JAVA_HOME/bin/javac LoggerBuildTimeInit.java
6-
$JAVA_HOME/bin/native-image -Ob --initialize-at-build-time=LoggerBuildTimeInit LoggerBuildTimeInit
5+
javac LoggerBuildTimeInit.java
6+
native-image -Ob --initialize-at-build-time=LoggerBuildTimeInit LoggerBuildTimeInit
77
./loggerbuildtimeinit
88

99
# Initialize a Logger at Run time
10-
$JAVA_HOME/bin/javac LoggerRunTimeInit.java
11-
$JAVA_HOME/bin/native-image -Ob -H:IncludeResources="logging.properties" LoggerRunTimeInit
10+
javac LoggerRunTimeInit.java
11+
native-image -Ob -H:IncludeResources="logging.properties" LoggerRunTimeInit
1212
./loggerruntimeinit

native-image/build-from-jar/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
$JAVA_HOME/bin/javac -d build src/com/example/App.java
5-
$JAVA_HOME/bin/jar --create --file App.jar --main-class com.example.App -C build .
6-
$JAVA_HOME/bin/native-image -Ob -jar App.jar
4+
javac -d build src/com/example/App.java
5+
jar --create --file App.jar --main-class com.example.App -C build .
6+
native-image -Ob -jar App.jar
77
./App

native-image/build-java-modules/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
set -ex
33

44
mvn --no-transfer-progress package
5-
$JAVA_HOME/bin/java --module-path target/HelloModule-1.0-SNAPSHOT.jar --module HelloModule
6-
$JAVA_HOME/bin/native-image -Ob --module-path target/HelloModule-1.0-SNAPSHOT.jar --module HelloModule
5+
java --module-path target/HelloModule-1.0-SNAPSHOT.jar --module HelloModule
6+
native-image -Ob --module-path target/HelloModule-1.0-SNAPSHOT.jar --module HelloModule
77
./hellomodule
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Build a Native Shared Library
2+
3+
You can find the steps to run this demo on [the website](https://www.graalvm.org/latest/reference-manual/native-image/guides/build-native-shared-library/).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
javac LibEnvMap.java
5+
native-image -o libenvmap --shared
6+
clang -I ./ -L ./ -l envmap -Wl,-rpath ./ -o main main.c
7+
./main USER

native-shared-library/README.md

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)