Skip to content

Commit

Permalink
fix: avoid IGUANA_INCLUDE_PATH var
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Dec 24, 2023
1 parent 4c11e8c commit 8ff505b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ jobs:
run: |
test_file=$(find validation_files -name "*.hipo" | head -n1)
source iguana/bin/this_iguana.sh
echo "CI VARS: ------------------"
echo "PKG_CONFIG_PATH = $PKG_CONFIG_PATH"
echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH"
echo "PYTHONPATH = $PYTHONPATH"
# .github/test-dependent-build.sh ${{ matrix.tool }} $test_file 1
.github/test-dependent-build.sh ${{ matrix.tool }} $test_file 1
# documentation
#########################################################
Expand Down
1 change: 1 addition & 0 deletions bind/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Then install packages with:
```bash
pip install -r bind/python/requirements.txt
```
**Note**: If you get an error stating that `"Python.h"` cannot be found, you need to install Python development headers and static libraries; depending on your OS and package manager, the relevant package to install is something like `python3-dev` or `python3-devel`.

## Building the Python Bindings
Use the `--python` option when running `configure.py`, or edit your `build-iguana.ini` file
Expand Down
19 changes: 13 additions & 6 deletions bind/python/pyiguana/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#!/usr/bin/env python3

import os, cppyy
import os, cppyy, pkgconfig

# add include dirs to cpppyy
iguana_include_path = os.environ.get('IGUANA_INCLUDE_PATH')
if iguana_include_path is not None:
for path in iguana_include_path.split(':'):
# read iguana pkg-config
PKG = 'iguana'
if not pkgconfig.exists(PKG):
raise Exception(f'failed to find pkg-config package "{PKG}"')
pkg_vars = pkgconfig.variables(PKG)

# add include dirs to cppyy
for var in ['includedir', 'dep_includedirs']:
include_path = pkg_vars[var]
for path in include_path.split(':'):
cppyy.add_include_path(path)

# add libraries to cppyy
[ cppyy.load_library(lib) for lib in [ 'hipo4', 'IguanaServices', 'IguanaAlgorithms' ]]
for lib in ['hipo4', 'IguanaServices', 'IguanaAlgorithms']:
cppyy.load_library(lib)

# include header file(s)
def include(*headers):
Expand Down
1 change: 1 addition & 0 deletions bind/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ cppyy==3.1.2
cppyy-backend==1.15.2
cppyy-cling==6.30.0
CPyCppyy==1.12.16
pkgconfig==1.5.5
14 changes: 9 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ fmt_dep = dependency('fmt', version: '>=9.1.0')
hipo_dep = dependency('hipo4', version: '>=1.3', method: 'cmake')

# dependency library paths
# TODO: maybe we don't need all of this if we can static-link libhipo
dep_lib_paths = []
dep_include_paths = []
dep_lib_paths = []
dep_include_paths = []
dep_pkg_config_paths = []
foreach path : get_option('cmake_prefix_path')
dep_lib_paths += path / 'lib'
dep_include_paths += path / 'include'
endforeach
foreach path : get_option('pkg_config_path')
dep_pkg_config_paths += path
endforeach

# general project vars
project_lib_rpath = '$ORIGIN'
project_inc = include_directories('src')
project_libs = []
project_deps = declare_dependency(dependencies: [ fmt_dep, hipo_dep ])
project_pkg_vars = [
'dep_libdirs=' + ':'.join(dep_lib_paths),
'dep_includedirs=' + ':'.join(dep_include_paths),
'dep_libdirs=' + ':'.join(dep_lib_paths),
'dep_includedirs=' + ':'.join(dep_include_paths),
'dep_pkgconfigdirs=' + ':'.join(dep_pkg_config_paths),
]

# build and install shared libraries
Expand Down
13 changes: 2 additions & 11 deletions meson/this_iguana.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@ thisDir=$(cd $(dirname $thisEnv)/.. && pwd -P)

# append to PKG_CONFIG_PATH
export PKG_CONFIG_PATH=$thisDir/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
dep_pkgconfigdirs=$(pkg-config --variable dep_pkgconfigdirs iguana)
[ -n "${dep_pkgconfigdirs-}" ] && export PKG_CONFIG_PATH=$dep_pkgconfigdirs${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}

# append to LD_LIBRARY_PATH
for var in libdir dep_libdirs; do
dir=$(pkg-config --variable $var iguana)
[ -n "${dir-}" ] && export LD_LIBRARY_PATH=$dir${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
done

# IGUANA_INCLUDE_PATH
#
###### TODO: can we avoid this? #####
#
unset IGUANA_INCLUDE_PATH
for var in includedir dep_includedirs; do
dir=$(pkg-config --variable $var iguana)
[ -n "${dir-}" ] && export IGUANA_INCLUDE_PATH=$dir${IGUANA_INCLUDE_PATH:+:${IGUANA_INCLUDE_PATH}}
done

# append to PYTHONPATH
iguana_pythonpath=$(pkg-config --variable pythonpath iguana)
[ -n "${iguana_pythonpath-}" ] && export PYTHONPATH=$iguana_pythonpath${PYTHONPATH:+:${PYTHONPATH}}
Expand All @@ -33,7 +25,6 @@ Iguana Environment Variables
----------------------------
PKG_CONFIG_PATH = ${PKG_CONFIG_PATH-}
LD_LIBRARY_PATH = ${LD_LIBRARY_PATH-}
IGUANA_INCLUDE_PATH = ${IGUANA_INCLUDE_PATH-}
PYTHONPATH = ${PYTHONPATH-}
----------------------------
"""

0 comments on commit 8ff505b

Please sign in to comment.