Skip to content

Commit

Permalink
Preview of java 22 jextract to replace JNI package
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF committed Oct 11, 2024
1 parent 6e8c7a9 commit 4e5e7b8
Show file tree
Hide file tree
Showing 319 changed files with 188,902 additions and 1 deletion.
98 changes: 98 additions & 0 deletions .github/workflows/cmake-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,104 @@ jobs:
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`

####### clang builds
build_and_test_win_clang:
# Windows w/ clang + CMake
#
name: "Windows ClangCL CTest"
runs-on: windows-latest
steps:
- name: Install Dependencies (Windows_clang)
run: choco install ninja

- name: Workaround C++ clang
run: |
choco upgrade llvm
- name: Set file base name (Windows_clang)
id: set-file-base
run: |
FILE_NAME_BASE=$(echo "${{ inputs.file_base }}")
echo "FILE_BASE=$FILE_NAME_BASE" >> $GITHUB_OUTPUT
if [[ '${{ inputs.use_environ }}' == 'release' ]]
then
SOURCE_NAME_BASE=$(echo "${{ inputs.snap_name }}")
else
SOURCE_NAME_BASE=$(echo "hdfsrc")
fi
echo "SOURCE_BASE=$SOURCE_NAME_BASE" >> $GITHUB_OUTPUT
shell: bash

# Get files created by release script
- name: Get zip-tarball (Windows_clang)
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: zip-tarball
path: ${{ github.workspace }}

- name: using powershell
shell: pwsh
run: Get-Location

- name: List files for the space (Windows_clang)
run: |
Get-ChildItem -Path ${{ github.workspace }}
Get-ChildItem -Path ${{ runner.workspace }}
shell: pwsh

- name: Uncompress source (Windows_clang)
working-directory: ${{ github.workspace }}
run: 7z x ${{ steps.set-file-base.outputs.FILE_BASE }}.zip
shell: bash

- name: Copy script files for the space (Windows_clang)
run: |
Copy-Item -Path ${{ runner.workspace }}/hdf5/${{ steps.set-file-base.outputs.SOURCE_BASE }}/config/cmake/scripts/CTestScript.cmake -Destination ${{ runner.workspace }}/hdf5/
Copy-Item -Path ${{ runner.workspace }}/hdf5/${{ steps.set-file-base.outputs.SOURCE_BASE }}/config/cmake/scripts/HDF5config.cmake -Destination ${{ runner.workspace }}/hdf5/
shell: pwsh

- name: List files for the hdf5 (Windows_clang)
run: |
Get-ChildItem -Path ${{ runner.workspace }}/hdf5
shell: pwsh

- name: Create options file (Windows_clang)
uses: "DamianReeves/write-file-action@master"
with:
path: ${{ runner.workspace }}/hdf5/HDF5options.cmake
write-mode: overwrite
contents: |
set (CTEST_DROP_SITE_INIT "my.cdash.org")
# Change following line to submit to your CDash dashboard to a different CDash project
#set (CTEST_DROP_LOCATION_INIT "/submit.php?project=HDF5")
set (SITE_BUILDNAME_SUFFIX "${{ steps.set-file-base.outputs.FILE_BASE }}")
#set (CMAKE_GENERATOR_TOOLSET "ClangCL")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} --log-level=TRACE")
#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/clang.cmake")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=ON")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=ON")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=OFF")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=ON")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PLUGIN_SUPPORT:BOOL=ON")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF")
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DZLIB_USE_LOCALCONTENT:BOOL=OFF")
- name: Run ctest (Windows_clang) with clang
run: |
cd "${{ runner.workspace }}/hdf5"
ctest -S HDF5config.cmake,CTEST_SITE_EXT=GH-Clang,LOCAL_SUBMIT=ON,NINJA=TRUE,BUILD_GENERATOR=VS202264,CTEST_SOURCE_NAME=${{ steps.set-file-base.outputs.SOURCE_BASE }} -C Release -VV -O hdf5.log
shell: pwsh
continue-on-error: true

# Save log files created by ctest script
- name: Save log (Windows_clang)
uses: actions/upload-artifact@v4
with:
name: clang-win-log
path: ${{ runner.workspace }}/hdf5/hdf5.log
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`

build_and_test_linux_clang:
# Linux (Ubuntu) w/ clang + CMake
#
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/daily-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: hdf5 dev daily build on schedule
on:
workflow_dispatch:
schedule:
- cron: "6 0 * * *"
- cron: "8 0 * * *"

permissions:
contents: write # In order to allow tag creation and file deletion
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ set (HDF5_HL_F90_C_LIB_CORENAME "${HDF5_LIB_BASE}${HDF5_HL_F90_C_LIB_CORE}")
set (HDF5_JAVA_JNI_LIB_CORENAME "${HDF5_LIB_BASE}${HDF5_JAVA_JNI_LIB_CORE}")
set (HDF5_JAVA_HDF5_LIB_CORENAME "jarhdf5")
set (HDF5_JAVA_TEST_LIB_CORENAME "jartest5")
set (HDF5_JAVA_JSRC_LIB_CORENAME "javahdf5")
set (HDF5_JAVA_JTEST_LIB_CORENAME "javatest5")

#-----------------------------------------------------------------------------
# Set the true names of all the libraries if customized by external project
Expand All @@ -213,6 +215,8 @@ set (HDF5_HL_F90_C_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_LIB_BASE}${HD
set (HDF5_JAVA_JNI_LIB_NAME "${HDF5_LIB_BASE}${HDF5_JAVA_JNI_LIB_CORE}")
set (HDF5_JAVA_HDF5_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_HDF5_LIB_CORENAME}${HDF5_LIB_INFIX}${HDF5_EXTERNAL_LIB_SUFFIX}")
set (HDF5_JAVA_TEST_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_TEST_LIB_CORENAME}${HDF5_LIB_INFIX}${HDF5_EXTERNAL_LIB_SUFFIX}")
set (HDF5_JAVA_JSRC_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_JSRC_LIB_CORENAME}${HDF5_LIB_INFIX}${HDF5_EXTERNAL_LIB_SUFFIX}")
set (HDF5_JAVA_JTEST_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_JTEST_LIB_CORENAME}${HDF5_LIB_INFIX}${HDF5_EXTERNAL_LIB_SUFFIX}")

#-----------------------------------------------------------------------------
# Set the target names of all the libraries
Expand Down Expand Up @@ -248,6 +252,8 @@ set (HDF5_F90_TEST_LIBSH_TARGET "${HDF5_F90_TEST_LIB_CORENAME}-shared")
set (HDF5_F90_C_TEST_LIBSH_TARGET "${HDF5_F90_C_TEST_LIB_CORENAME}-shared")
set (HDF5_HL_F90_LIBSH_TARGET "${HDF5_HL_F90_LIB_CORENAME}-shared")
set (HDF5_HL_F90_C_LIBSH_TARGET "${HDF5_HL_F90_C_LIB_CORENAME}-shared")
set (HDF5_JAVA_JSRC_LIB_TARGET "${HDF5_JAVA_JSRC_LIB_CORENAME}")
set (HDF5_JAVA_JTEST_LIB_TARGET "${HDF5_JAVA_JTEST_LIB_CORENAME}")

#-----------------------------------------------------------------------------
# Define some CMake variables for use later in the project
Expand Down
92 changes: 92 additions & 0 deletions bin/h5jextract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#! /bin/sh
#
# Copyright by The HDF Group.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# [email protected].
#
## Update HDF5 java/jsrc after the HDF5 software has been built ##
## For help page, use "h5jextract -help" ##

# show help page
usage() {
# A wonderfully informative "usage" message.
echo "usage: $prog_name [OPTIONS]"
echo " OPTIONS:"
echo " -help|help This help message"
echo " -echo Show all the shell commands executed"
echo " -jextract=DIR Directory to find the jextract binary"
echo " [default: current <user home>/jextract/bin]"
echo " -sourcedir=DIR Directory for the HDF5 source files"
echo " [default: current directory]"
echo " -includedir=DIR Directory for the HDF5 header files"
echo " [default: current directory/include]"
echo " [should be set to the public only headers]"
echo " "
exit $EXIT_FAILURE
}

# Report Error message
ERROR()
{
echo "***ERROR***"
echo "$1"
}

# Main
#
############################################################################
# Initialization
prefix=
jextract=
includedir=

# Parse options
for arg in $@ ; do
case "$arg" in
-jextract=*)
jextract="`echo $arg | cut -f2 -d=`"
;;
-sourcedir=*)
sourcedir="`echo $arg | cut -f2 -d=`"
;;
-includedir=*)
includedir="`echo $arg | cut -f2 -d=`"
;;
-echo)
set -x
;;
-help|help)
usage
;;
*)
ERROR "Unknown Option($arg)"
usage
exit $EXIT_FAILURE
;;
esac
done

# Set to default value, one above where i am, if not given by user
if [ -z "$sourcedir" ]; then
sourcedir=`(cd ..;pwd)`
fi
if [ -z "$includedir" ]; then
includedir='${sourcedir}'/include # use single quotes to prevent expansion of $
fi
if [ -z "$jextract" ]; then
jextract='${HOME}'/jextract/bin # use single quotes to prevent expansion of $
fi


$jextract/jextract \
--include-dir $includedir \
--output $sourcedir/java/jsrc \
--target-package org.hdfgroup.javahdf5 \
--library hdf5 \
$includedir/hdf5.h
8 changes: 8 additions & 0 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ if (HDF5_JAVA_PACK_JRE)
USE_SOURCE_PERMISSIONS
)
endif ()

message (VERBOSE "Java version is ${Java_VERSION_STRING}")
if (Java_VERSION_STRING VERSION_GREATER_EQUAL "22.0.0")
add_subdirectory (jsrc)
if (NOT HDF5_EXTERNALLY_CONFIGURED AND BUILD_TESTING)
add_subdirectory (jtest)
endif ()
endif ()
33 changes: 33 additions & 0 deletions java/jsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required (VERSION 3.18)
project (HDF5_JAVA_JSRC Java)

set (CMAKE_VERBOSE_MAKEFILE 1)

set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${HDF5_JAVA_JSRC_SOURCE_DIR};${HDF5_JAVA_JSRC_BINARY_DIR}")

file (GLOB HDF5_JAVA_JSRC_SOURCES LIST_DIRECTORIES false ${HDF5_JAVA_JSRC_SOURCE_DIR}/org/hdfgroup/javahdf5/*.java)

file (WRITE ${PROJECT_BINARY_DIR}/Manifest.txt
"
"
)

set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_LOGGING_JAR}")

add_jar (${HDF5_JAVA_JSRC_LIB_TARGET} OUTPUT_NAME "${HDF5_JAVA_JSRC_LIB_TARGET}-${HDF5_PACKAGE_VERSION}" OUTPUT_DIR ${CMAKE_JAVA_TARGET_OUTPUT_DIR} MANIFEST ${PROJECT_BINARY_DIR}/Manifest.txt ${HDF5_JAVA_JSRC_SOURCES})
install_jar (${HDF5_JAVA_JSRC_LIB_TARGET} LIBRARY DESTINATION ${HDF5_INSTALL_JAR_DIR} COMPONENT libraries)
#if (NOT WIN32)
# install_jni_symlink (${HDF5_JAVA_JSRC_LIB_TARGET} ${HDF5_INSTALL_JAR_DIR} libraries)
#endif ()

get_target_property (${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE ${HDF5_JAVA_JSRC_LIB_TARGET} JAR_FILE)
SET_GLOBAL_VARIABLE (HDF5_JAVA_XJARS_TO_EXPORT "${HDF5_JAVA_XJARS_TO_EXPORT};${${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE}")
SET_GLOBAL_VARIABLE (HDF5_JAVA_XJARS ${${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE})

set_target_properties (${HDF5_JAVA_JSRC_LIB_TARGET} PROPERTIES FOLDER libraries/java)
if (HDF5_ENABLE_FORMATTERS)
clang_format (HDF5_JAVA_SRC_FORMAT ${HDF5_JAVA_JSRC_SOURCES})
endif ()

set (CMAKE_JAVA_INCLUDE_PATH "")

56 changes: 56 additions & 0 deletions java/jsrc/org/hdfgroup/javahdf5/FILE.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Generated by jextract

package org.hdfgroup.javahdf5;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
* {@snippet lang=c :
* typedef struct _IO_FILE {
* int _flags;
* char *_IO_read_ptr;
* char *_IO_read_end;
* char *_IO_read_base;
* char *_IO_write_base;
* char *_IO_write_ptr;
* char *_IO_write_end;
* char *_IO_buf_base;
* char *_IO_buf_end;
* char *_IO_save_base;
* char *_IO_backup_base;
* char *_IO_save_end;
* struct _IO_marker *_markers;
* struct _IO_FILE *_chain;
* int _fileno;
* int _flags2;
* __off_t _old_offset;
* unsigned short _cur_column;
* signed char _vtable_offset;
* char _shortbuf[1];
* _IO_lock_t *_lock;
* __off64_t _offset;
* struct _IO_codecvt *_codecvt;
* struct _IO_wide_data *_wide_data;
* struct _IO_FILE *_freeres_list;
* void *_freeres_buf;
* size_t __pad5;
* int _mode;
* char _unused2[20];
* } FILE
* }
*/
public class FILE extends _IO_FILE {

FILE() {
// Should not be called directly
}
}

Loading

0 comments on commit 4e5e7b8

Please sign in to comment.