Skip to content

Commit

Permalink
[SCons] Link Python module to Cantera shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Feb 3, 2023
1 parent 5ae4847 commit 8114f2f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -384,6 +384,7 @@ jobs:
- name: Run the examples
# See https://unix.stackexchange.com/a/392973 for an explanation of the -exec part
run: |
export LD_LIBRARY_PATH=build/lib
find samples/python -type f -iname "*.py" \
-exec sh -c 'for n; do echo "$n" | tee -a results.txt && python3 "$n" >> results.txt || exit 1; done' sh {} +
env:
Expand Down
3 changes: 3 additions & 0 deletions SConstruct
Expand Up @@ -2087,6 +2087,9 @@ else:
for loc in locations:
env[f"inst_{loc}"] = env[f"ct_{loc}"].replace(env["ct_installroot"], instRoot)

if env['use_rpath_linkage']:
env.Append(RPATH=env['ct_libdir'])

# **************************************
# *** Set options needed in config.h ***
# **************************************
Expand Down
6 changes: 6 additions & 0 deletions doc/SConscript
Expand Up @@ -8,6 +8,12 @@ Import('env', 'build', 'install')

localenv = env.Clone()

# Add build/lib in order to find Cantera shared library
if env['OS'] == 'Darwin':
localenv.PrependENVPath('DYLD_LIBRARY_PATH', Dir('#build/lib').abspath)
else:
localenv.PrependENVPath('LD_LIBRARY_PATH', Dir('#build/lib').abspath)

Page = namedtuple('Page', ['name', 'title', 'objects'])


Expand Down
16 changes: 15 additions & 1 deletion interfaces/cython/SConscript
Expand Up @@ -45,6 +45,11 @@ for pyxfile in multi_glob(localenv, "cantera", "pyx"):
cython_obj.append(obj)
cython_obj.extend(env['python_ext_objects'])

if not env['system_fmt']:
# Workaround until we can figure out why all the necessary symbols aren't
# being exported from fmt
cython_obj.extend(localenv['fmt_targets'])

module_ext = localenv["py_module_ext"]
ext = localenv.LoadableModule(f"cantera/_cantera{module_ext}",
cython_obj, LIBPREFIX="", SHLIBSUFFIX=module_ext,
Expand All @@ -62,7 +67,16 @@ env['python_extension'] = ext
localenv.Depends(mod, [ext, dataFiles, setup_cfg, readme, license,
"setup.py", "pyproject.toml",
"cantera/test/README.txt", "cantera/examples/README.txt"])
localenv.Depends(ext, localenv['cantera_staticlib'])

if env['OS'] == 'Windows':
# On Windows, the cantera library directory is likely not to be on the path.
# However, Windows does search the directory containing a library (i.e. the
# Python extension module) for DLL dependencies.
dll = [f for f in localenv['cantera_shlib'] if f.name.endswith('.dll')][0]
copy_dll = localenv.Command(f'cantera/{dll.name}', dll, Copy("$TARGET", "$SOURCE"))
localenv.Depends(ext, copy_dll)
else:
localenv.Depends(ext, localenv['cantera_shlib'])

for f in (multi_glob(localenv, 'cantera', 'py') +
multi_glob(localenv, 'cantera/*', 'py')):
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/setup.cfg.in
Expand Up @@ -51,7 +51,7 @@ packages =
# The module extension needs to be here since we don't want setuptools to compile
# the extension, so there are no ``source`` files in the setup.py ``extension`` and
# we have to treat the module as package data.
cantera = *.pxd, *@py_module_ext@, test/*.txt, examples/*.txt, data/*.*
cantera = *.pxd, *.dll, *@py_module_ext@, test/*.txt, examples/*.txt, data/*.*

[options.extras_require]
hdf5 = h5py
Expand Down
2 changes: 1 addition & 1 deletion site_scons/buildutils.py
Expand Up @@ -1285,7 +1285,7 @@ def setup_python_env(env):
plat = info['plat'].replace('-', '_').replace('.', '_')
numpy_include = info["numpy_include"]
env.Prepend(CPPPATH=[Dir('#include'), inc, numpy_include])
env.Prepend(LIBS=env['cantera_libs'])
env.Prepend(LIBS=env['cantera_shared_libs'])

# Fix the module extension for Windows from the sysconfig library.
# See https://github.com/python/cpython/pull/22088 and
Expand Down

0 comments on commit 8114f2f

Please sign in to comment.