Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,35 @@ jobs:
- uses: ./.github/workflows/tests/swift

##### KOTLIN BUILD #####
kotlin_windows:
needs: [setup_config]
runs-on: "windows-2022"
steps:
- uses: actions/checkout@v4
with:
lfs: true
- run: git lfs pull
- uses: ./.github/workflows/kotlin/kotlin-windows

kotlin_macos:
needs: [setup_config]
runs-on: "macos-15"
steps:
- uses: actions/checkout@v4
with:
lfs: true
- run: git lfs pull
- uses: ./.github/workflows/kotlin/kotlin-macos

build_kotlin:
needs: setup_config
needs: [setup_config, kotlin_macos, kotlin_windows ]
runs-on: "ubuntu-22.04"
steps:
- uses: actions/checkout@v4
with:
lfs: true
- run: git lfs pull
- uses: ./.github/workflows/kotlin
- uses: ./.github/workflows/kotlin/kotlin-linux

tests_nuget_android:
needs: [nugets, setup_config]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ runs:
version=$(grep "version" config.txt | sed -E 's/version = "(.*)"/\1/')
echo "version=$version" >> $GITHUB_OUTPUT

- name: Download Native Libs
uses: actions/download-artifact@v4
with:
pattern: kotlin-*
merge-multiple: true
path: ./wrappers/kotlin/lib/src/main/resources/

- name: Installing dependencies
shell: bash
run: |
Expand Down Expand Up @@ -88,7 +95,8 @@ runs:
export CC_x86_64_linux_android="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang"
export AR_x86_64_linux_android="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"

make release RELEASE=1
make android
make linux

chmod +x gradlew
./gradlew test
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/kotlin/kotlin-macos/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build macos natives for kotlin
runs:
using: composite
steps:
- name: Download Version File
uses: actions/download-artifact@v4
with:
name: config.txt

- name: Install Rust
shell: bash
run: |
set -e
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
echo "MACOSX_DEPLOYMENT_TARGET=10.15" >> $GITHUB_ENV
source $HOME/.cargo/env

rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin

- name: Build
shell: bash
working-directory: ./wrappers/kotlin
run: make macos

- name: Test
shell: bash
working-directory: ./wrappers/kotlin
run: |
chmod +x gradlew
./gradlew test
./gradlew build
./gradlew generatePomFileForMavenPublication

- name: Upload Kotlin package
uses: actions/upload-artifact@v4.3.6
with:
name: kotlin-macos
path: ./wrappers/kotlin/lib/src/main/resources/
33 changes: 33 additions & 0 deletions .github/workflows/kotlin/kotlin-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build windows natives for kotlin
runs:
using: composite
steps:
- name: Download Version File
uses: actions/download-artifact@v4
with:
name: config.txt

- name: Install Rust
shell: bash
run: rustup target add x86_64-pc-windows-gnu

- name: Build
shell: bash
working-directory: ./wrappers/kotlin
run: make windows

- name: Test
shell: bash
working-directory: ./wrappers/kotlin
run: |
chmod +x gradlew
./gradlew test
./gradlew build
./gradlew generatePomFileForMavenPublication


- name: Upload Kotlin package
uses: actions/upload-artifact@v4.3.6
with:
name: kotlin-windows
path: ./wrappers/kotlin/lib/src/main/resources/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ __pycache__
config.txt
.github/hooks
TestResults
devolutions_crypto.kt
138 changes: 73 additions & 65 deletions wrappers/kotlin/Makefile
Original file line number Diff line number Diff line change
@@ -1,85 +1,93 @@
RELEASE ?= 0
ifeq ($(RELEASE), 0)
BUILD_PROFILE = debug
else
BUILD_PROFILE = release
RELEASE_FLAG = --release
endif
# Default target
.PHONY: all
all: help

ROOT = ../..
# Platform-specific build targets
.PHONY: windows linux macos android

LIB_NAME = devolutions_crypto_uniffi
LIB_NAME_DASHES = devolutions-crypto-uniffi
windows:
cargo build --release --target x86_64-pc-windows-gnu -p devolutions-crypto-uniffi

LINUX_DEBUG_DIR = $(ROOT)/target/debug
LINUX_DIR = $(ROOT)/target/$(BUILD_PROFILE)
LINUX_DLL = $(LINUX_DIR)/lib$(LIB_NAME).so
cargo build --release -p uniffi-bindgen
cargo run --release -p uniffi-bindgen -- generate --library ../../target/x86_64-pc-windows-gnu/release/devolutions_crypto_uniffi.dll --language kotlin -o ./lib/src/main/kotlin/

KOTLIN_WRAPPER = ./lib/src/main/kotlin
KOTLIN_WRAPPER_FILE = $(KOTLIN_WRAPPER)/org/devolutions/crypto/devolutions_crypto.kt
mkdir -p ./lib/src/main/resources/win32-x86-64/

UNIFFI_PATH = $(ROOT)/uniffi
UNIFFI_BINDGEN = $(UNIFFI_PATH)/uniffi-bindgen
DC_UNIFFI = $(UNIFFI_PATH)/$(LIB_NAME_DASHES)
DC_UNIFFI_SOURCES = $(wildcard $(ROOT)/src/*) $(ROOT)/Cargo.toml $(wildcard $(DC_UNIFFI)/src/*) $(DC_UNIFFI)/Cargo.toml
UNIFFI_BINDGEN_EXE = $(LINUX_DEBUG_DIR)/uniffi-bindgen
cp ../../target/x86_64-pc-windows-gnu/release/devolutions_crypto_uniffi.dll ./lib/src/main/resources/win32-x86-64/devolutions_crypto_uniffi.dll

RUST_ARCHS = aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
ANDROID_ARCHS = android-aarch64 android-armv7 android-x86 android-x86-64
linux:
cargo build --release --target x86_64-unknown-linux-gnu -p devolutions-crypto-uniffi

KT_LINUX_PATH = ./lib/src/main/resources/linux-x86-64/lib$(LIB_NAME).so
KT_ANDROID_PATH = $(foreach var,$(ANDROID_ARCHS),./lib/src/main/resources/$(var)/lib$(LIB_NAME).so)
cargo build --release -p uniffi-bindgen
cargo run --release -p uniffi-bindgen -- generate --library ../../target/x86_64-unknown-linux-gnu/release/libdevolutions_crypto_uniffi.so --language kotlin -o ./lib/src/main/kotlin/

mkdir -p ./lib/src/main/resources/linux-x86-64/

.PHONY: all release linux android clean
cp ../../target/x86_64-unknown-linux-gnu/release/libdevolutions_crypto_uniffi.so ./lib/src/main/resources/linux-x86-64/libdevolutions_crypto_uniffi.so

all: linux
macos:
cargo build --release --target aarch64-apple-darwin -p devolutions-crypto-uniffi
cargo build --release --target x86_64-apple-darwin -p devolutions-crypto-uniffi

release: linux android
cargo build --release -p uniffi-bindgen
cargo run --release -p uniffi-bindgen -- generate --library ../../target/aarch64-apple-darwin/release/libdevolutions_crypto_uniffi.dylib --language kotlin -o ./lib/src/main/kotlin/

linux: $(KOTLIN_WRAPPER_FILE) $(KT_LINUX_PATH)
android: $(KOTLIN_WRAPPER_FILE) $(KT_ANDROID_PATH)
mkdir -p ./lib/src/main/resources/darwin-aarch64/
mkdir -p ./lib/src/main/resources/darwin-x86-64/

# Build the library in debug
$(LINUX_DLL): $(DC_UNIFFI_SOURCES)
cargo build $(RELEASE_FLAG) -p "$(LIB_NAME_DASHES)"
cp ../../target/aarch64-apple-darwin/release/libdevolutions_crypto_uniffi.dylib ./lib/src/main/resources/darwin-aarch64/libdevolutions_crypto_uniffi.dylib
cp ../../target/x86_64-apple-darwin/release/libdevolutions_crypto_uniffi.dylib ./lib/src/main/resources/darwin-x86-64/libdevolutions_crypto_uniffi.dylib

# Copy the libraries to KT directory
$(KT_LINUX_PATH): $(LINUX_DLL)
mkdir -p $(@D)
cp $< $@
android:
cargo build --release --target aarch64-linux-android -p devolutions-crypto-uniffi
cargo build --release --target armv7-linux-androideabi -p devolutions-crypto-uniffi
cargo build --release --target i686-linux-android -p devolutions-crypto-uniffi
cargo build --release --target x86_64-linux-android -p devolutions-crypto-uniffi

define compile_android
cargo build $(RELEASE_FLAG) --target=$(ARCH) -p "$(LIB_NAME_DASHES)"
mkdir -p $(@D)
cp $(ROOT)/target/$(ARCH)/$(BUILD_PROFILE)/lib$(LIB_NAME).so $@
endef
cargo build --release -p uniffi-bindgen
cargo run --release -p uniffi-bindgen -- generate --library ../../target/aarch64-linux-android/release/libdevolutions_crypto_uniffi.so --language kotlin -o ./lib/src/main/kotlin/

./lib/src/main/resources/android-aarch64/lib$(LIB_NAME).so: $(DC_UNIFFI_SOURCES)
$(eval ARCH=aarch64-linux-android)
@$(call compile_android)
mkdir -p ./lib/src/main/resources/android-aarch64/
mkdir -p ./lib/src/main/resources/android-armv7/
mkdir -p ./lib/src/main/resources/android-x86/
mkdir -p ./lib/src/main/resources/android-x86-64/

./lib/src/main/resources/android-armv7/lib$(LIB_NAME).so: $(DC_UNIFFI_SOURCES)
$(eval ARCH=armv7-linux-androideabi)
@$(call compile_android)
cp ../../target/aarch64-linux-android/release/libdevolutions_crypto_uniffi.so ./lib/src/main/resources/android-aarch64/libdevolutions_crypto_uniffi.so
cp ../../target/armv7-linux-androideabi/release/libdevolutions_crypto_uniffi.so ./lib/src/main/resources/android-armv7/libdevolutions_crypto_uniffi.so
cp ../../target/i686-linux-android/release/libdevolutions_crypto_uniffi.so ./lib/src/main/resources/android-x86/libdevolutions_crypto_uniffi.so
cp ../../target/x86_64-linux-android/release/libdevolutions_crypto_uniffi.so ./lib/src/main/resources/android-x86-64/libdevolutions_crypto_uniffi.so

./lib/src/main/resources/android-x86/lib$(LIB_NAME).so: $(DC_UNIFFI_SOURCES)
$(eval ARCH=i686-linux-android)
@$(call compile_android)

./lib/src/main/resources/android-x86-64/lib$(LIB_NAME).so: $(DC_UNIFFI_SOURCES)
$(eval ARCH=x86_64-linux-android)
@$(call compile_android)
# Clean targets for each platform
.PHONY: clean clean-windows clean-linux clean-macos clean-android

# Build uniffi-bindgen
$(UNIFFI_BINDGEN_EXE): $(wildcard $(UNIFFI_BINDGEN)/src/*) $(UNIFFI_BINDGEN)/Cargo.toml
cargo build -p "uniffi-bindgen"

# Generate the wrapper file
$(KOTLIN_WRAPPER_FILE): $(LINUX_DLL) $(UNIFFI_BINDGEN_EXE)
$(UNIFFI_BINDGEN_EXE) generate --library "$(LINUX_DLL)" --language kotlin -o $(KOTLIN_WRAPPER)

clean:
clean: clean-windows clean-linux clean-macos clean-android
cargo clean
rm -f $(KOTLIN_WRAPPER_FILE)
rm -f $(KT_ANDROID_PATH)
rm -f $(KT_LINUX_PATH)
rm -rf ./lib/src/main/kotlin/org

clean-windows:
rm -rf ./lib/src/main/resources/win32-x86-64/

clean-linux:
rm -rf ./lib/src/main/resources/linux-x86-64/

clean-macos:
rm -rf ./lib/src/main/resources/darwin-aarch64/
rm -rf ./lib/src/main/resources/darwin-x86-64/

clean-android:
rm -rf ./lib/src/main/resources/android-aarch64/
rm -rf ./lib/src/main/resources/android-armv7/
rm -rf ./lib/src/main/resources/android-x86/
rm -rf ./lib/src/main/resources/android-x86-64/

# Help target
.PHONY: help
help:
@echo "Makefile Usage:"
@echo " make windows - Build for Windows"
@echo " make linux - Build for Linux"
@echo " make macos - Build for macOS"
@echo " make android - Build for Android"
@echo " make clean - Clean all builds"
@echo " make clean-<platform> - Clean a specific platform build (e.g., clean-windows)"
2 changes: 0 additions & 2 deletions wrappers/kotlin/build-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
make release RELEASE=1

chmod +x gradlew
./gradlew test
./gradlew build
Expand Down
Empty file.