Skip to content

Update pullrequest.yml & Fix JVM Cache Dir #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
53 changes: 18 additions & 35 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
name: "PullRequest Checks"

on:
push:
pull_request:
branches: [ "main" ]
schedule:
- cron: '27 0 * * 2'

jobs:
analyze:
name: Analyze C/C++ and Java/Kotlin
build:
runs-on: 'ubuntu-latest'
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -34,17 +24,8 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y cmake swig ninja-build clang clang-tools libc++-dev libc++abi-dev
# - name: Install latest cmake
# run: |
# CMAKE_URL="https://github.com/Kitware/CMake/releases/latest/download/cmake-4.0.0-linux-x86_64.sh"
# EXPECTED_HASH="33ba237f2850a82d5c71c1d41803ab832a9a7aac7d99fa6e48bbe5bb4d66653c"
#
# wget "$CMAKE_URL" -O cmake-installer.sh
# echo "$EXPECTED_HASH cmake-installer.sh" | sha256sum -c -
#
# chmod +x cmake-installer.sh
# sudo ./cmake-installer.sh --skip-license --prefix=/usr/local
sudo apt-get install -y cmake swig ninja-build clang clang-tools
sudo apt-get install -y libc++-dev libc++abi-dev llvm
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Setup Android NDK
Expand All @@ -53,22 +34,24 @@ jobs:
sdkmanager "ndk;27.2.12479018"
sdkmanager "cmake;3.31.6"
echo "ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/27.2.12479018" >> $GITHUB_ENV
echo "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
# echo "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH

- name: KTLint Check
run: |
./gradlew ktlintCheck

- name: Detekt Check
run: |
./gradlew detekt
# - name: KTLint Check
# run: |
# ./gradlew ktlintCheck
#
# - name: Detekt Check
# run: |
# ./gradlew detekt

- name: Test
shell: bash
env:
CC: clang
CXX: clang++
CXXFLAGS: --stdlib=libc++
CXXFLAGS: "--stdlib=libc++"
run: |
./gradlew jvmTest
./gradlew crypto-jvm-lib:cmakeBuild
ls -l crypto-jvm-lib/build/cmake-build/
ldd crypto-jvm-lib/build/cmake-build/liboh_crypto.so

4 changes: 4 additions & 0 deletions crypto-jvm-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ val copyNativeLibs by tasks.registering(Copy::class) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.named("clean") {
mustRunAfter(":crypto:clean")
}

tasks.named("jar") {
dependsOn(copyNativeLibs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ fun loadNativeLibrary() {

val libResUrl = ClassLoader.getSystemResource("$hostOs-$hostArch/$libName")

val tempLib = File.createTempFile("lib", libName)
tempLib.deleteOnExit()
libResUrl.openStream().copyTo(tempLib.outputStream())
val cacheFilePath = getCacheDir() + File.pathSeparator + libName
val cacheFile = File(cacheFilePath)
cacheFile.parentFile.mkdirs()
libResUrl.openStream().copyTo(cacheFile.outputStream())

System.load(tempLib.absolutePath)
System.load(cacheFile.absolutePath)
}
}

private fun getCacheDir(): String {
val os = System.getProperty("os.name").lowercase()
val userHome = System.getProperty("user.home")

return when {
os.contains("win") -> System.getenv("LOCALAPPDATA") ?: "$userHome\\AppData\\Local"
os.contains("mac") -> "$userHome/Library/Caches"
else -> System.getenv("XDG_CACHE_HOME") ?: "$userHome/.cache"
} + File.pathSeparator + "de.gematik.openhealth.crypto"
}
4 changes: 4 additions & 0 deletions crypto-jvm-swig/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ val patchGeneratedJava by tasks.registering {
dependsOn(generateJniWrapper)
}

tasks.named("clean") {
mustRunAfter(":crypto:clean")
}

tasks.named("sourcesJar") {
dependsOn(patchGeneratedJava)
}
Expand Down
4 changes: 4 additions & 0 deletions crypto-web-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ val npxNodeConv by tasks.registering(Exec::class) {
dependsOn(npmInstall)
}

tasks.named("clean") {
mustRunAfter(":crypto:clean")
}

tasks.named("compileKotlinJs") {
dependsOn(copyJsLibs, npxNodeConv)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ suspend fun <R : Any?> useCryptoAsync(block: suspend CryptoScope.() -> R): R =

internal expect fun <R : Any?> nativeUseCrypto(block: CryptoScope.() -> R): R

internal expect suspend fun <R : Any?> nativeUseCryptoSuspendable(block: suspend CryptoScope.() -> R): R
internal expect suspend fun <R : Any?> nativeUseCryptoSuspendable(
block: suspend CryptoScope.() -> R,
): R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class CmacTest {
)
}

@Ignore // TODO: check if we should support this
// TODO OPEN-56: check if we should support this
@Ignore
@Test
fun `cmac final can only be called once`() =
runTestWithProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ internal actual fun <R : Any?> nativeUseCrypto(block: CryptoScope.() -> R): R =
* JavaScript-specific implementation for asynchronous cryptographic operations.
* Executes the given suspend block within a crypto scope.
*/
internal actual suspend fun <R : Any?> nativeUseCryptoSuspendable(block: suspend CryptoScope.() -> R): R =
block(JsCryptoScope())
internal actual suspend fun <R : Any?> nativeUseCryptoSuspendable(
block: suspend CryptoScope.() -> R,
): R = block(JsCryptoScope())
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ internal actual fun <R : Any?> nativeUseCrypto(block: CryptoScope.() -> R): R =
* JVM-specific implementation for asynchronous cryptographic operations.
* Executes the given suspend block within a crypto scope.
*/
internal actual suspend fun <R : Any?> nativeUseCryptoSuspendable(block: suspend CryptoScope.() -> R): R =
block(JvmCryptoScope())
internal actual suspend fun <R : Any?> nativeUseCryptoSuspendable(
block: suspend CryptoScope.() -> R,
): R = block(JvmCryptoScope())
11 changes: 7 additions & 4 deletions libs/openssl/wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set(CMAKE_CXX_STANDARD 23)

project(crypto)

# enable_testing()

### OpenSSL

include(cmake/openssl.cmake)
Expand Down Expand Up @@ -39,6 +37,13 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
add_library(oh_crypto SHARED ${PROJECT_ROOT_DIR}/crypto-jvm-swig/build/generated/sources/jni/crypto.cpp)
target_include_directories(oh_crypto PRIVATE src)
target_link_libraries(oh_crypto PRIVATE oh_crypto_base OpenSSL::Crypto JNI::JNI)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(oh_crypto PRIVATE -stdlib=libc++)
target_link_options(oh_crypto PRIVATE -stdlib=libc++)
endif()
endif()
else ()
# Build the lib as a wasm module using Emscripten
add_executable(oh_crypto src/ems_wrapper.cpp)
Expand Down Expand Up @@ -71,5 +76,3 @@ else ()
target_link_options(oh_crypto PRIVATE -Oz -flto)
endif ()
endif ()

#add_subdirectory(test)
17 changes: 11 additions & 6 deletions libs/openssl/wrapper/cmake/openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
set(_OPENSSL_LIB_PATH "lib")
set(_OPENSSL_LIB_SUFFIX "a")

# OpenSSL requires the android toolchain on the PATH
file(GLOB NDK_DIRS "$ENV{ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/*/bin")
list(GET NDK_DIRS 0 NDK_BIN_PATH)

elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# if(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
# set(_OPENSSL_TARGET "darwin64-arm64-cc") # macOS ARM target
Expand Down Expand Up @@ -74,15 +78,16 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
CROSS_COMPILE=\"\" \
${OPENSSL_SOURCE_DIR}/Configure \
--prefix=${OPENSSL_INSTALL_DIR} \
${OPENSSL_CONFIG_PARAMS}
${_OPENSSL_TARGET}"
${OPENSSL_CONFIG_PARAMS} \
${_OPENSSL_TARGET}"
)
else ()
set(OPENSSL_CONFIGURE_COMMAND
bash -c "${OPENSSL_SOURCE_DIR}/Configure \
bash -c "PATH=${NDK_BIN_PATH}:$PATH \
${OPENSSL_SOURCE_DIR}/Configure \
--prefix=${OPENSSL_INSTALL_DIR} \
${OPENSSL_CONFIG_PARAMS}
${_OPENSSL_TARGET}"
${OPENSSL_CONFIG_PARAMS} \
${_OPENSSL_TARGET}"
)
endif ()

Expand All @@ -97,7 +102,7 @@ ExternalProject_Add(
CONFIGURE_COMMAND
${OPENSSL_CONFIGURE_COMMAND}
UPDATE_COMMAND ""
BUILD_COMMAND make -j14
BUILD_COMMAND bash -c "PATH=${NDK_BIN_PATH}:$PATH make -j14"
BUILD_IN_SOURCE 0
# required, otherwise ninja fails
BUILD_BYPRODUCTS ${_OPENSSL_BUILD_TARGET}
Expand Down
35 changes: 0 additions & 35 deletions libs/openssl/wrapper/test/CMakeLists.txt

This file was deleted.

Loading