Skip to content

Commit

Permalink
native image
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Jan 14, 2024
1 parent 71dde31 commit 46274e8
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 2,062 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
distribution: 'temurin'
java-version: '21'
- name: Use Node.js
uses: actions/setup-node@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nodejstests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
- run: |
sbt stage assembly createDistribution
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
- name: build
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
distribution: 'temurin'
java-version: '21'
- name: Release
run: |
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ jobs:
path: 'repotests/django-DefectDojo'
- uses: coursier/cache-action@v6
- name: Set up JDK
uses: actions/setup-java@v4
uses: graalvm/setup-graalvm@v1
with:
distribution: 'zulu'
distribution: 'graalvm-community'
java-version: '21'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
components: 'native-image'
cache: 'sbt'
- run: |
sbt stage astGenDlTask
./atom.sh --remove-atom -o /tmp/java.atom -l java $GITHUB_WORKSPACE/repotests/shiftleft-java-example -Dlog4j.configurationFile=log4j2.xml
Expand Down Expand Up @@ -70,3 +74,8 @@ jobs:
env:
JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
if: runner.os != 'Windows'
- run: |
bash ci/native-image.sh
env:
JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
shell: bash
22 changes: 18 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ jobs:
fetch-depth: 0
- uses: coursier/cache-action@v6
- name: Set up JDK
uses: actions/setup-java@v4
uses: graalvm/setup-graalvm@v1
with:
distribution: 'zulu'
distribution: 'graalvm-community'
java-version: '21'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
components: 'native-image'
cache: 'sbt'
- run: |
sbt stage astGenDlTask assembly createDistribution
sha512sum target/atom.zip > target/atom.zip.sha512
bash ci/native-image.sh
cp target/graalvm-native-image/atom target/graalvm-native-image/c2atom
sha512sum target/graalvm-native-image/c2atom > target/graalvm-native-image/c2atom.sha512
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: sbt publish
Expand All @@ -38,10 +45,15 @@ jobs:
run: |
cd target
echo $GITHUB_TOKEN | oras login ghcr.io -u $GITHUB_USERNAME --password-stdin
oras push ghcr.io/$IMAGE_NAME:v1 \
--annotation-file ../ci/annotations.json \
oras push ghcr.io/$IMAGE_NAME:v2 \
--artifact-type application/vnd.oras.config.v1+json \
./atom.zip:application/vnd.appthreat.atom.layer.v1+tar \
./atom.zip.sha512:application/vnd.appthreat.atom.layer.v1+tar
cd graalvm-native-image
oras push ghcr.io/appthreat/c2atom:v2 \
--artifact-type application/vnd.oras.config.v1+json \
./c2atom:application/vnd.appthreat.atom.layer.v1+tar \
./c2atom.sha512:application/vnd.appthreat.atom.layer.v1+tar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: ${{ github.actor }}
Expand All @@ -52,3 +64,5 @@ jobs:
files: |
target/atom.zip
target/atom.zip.sha512
target/graalvm-native-image/c2atom
target/graalvm-native-image/c2atom.sha512
2 changes: 1 addition & 1 deletion .github/workflows/repotests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ bash build.sh && sudo npm install -g .
chennai> importAtom("/home/almalinux/work/sandbox/apollo/app.atom")
```

## Generating Java 21 native-image

[native-image](https://www.graalvm.org/latest/reference-manual/native-image/) generation for atom is possible. We have tested the generation with both graalce and graal versions for the following languages.

- C/C++/h

```shell
sdk use java 21.0.1-graalce
git clone https://github.com/AppThreat/atom
cd atom
git checkout release/2.x
bash ci/native-image.sh
./target/graalvm-native-image/atom --help
./target/graalvm-native-image/atom -l c -o app.atom .
```

We will add support for more languages over time.

## Enterprise support

Enterprise support including custom language development and integration services is available via AppThreat Ltd. Free community support is also available via [discord](https://discord.gg/tmmtjCEHNV).
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ThisBuild / organization := "io.appthreat"
ThisBuild / version := "2.0.1"
ThisBuild / scalaVersion := "3.3.1"

val chenVersion = "2.0.1"
val chenVersion = "2.0.2"

lazy val atom = Projects.atom

Expand All @@ -12,7 +12,7 @@ val astGenVersion = "3.5.0"
libraryDependencies ++= Seq(
"com.github.pathikrit" %% "better-files" % "3.9.2",
"com.github.scopt" %% "scopt" % "4.1.0",
"org.slf4j" % "slf4j-simple" % "2.0.11" % Optional,
"org.slf4j" % "slf4j-nop" % "2.0.11" % Optional,
"io.appthreat" %% "c2cpg" % Versions.chen excludeAll (
ExclusionRule(organization = "com.ibm.icu", name = "icu4j"),
ExclusionRule(organization = "org.jline", name = "jline"),
Expand Down
2 changes: 2 additions & 0 deletions ci/native-image.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
# bash ci/native-image.sh

# sdk use java 21.0.1-graalce

echo "About to build the native image. This would take a few minutes ..."
sbt "GraalVMNativeImage / packageBin"

Expand Down
2 changes: 2 additions & 0 deletions ci/trace-native-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# bash ci/trace-native-image.sh py <file path>
# bash ci/trace-native-image.sh c <file path>

# sdk use java 21.0.1-graalce

sbt clean stage
./atom.sh -J-agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image reachables -l $1 -o /tmp/app.atom -s /tmp/reachables.slices.json $2

Expand Down
Loading

0 comments on commit 46274e8

Please sign in to comment.