diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 00331b2..9cdb05a 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -15,15 +15,12 @@ jobs: - os: linux runner: ubuntu-latest libname: libopensesamenative.so - java_home: "$JAVA_HOME_17_X64" - os: macos runner: macos-latest libname: libopensesamenative.dylib - java_home: "$JAVA_HOME_17_arm64" - os: windows - runner: windows-latest + runner: ubuntu-latest libname: opensesamenative.dll - java_home: "$JAVA_HOME_17_X64" - os: linux arch: i386 compiler_package: g++-i686-linux-gnu @@ -33,6 +30,16 @@ jobs: - os: linux arch: arm compiler_package: g++-arm-linux-gnueabi + - os: windows + arch: x86_64 + compiler_package: g++-mingw-w64-x86-64 + - os: windows + arch: i386 + compiler_package: g++-mingw-w64-i686 + - os: windows + arch: aarch64 + msys: CLANGARM64 + runner: windows-latest exclude: - os: macos arch: i386 @@ -46,25 +53,23 @@ jobs: - name: Setup GCC if: ${{ matrix.compiler_package }} run: sudo apt install -y ${{ matrix.compiler_package }} + - name: Setup MSYS2 + if: ${{ matrix.msys }} + uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.msys }} - name: Configure CMake run: > cmake -B cmakebuild -DCMAKE_TOOLCHAIN_FILE="toolchains/${{ matrix.os }}-${{ matrix.arch }}.cmake" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -DJAVA_HOME=${{ matrix.java_home }} -S ${{ github.workspace }} - name: Build run: cmake --build cmakebuild --config ${{ matrix.build_type }} - - if: ${{ matrix.os != 'windows' }} - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}-${{ matrix.arch }} path: cmakebuild/${{ matrix.libname }} - - if: ${{ matrix.os == 'windows' }} - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.os }}-${{ matrix.arch }} - path: cmakebuild/${{ matrix.build_type }}/${{ matrix.libname }} publish: permissions: contents: read diff --git a/.gitignore b/.gitignore index d10e473..d782552 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ _deps CMakeUserPresets.json cmakebuild +out build .gradle diff --git a/CMakeLists.txt b/CMakeLists.txt index 0319926..18a7b09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,37 @@ cmake_minimum_required(VERSION 3.17) project(OpenSesameNatives LANGUAGES CXX C) -find_package(JNI REQUIRED) +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/share/native/include" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/unix/native/include" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/windows/native/include" + COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/jni_headers" + COMMAND git -C "${CMAKE_CURRENT_BINARY_DIR}/jni_headers" init + COMMAND git -C "${CMAKE_CURRENT_BINARY_DIR}/jni_headers" remote add origin https://github.com/openjdk/jdk.git + COMMAND git -C "${CMAKE_CURRENT_BINARY_DIR}/jni_headers" sparse-checkout set src/java.base/share/native/include src/java.base/unix/native/include src/java.base/windows/native/include + COMMAND git -C "${CMAKE_CURRENT_BINARY_DIR}/jni_headers" fetch --depth=1 --filter=blob:none origin dfacda488bfbe2e11e8d607a6d08527710286982 + COMMAND git -C "${CMAKE_CURRENT_BINARY_DIR}/jni_headers" checkout dfacda488bfbe2e11e8d607a6d08527710286982 + VERBATIM +) + +add_custom_target(fetch_jni_headers + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/share/native/include" + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/unix/native/include" + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/windows/native/include") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdlib") -include_directories(${JNI_INCLUDE_DIRS}) add_library(opensesamenative SHARED - src/cpp/opensesamenative.cpp) \ No newline at end of file + src/cpp/opensesamenative.cpp) +add_dependencies(opensesamenative fetch_jni_headers) + +target_include_directories(opensesamenative PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/share/native/include") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_include_directories(opensesamenative PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/unix/native/include") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_include_directories(opensesamenative PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}/jni_headers/src/java.base/windows/native/include") +endif() \ No newline at end of file diff --git a/toolchains/windows-aarch64.cmake b/toolchains/windows-aarch64.cmake index a25d652..aa7bfb2 100644 --- a/toolchains/windows-aarch64.cmake +++ b/toolchains/windows-aarch64.cmake @@ -1,4 +1,5 @@ set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_C_COMPILER cl) -set(CMAKE_CXX_COMPILER cl) -set(CMAKE_GENERATOR_PLATFORM "ARM64") \ No newline at end of file +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) +set(CMAKE_C_FLAGS "-march=armv8-a") +set(CMAKE_CXX_FLAGS "-march=armv8-a") \ No newline at end of file diff --git a/toolchains/windows-i386.cmake b/toolchains/windows-i386.cmake index d915497..f22cd42 100644 --- a/toolchains/windows-i386.cmake +++ b/toolchains/windows-i386.cmake @@ -1,4 +1,5 @@ set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_C_COMPILER cl) -set(CMAKE_CXX_COMPILER cl) -set(CMAKE_GENERATOR_PLATFORM "Win32") \ No newline at end of file +set(CMAKE_C_COMPILER mingw-w64-i686-gcc) +set(CMAKE_CXX_COMPILER mingw-w64-i686-g++) +set(CMAKE_C_FLAGS "-m32 -march=i386") +set(CMAKE_CXX_FLAGS "-m32 -march=i386") \ No newline at end of file diff --git a/toolchains/windows-x86_64.cmake b/toolchains/windows-x86_64.cmake index d7cfa48..ebf2b3e 100644 --- a/toolchains/windows-x86_64.cmake +++ b/toolchains/windows-x86_64.cmake @@ -1,4 +1,5 @@ set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_C_COMPILER cl) -set(CMAKE_CXX_COMPILER cl) -set(CMAKE_GENERATOR_PLATFORM "x64") \ No newline at end of file +set(CMAKE_C_COMPILER mingw-w64-x86-64-gcc) +set(CMAKE_CXX_COMPILER mingw-w64-x86-64-g++) +set(CMAKE_C_FLAGS "-m64") +set(CMAKE_CXX_FLAGS "-m64") \ No newline at end of file