Skip to content

Commit

Permalink
More toolchain changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Jul 15, 2024
1 parent 1adfd0c commit ef344e2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ _deps
CMakeUserPresets.json

cmakebuild
out

build
.gradle
32 changes: 29 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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()
7 changes: 4 additions & 3 deletions toolchains/windows-aarch64.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(CMAKE_GENERATOR_PLATFORM "ARM64")
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_C_FLAGS "-march=armv8-a")
set(CMAKE_CXX_FLAGS "-march=armv8-a")
7 changes: 4 additions & 3 deletions toolchains/windows-i386.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(CMAKE_GENERATOR_PLATFORM "Win32")
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")
7 changes: 4 additions & 3 deletions toolchains/windows-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(CMAKE_GENERATOR_PLATFORM "x64")
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")

0 comments on commit ef344e2

Please sign in to comment.