Skip to content

Commit

Permalink
Merge pull request #126 from Peefy/feat-kotlin-lib
Browse files Browse the repository at this point in the history
feat: add kcl kotlin lib and tests
  • Loading branch information
Peefy authored Jul 28, 2024
2 parents 8facb02 + 5ed1486 commit 082b057
Show file tree
Hide file tree
Showing 43 changed files with 75,707 additions and 1 deletion.
181 changes: 181 additions & 0 deletions .github/workflows/kotlin-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: kotlin-test

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
paths:
- "kotlin/**"
- ".github/workflows/kotlin-test.yaml"
workflow_dispatch:

jobs:
test-and-build:
permissions:
actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
contents: read # for actions/checkout to fetch code
name: "${{ matrix.root-pom }} on JDK ${{ matrix.java }} for the classifier ${{ matrix.classifier }}"
strategy:
matrix:
include:
- os: ubuntu-latest
classifier: linux-aarch_64
java: 8
root-pom: 'pom.xml'
- os: windows-latest
classifier: windows-x86_64
java: 8
root-pom: 'pom.xml'
- os: macos-latest
classifier: osx-x86_64
java: 8
root-pom: 'pom.xml'
- os: macos-latest
classifier: osx-aarch_64
java: 8
root-pom: 'pom.xml'
runs-on: ${{ matrix.os }}
env:
ROOT_POM: ${{ matrix.root-pom }}
steps:
- uses: actions/checkout@v4

- name: 'Set up JDK ${{ matrix.java }}'
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
cache: 'maven'

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.79
override: true
components: clippy, rustfmt

- name: Setup linux-aarch_64 rust target
if: "contains(matrix.classifier, 'linux-aarch_64')"
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
# Setup for cargo
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: 'Test'
shell: bash
working-directory: kotlin
run: make test

- name: 'Build and Deploy'
shell: bash
working-directory: kotlin
run: mvn clean package -DskipTests=true -Djni.classifier=${{ matrix.classifier }} -Dcargo-build.profile=release

- name: 'Upload artifact'
uses: actions/upload-artifact@v3
with:
name: kcl-lib-${{ matrix.classifier }}
path: |
kotlin/target/classes/native
build-centos7:
runs-on: ubuntu-latest
container:
image: "kcllang/kcl-java-builder-centos7:0.1.0"

permissions:
contents: read
packages: write
needs: [ test-and-build ]
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download windows x86_64 lib
uses: actions/download-artifact@v3
with:
name: kcl-lib-windows-x86_64
path: kotlin/native

- name: Download linux aarch_64 lib
uses: actions/download-artifact@v3
with:
name: kcl-lib-linux-aarch_64
path: kotlin/native

- name: Download darwin x86_64 lib
uses: actions/download-artifact@v3
with:
name: kcl-lib-osx-x86_64
path: kotlin/native

- name: Download darwin aarch_64 lib
uses: actions/download-artifact@v3
with:
name: kcl-lib-osx-aarch_64
path: kotlin/native

- name: Package Kotlin artifact
working-directory: kotlin
run: |
rustup default stable && mvn package -DskipTests=true -Dcargo-build.profile=release
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: kcl-lib
path: kotlin/target/*.jar

deploy:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
needs: [ test-and-build, build-centos7 ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Download Jar
uses: actions/download-artifact@v3
with:
name: kcl-lib
path: kotlin/release

- name: Release to Github Packages
if: "startsWith(github.ref, 'refs/tags/')"
working-directory: kotlin
run: |
JAR_FILE=$(find ./release -name "*.jar" ! -name "*sources.jar")
echo "Deploying $JAR_FILE"
mvn deploy:deploy-file \
-Dfile=$JAR_FILE \
-DpomFile=./pom.xml \
-DrepositoryId=github \
-Durl=https://maven.pkg.github.com/kcl-lang/lib \
-s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ _a.out_*.*
**/.DS_Store
**/.vscode
__pycache__
build
23 changes: 23 additions & 0 deletions kotlin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "kcl-lib-jni"
publish = false
version = "0.1.0"

[lib]
crate-type = ["cdylib"]
doc = false

[dependencies]
jni = "0.21.1"
prost = "0.11.8"
prost-types = "0.11.8"
serde_json = "1"
indexmap = "2.2.5"
anyhow = "1"
serde = { version = "1", features = ["derive"] }
once_cell = "1.19.0"
lazy_static = "1.4.0"

kclvm-parser = { git = "https://github.com/kcl-lang/kcl", version = "0.10.0-alpha.1" }
kclvm-sema = { git = "https://github.com/kcl-lang/kcl", version = "0.10.0-alpha.1" }
kclvm-api = { git = "https://github.com/kcl-lang/kcl", version = "0.10.0-alpha.1" }
13 changes: 13 additions & 0 deletions kotlin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default: build

build:
mvn clean install -e -DskipTests -Dcargo-build.profile=release

pkg:
mvn clean package -Dcargo-build.profile=release

deploy:
mvn clean deploy -Dcargo-build.profile=release

test:
mvn clean test -Dcargo-build.profile=release
Loading

0 comments on commit 082b057

Please sign in to comment.