Skip to content

Commit

Permalink
feat(compiler): add aqua native compilation (#681)
Browse files Browse the repository at this point in the history
* feat(compiler): add aqua native compilation
  • Loading branch information
gurinderu authored Mar 7, 2023
1 parent 95c0ec5 commit 5f4808b
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Publish binary aqua"

on:
workflow_dispatch:
inputs:
runs-on:
type: string
required: true
arch:
type: string
required: true
os:
type: string
required: true
static:
type: boolean
required: true
workflow_call:
inputs:
runs-on:
type: string
required: true
arch:
type: string
required: true
os:
type: string
required: true
static:
type: boolean
required: true

jobs:
build:
name: "Publish aqua-native"
runs-on: ${{ inputs.runs-on }}
timeout-minutes: 10

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
set-java-home: true
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: coursier/cache-action@v6

- uses: coursier/setup-action@v1
with:
apps: sbt

- name: build
run: sbt "cli/GraalVMNativeImage/packageBin"
env:
COMPILE_STATIC: ${{ inputs.static }}

- uses: actions/upload-artifact@v3
with:
name: aqua-${{ inputs.os }}-${{ inputs.arch }}
path: cli/cli/.jvm/target/graalvm-native-image/cli
22 changes: 22 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,25 @@ jobs:
- name: Publish to NPM registry
run: npm publish --access public --tag unstable
working-directory: language-server/language-server-npm

aqua-native:
name: "Publish aqua-native"
strategy:
matrix:
runner:
- runs-on: ubuntu-latest
arch: amd64
os: linux
static: true
- runs-on: macos-latest
arch: amd64
os: macos
static: false
needs:
- compile
uses: ./.github/workflows/binary.yml
with:
runs-on: ${{ matrix.runner.runs-on }}
arch: ${{ matrix.runner.arch }}
os: ${{ matrix.runner.os }}
static: ${{ matrix.runner.static }}
16 changes: 16 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,19 @@ jobs:
with:
working-directory: language-server/language-server-npm
id: ${{ steps.version.outputs.id }}
aqua-native:
strategy:
matrix:
runner:
- runs-on: ubuntu-latest
arch: amd64
os: linux
static: true
needs:
- compile
uses: ./.github/workflows/binary.yml
with:
runs-on: ${{ matrix.runner.runs-on }}
arch: ${{ matrix.runner.arch }}
os: ${{ matrix.runner.os }}
static: ${{ matrix.runner.static }}
15 changes: 15 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,23 @@ lazy val cli = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("cli/cli"))
.enablePlugins(GraalVMNativeImagePlugin)
.settings(commons: _*)
.settings(
Compile / mainClass := Some("aqua.AquaCli"),
graalVMNativeImageOptions ++= Seq(
"--no-fallback",
"--diagnostics-mode",
"--initialize-at-build-time",
"--initialize-at-run-time=scala.util.Random$",
"-H:-DeleteLocalSymbols",
"-H:+PreserveFramePointer",
"-H:+ReportExceptionStackTraces",
"-H:+DashboardHeap",
"-H:+DashboardCode",
"-H:+DashboardPointsTo",
"-H:+DashboardAll"
) ++ sys.env.get("COMPILE_STATIC").filter(_.trim.toLowerCase() == "true").map(_ => Seq("--static")).getOrElse(Seq.empty),
libraryDependencies ++= Seq(
"com.monovore" %%% "decline" % declineV,
"com.monovore" %%% "decline-effect" % declineV
Expand Down
32 changes: 32 additions & 0 deletions cli/cli/src/main/resources/META-INF/native-image/jni-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"name":"aqua.AquaCli",
"methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }]
},
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.InternalError",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.String",
"methods":[
{"name":"lastIndexOf","parameterTypes":["int"] },
{"name":"substring","parameterTypes":["int"] }
]
},
{
"name":"java.lang.System",
"methods":[
{"name":"getProperty","parameterTypes":["java.lang.String"] },
{"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }
]
},
{
"name":"java.util.Arrays",
"methods":[{"name":"asList","parameterTypes":["java.lang.Object[]"] }]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"interfaces":["sun.misc.SignalHandler"]
}
]
Loading

0 comments on commit 5f4808b

Please sign in to comment.