diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..0243837 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target-dir = "Binaries" diff --git a/Bootstrap.ps1 b/Bootstrap.ps1 index 01beeb3..4360b90 100755 --- a/Bootstrap.ps1 +++ b/Bootstrap.ps1 @@ -4,9 +4,6 @@ if ($IsWindows) { - echo "Generating Visual Studio project..." - - & "./Vendor/Premake/Windows/premake5.exe" "vs2019" } # Mac @@ -15,11 +12,6 @@ elseif ($IsMacOS) { sudo chmod +x ./gradlew sudo chmod +x ./Scripts/Package.ps1 - - echo "Generating XCode project..." - - sudo chmod +x ./Vendor/Premake/Mac/premake5 - & "./Vendor/Premake/Mac/premake5" "xcode4" } # Linux @@ -28,9 +20,4 @@ elseif ($IsLinux) { sudo chmod +x ./gradlew sudo chmod +x ./Scripts/Package.ps1 - - echo "Generating GMake project..." - - sudo chmod +x ./Vendor/Premake/Linux/premake5 - & "./Vendor/Premake/Linux/premake5" "gmake2" } diff --git a/Bootstrap.sh b/Bootstrap.sh index b54172e..e5a5567 100755 --- a/Bootstrap.sh +++ b/Bootstrap.sh @@ -7,17 +7,10 @@ sudo chmod +x ./Scripts/Package.ps1 if [ "$(expr substr $(uname -s) 1 5)" = "Linux" ] then - echo "Generating GMake project..." - - sudo chmod +x ./Vendor/Premake/Linux/premake5 - ./Vendor/Premake/Linux/premake5 gmake2 # Mac elif [ "$(uname)" = "Darwin" ] then - echo "Generating XCode project..." - sudo chmod +x ./Vendor/Premake/Mac/premake5 - ./Vendor/Premake/Mac/premake5 xcode4 fi diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2ac6ce2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "TribuFu-jvm" +version = "0.0.1" +description = "Jvm bindings to TribuFu SDK" +repository = "https://github.com/TribuFu/SDK" +authors = ["TribuFu "] +license = "Apache-2.0" +edition = "2018" +publish = false + +[lib] +name="TribuFu_jvm" +crate-type = ["cdylib", "rlib"] +path = "Source/lib.rs" + +[dependencies] +TribuFu = { path = "../DevKit.Rs", package = "TribuFu" } +jni = "0.19.0" diff --git a/Native/Source/Library.c b/Native/Source/Library.c deleted file mode 100644 index 352582a..0000000 --- a/Native/Source/Library.c +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) TribuFu. All Rights Reserved - -#include -#include "TribuFu.h" -#include "Library.h" - -JNIEXPORT jstring JNICALL Java_tribufu_TribuFu_Hello(JNIEnv *env, jobject obj, jstring str) -{ - char *result = Hello("C"); - - return result; -} diff --git a/Native/Source/Library.h b/Native/Source/Library.h deleted file mode 100644 index 6f47672..0000000 --- a/Native/Source/Library.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) TribuFu. All Rights Reserved - -#pragma once - -#include -#include "TribuFu.h" - -/* - * Class: tribufu_TribuFu - * Method: Hello - * Signature: (Ljava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_tribufu_TribuFu_Hello(JNIEnv *, jobject, jstring); diff --git a/Native/Source/TribuFu.java b/Native/Source/TribuFu.java deleted file mode 100644 index add043f..0000000 --- a/Native/Source/TribuFu.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) TribuFu. All Rights Reserved - -package tribufu; - -public class TribuFu { - /** - * A native method that is implemented by the 'TribuFu' native library. - */ - public native String Hello(String input); - - // Used to load the 'TribuFu' library on application startup. - static { - System.loadLibrary("TribuFu_jvm"); - } -} diff --git a/Native/premake5.lua b/Native/premake5.lua deleted file mode 100644 index 3b2ba97..0000000 --- a/Native/premake5.lua +++ /dev/null @@ -1,64 +0,0 @@ -project "TribuFu_jvm" - location "." - kind "SharedLib" - language "C" - - targetdir ("./Binaries/%{cfg.buildcfg}") - objdir ("./Intermediate/") - - files - { - "./Source/**.h", - "./Source/**.c", - } - - includedirs - { - "../Vendor/TribuFu", - "D:/Program Files/AdoptOpenJDK/jdk-11.0.10.9-hotspot/include", - "D:/Program Files/AdoptOpenJDK/jdk-11.0.10.9-hotspot/include/win32" - } - - filter "system:windows" - staticruntime "Off" - systemversion "latest" - - links - { - "TribuFu.lib" - } - - libdirs - { - "../Vendor/TribuFu/Windows" - } - - filter { "system:windows", "configurations:debug" } - runtime "Debug" - symbols "on" - - filter { "system:windows", "configurations:release" } - runtime "Release" - optimize "on" - - filter "system:linux" - links - { - "TribuFu" - } - - libdirs - { - "../Vendor/TribuFu/Linux" - } - - filter "system:darwin" - links - { - "TribuFu" - } - - libdirs - { - "../Vendor/TribuFu/Mac" - } diff --git a/Scripts/Package.ps1 b/Scripts/Package.ps1 index 5334686..3605895 100755 --- a/Scripts/Package.ps1 +++ b/Scripts/Package.ps1 @@ -4,5 +4,11 @@ ./gradlew jar New-Item -Path "./Release" -ItemType Directory -Force +New-Item -Path "./Release/Windows" -ItemType Directory -Force +New-Item -Path "./Release/Mac" -ItemType Directory -Force +New-Item -Path "./Release/Linux" -ItemType Directory -Force +New-Item -Path "./Release/Android" -ItemType Directory -Force Copy-Item -Path "./lib/build/libs/lib-0.0.1.jar" -Destination "./Release/TribuFu.jar" -Recurse -Force + +Copy-Item -Path "./Binaries/debug/TribuFu_jvm.dll" -Destination "./Release/Windows/TribuFu_jvm.dll" -Recurse -Force diff --git a/Source/lib.rs b/Source/lib.rs new file mode 100644 index 0000000..605c001 --- /dev/null +++ b/Source/lib.rs @@ -0,0 +1,41 @@ +// Copyright (c) TribuFu. All Rights Reserved + +//! Jvm bindings to TribuFu SDK. + +#![allow(non_snake_case)] +#![allow(unused_variables)] +#![allow(unused_imports)] + +#[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_os = "linux", + target_os = "android", +)))] +compile_error!("INVALID_TARGET_PLATFORM"); + +use jni::objects::{JClass, JString}; +use jni::sys::jstring; +use jni::JNIEnv; +use std::ffi::{CStr, CString}; + +#[no_mangle] +// This is the class that owns our static method. It's not going to be used, +// but still must be present to match the expected signature of a static +// native method. +pub extern "system" fn Java_tribufu_TribuFu_Hello( + env: JNIEnv, + _: JClass, + j_input: JString, +) -> jstring { + // First, we have to get the string out of Java. Check out the `strings` + // module for more info on how this works. + let input = CString::from(unsafe { CStr::from_ptr(env.get_string(j_input).unwrap().as_ptr()) }); + + // Then we have to create a new Java string to return. Again, more info + // in the `strings` module. + let res = env.new_string(input.to_str().unwrap()).unwrap(); + + // Finally, extract the raw pointer to return. + return res.into_inner(); +} diff --git a/premake5.lua b/premake5.lua deleted file mode 100644 index b1fe65c..0000000 --- a/premake5.lua +++ /dev/null @@ -1,10 +0,0 @@ -workspace "DevKit.Jvm" - architecture "x64" - - configurations - { - "debug", - "release" - } - - include "Native"