Skip to content

Commit

Permalink
Update cutest_delegate.f90
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison authored Jun 13, 2024
1 parent b1474b2 commit 23dba6e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 27 deletions.
50 changes: 40 additions & 10 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
task:
matrix:
- name: Meson / freebsd/gcc-12/Int32
- name: Meson / freebsd/gcc-12/Mode-static/Int32
freebsd_instance:
image: freebsd-13-3-release-amd64
env:
- INT64: "false"
- name: Meson / freebsd/gcc-12/Int64
- MODE: "static"
- name: Meson / freebsd/gcc-12/Mode-shared/Int32
freebsd_instance:
image: freebsd-13-3-release-amd64
env:
- INT64: "false"
- MODE: "shared"
- name: Meson / freebsd/gcc-12/Mode-static/Int64
freebsd_instance:
image: freebsd-13-3-release-amd64
env:
- INT64: "true"
- MODE: "static"
- name: Meson / freebsd/gcc-12/Mode-shared/Int64
freebsd_instance:
image: freebsd-13-3-release-amd64
env:
- INT64: "true"
- name: Meson / macos-silicon/gcc-14/Int32
- MODE: "shared"
- name: Meson / macos-silicon/gcc-14/Mode-static/Int32
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
env:
- INT64: "false"
- name: Meson / macos-silicon/gcc-14/Int64
- MODE: "static"
- name: Meson / macos-silicon/gcc-14/Mode-shared/Int32
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
env:
- INT64: "false"
- MODE: "shared"
- name: Meson / macos-silicon/gcc-14/Mode-static/Int64
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
env:
- INT64: "true"
- MODE: "static"
- name: Meson / macos-silicon/gcc-14/Mode-shared/Int64
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
env:
- INT64: "true"
- MODE: "shared"
dependencies_script: |
echo $(uname)
if [ "$(uname)" = "FreeBSD" ]; then
Expand All @@ -29,13 +57,15 @@ task:
fi
configure_script: |
if [ "$(uname -s)" = "FreeBSD" ]; then
FC=gfortran12 CC=gcc12 CXX=g++12 meson setup builddir -Dcutest_int64=${INT64} \
-Dquadruple=true \
--prefix=${CIRRUS_WORKING_DIR}/../meson
FC=gfortran12 CC=gcc12 CXX=g++12 meson setup builddir --prefix=${CIRRUS_WORKING_DIR}/../meson \
-Ddefault_library=${MODE} \
-Dcutest_int64=${INT64} \
-Dquadruple=true
else
FC=gfortran-14 CC=gcc-14 CXX=g++-14 meson setup builddir -Dcutest_int64=${INT64} \
-Dquadruple=true \
--prefix=${CIRRUS_WORKING_DIR}/../meson
FC=gfortran-14 CC=gcc-14 CXX=g++-14 meson setup builddir --prefix=${CIRRUS_WORKING_DIR}/../meson \
-Ddefault_library=${MODE} \
-Dcutest_int64=${INT64} \
-Dquadruple=true
fi
build_script: |
meson compile -C builddir
Expand Down
35 changes: 34 additions & 1 deletion .github/workflows/meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,67 @@ on:
types: [opened, synchronize, reopened]
jobs:
build:
name: ${{ matrix.os }}/${{ matrix.compiler }}-v${{ matrix.version }}/Int${{ matrix.int }}
name: ${{ matrix.os }}/${{ matrix.compiler }}-v${{ matrix.version }}/Mode-${{ matrix.mode }}/Int${{ matrix.int }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-13]
arch: ['x64']
version: ['11']
int: ['32', '64']
mode: ['static', 'shared']
include:
- compiler: gcc
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '32'
mode: 'static'
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '32'
mode: 'shared'
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '64'
mode: 'static'
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '64'
mode: 'shared'
- os: windows-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'static'
- os: windows-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'static'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'static'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'shared'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'static'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'shared'
# - os: ubuntu-latest
# compiler: nvidia-hpc
# version: '24.05'
Expand Down Expand Up @@ -79,8 +106,14 @@ jobs:
if [[ "${{matrix.int}}" == "64" ]]; then
INT64="true"
fi
if [[ "${{matrix.mode}}" == "static" ]]; then
MODE="static"
else
MODE="shared"
fi
meson setup builddir --buildtype=debug \
--prefix=$GITHUB_WORKSPACE/cutest \
-Ddefault_library=${MODE} \
-Dquadruple=true \
-Dcutest_int64=$INT64
Expand Down
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ endif
if cutest_int64
pp_options += '-DINTEGER_64'
endif
if host_machine.system() == 'windows'
pp_options += '-DWINDOWS'
endif

# Library libcutest_single or libcutest_single_64
libcutest_single_name = 'cutest_single'
Expand Down
51 changes: 36 additions & 15 deletions src/tools/cutest_delegate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,52 @@
#define RANGE_BIND_NAME "range_"
#endif

#ifdef WINDOWS
#define cutest_dlopen LoadLibrary
#define DLOPEN_BIND_NAME "LoadLibraryA"
#define cutest_dlsym GetProcAddress
#define DLSYM_BIND_NAME "GetProcAddress"
#define cutest_dlclose FreeLibrary
#define DLCLOSE_BIND_NAME "FreeLibrary"
#else
#define cutest_dlopen dlopen
#define DLOPEN_BIND_NAME "dlopen"
#define cutest_dlsym dlsym
#define DLSYM_BIND_NAME "dlsym"
#define cutest_dlclose dlclose
#define DLCLOSE_BIND_NAME "dlclose"
#endif

module cutest_delegate_r
use, intrinsic :: iso_c_binding
implicit none

! Interface pour dlopen
! Interface for dlopen / LoadLibrary
interface
function dlopen(name, mode) bind(C, name="dlopen")
function cutest_dlopen(name, mode) bind(C, name=DLOPEN_BIND_NAME)
use iso_c_binding, only: c_ptr, c_int, c_char
type(c_ptr) :: dlopen
type(c_ptr) :: cutest_dlopen
character(kind=c_char), dimension(*) :: name
integer(kind=c_int) :: mode
end function dlopen
end function cutest_dlopen
end interface

! Interface pour dlsym
! Interface for dlsym / GetProcAddress
interface
function dlsym(handle, symbol) bind(C, name="dlsym")
function cutest_dlsym(handle, symbol) bind(C, name=DLSYM_BIND_NAME)
use iso_c_binding, only: c_funptr, c_ptr, c_char
type(c_funptr) :: dlsym
type(c_funptr) :: cutest_dlsym
type(c_ptr), value :: handle
character(kind=c_char), dimension(*) :: symbol
end function dlsym
end function cutest_dlsym
end interface

! Interface for dlclose / FreeLibrary
interface
subroutine cutest_dlclose(handle) bind(C, name=DLCLOSE_BIND_NAME)
use iso_c_binding, only: c_ptr
type(c_ptr), value :: handle
end subroutine cutest_dlclose
end interface

! Constantes pour les modes d'ouverture de bibliothèques
Expand All @@ -65,23 +89,22 @@ subroutine load_routines(libname) bind(C, name=LOAD_ROUTINE_NAME)
character(kind=c_char), dimension(*), intent(in) :: libname

! Charge la bibliothèque dynamique
lib_handle = dlopen(libname, RTLD_LAZY)
lib_handle = cutest_dlopen(libname, RTLD_LAZY)
if (.not. c_associated(lib_handle)) then
stop "Unable to load library"
end if

! Récupère les adresses des fonctions
ptr_elfun = dlsym(lib_handle, "elfun"//c_null_char)
ptr_group = dlsym(lib_handle, "group"//c_null_char)
ptr_range = dlsym(lib_handle, "range"//c_null_char)
ptr_elfun = cutest_dlsym(lib_handle, ELFUN_BIND_NAME//c_null_char)
ptr_group = cutest_dlsym(lib_handle, GROUP_BIND_NAME//c_null_char)
ptr_range = cutest_dlsym(lib_handle, RANGE_BIND_NAME//c_null_char)

! Associe les pointeurs de procédure Fortran avec les adresses obtenues
call c_f_procpointer(ptr_elfun, fun_elfun)
call c_f_procpointer(ptr_group, fun_group)
call c_f_procpointer(ptr_range, fun_range)
end subroutine load_routines

! Routine pour appeler la fonction elfun
subroutine elfun() bind(C, name=ELFUN_BIND_NAME)
if (associated(fun_elfun)) then
call fun_elfun()
Expand All @@ -90,7 +113,6 @@ subroutine elfun() bind(C, name=ELFUN_BIND_NAME)
end if
end subroutine elfun

! Routine pour appeler la fonction group
subroutine group() bind(C, name=GROUP_BIND_NAME)
if (associated(fun_group)) then
call fun_group()
Expand All @@ -99,7 +121,6 @@ subroutine group() bind(C, name=GROUP_BIND_NAME)
end if
end subroutine group

! Routine pour appeler la fonction range
subroutine range() bind(C, name=RANGE_BIND_NAME)
if (associated(fun_range)) then
call fun_range()
Expand Down
2 changes: 1 addition & 1 deletion src/tools/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ libcutest_src += files('ccfg.F90',
'varnames.F90')

if get_option('default_library') == 'shared'
libcutest_src += files('cutest_delegate.f90')
libcutest_src += files('cutest_delegate.f90')
endif

0 comments on commit 23dba6e

Please sign in to comment.