fix(python): fully working and portable python build

This commit is contained in:
2026-06-11 13:58:17 -04:00
parent 0e4cdcd278
commit 1540d2c4b8
13 changed files with 84 additions and 23 deletions

View File

@@ -2,7 +2,8 @@ composition_p = subproject('libcomposition',
default_options: [
'pkg_config=' + get_option('pkg_config').to_string(),
'build_tests=' + get_option('build_tests').to_string(),
'build_examples=false'
'build_examples=false',
'build_python=' + get_option('build_python').to_string()
])
comp_dep = composition_p.get_variable('composition_dep')
libcomposition = composition_p.get_variable('libcomposition')

View File

@@ -2,6 +2,7 @@ config_p = subproject('libconfig',
default_options:[
'pkg_config=' + get_option('pkg_config').to_string(),
'build_tests=' + get_option('build_tests').to_string(),
'build_examples=false'
])
'build_examples=false',
'build_python=' + get_option('build_python').to_string()
])
config_dep = config_p.get_variable('config_dep')

View File

@@ -1,8 +1,9 @@
const_p = subproject('libconstants', default_options: [
'pkg_config=' + get_option('pkg_config').to_string(),
'build_tests=' + get_option('build_tests').to_string(),
'build_examples=false'
])
'build_examples=false',
'build_python=' + get_option('build_python').to_string()
])
const_dep = const_p.get_variable('const_dep')
libconst = const_p.get_variable('libconst')

View File

@@ -1,7 +1,8 @@
logging_p = subproject('liblogging', default_options: [
'pkg_config=' + get_option('pkg_config').to_string(),
'build_tests=' + get_option('build_tests').to_string(),
'build_examples=false'
'build_examples=false',
'build_python=' + get_option('build_python').to_string()
])
liblogging = logging_p.get_variable('liblogging')

View File

@@ -1,16 +1,16 @@
if get_option('build_lib_comp') or get_option('build_lib_all') or get_option('build_python')
subdir('libcomposition')
endif
if get_option('build_lib_config') or get_option('build_lib_all') or get_option('build_python')
subdir('libconfig')
endif
if get_option('build_lib_const') or get_option('build_lib_all') or get_option('build_python')
subdir('libconstants')
endif
if get_option('build_lib_log') or get_option('build_lib_all')
if get_option('build_lib_log') or get_option('build_lib_all') or get_option('build_python')
subdir('liblogging')
endif
if get_option('build_lib_plugin') or get_option('build_lib_all')
if get_option('build_lib_comp') or get_option('build_lib_all') or get_option('build_python')
subdir('libcomposition')
endif
if get_option('build_lib_plugin') or get_option('build_lib_all') and not get_option('build_python')
subdir('libplugin')
endif

View File

@@ -1,5 +1,10 @@
py_installation = import('python').find_installation('python3', pure: false)
if host_machine.system() == 'darwin'
fourdst_ext_rpath = '@loader_path/lib'
else
fourdst_ext_rpath = '$ORIGIN/lib'
endif
py_mod = py_installation.extension_module(
'_phys',
sources: [
@@ -16,6 +21,8 @@ py_mod = py_installation.extension_module(
],
cpp_args : ['-UNDEBUG'],
install : true,
build_rpath: fourdst_ext_rpath,
install_rpath: fourdst_ext_rpath,
subdir: 'fourdst',
)

View File

@@ -1,8 +1,15 @@
project('fourdst', 'cpp', version: 'v0.10.3', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
project('fourdst', 'cpp', version: 'v0.10.4', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
add_project_arguments('-fvisibility=default', language: 'cpp')
if get_option('build_python')
py_installation = import('python').find_installation('python3', pure: false)
fourdst_wheel_libdir = 'fourdst/lib' # relative to the python platlib
fourdst_wheel_headerdir = 'fourdst/include'
else
fourdst_wheel_libdir = ''
fourdst_wheel_headerdir = ''
endif
# Configure vendor libraries
subdir('build-config')

View File

@@ -1,9 +1,5 @@
[build-system]
requires = [
"meson-python>=0.15.0", # Use a recent version
"meson>=1.6.0", # Specify your Meson version requirement
"pybind11>=2.10" # pybind11 headers needed at build time
]
requires = ["meson-python>=0.19,<0.20", "meson>=1.9.1,<1.10", "pybind11>=2.10"]
build-backend = "mesonpy"
[project]
@@ -33,6 +29,11 @@ dependencies = [
[project.scripts]
fourdst-cli = "fourdst.cli.main:app"
fourdst-compiler-flags = "fourdst:get_compiler_flags_formatted"
fourdst-include-dirs = "fourdst:get_include_dirs"
fourdst-lib-dirs = "fourdst:get_lib_dirs"
fourdst-rpath-flags = "fourdst:get_rpath_flags"
fourdst-version = "fourdst:print_fourdst_version"
[tool.meson-python.args]
setup = [

View File

@@ -20,3 +20,45 @@ try:
__version__ = version("fourdst")
except PackageNotFoundError:
__version__ = "0.0.0+unknown"
import os
from pathlib import Path
from typing import List
_PACKAGE_DIR = Path(__file__).resolve().parent
def get_lib_dirs() -> List[str]:
return [
os.fspath(_PACKAGE_DIR / "lib"),
os.fspath(_PACKAGE_DIR / "lib" / "vendor"),
]
def get_include_dirs() -> List[str]:
return [
os.fspath(_PACKAGE_DIR / "include"),
os.fspath(_PACKAGE_DIR / "include" / "fourdst" / "vendor"),
]
def get_rpath_flags() -> List[str]:
return ["-Wl,-rpath," + os.fspath(_PACKAGE_DIR / "lib")]
def get_lib_flags() -> List[str]:
flags = ["-L" + d for d in get_lib_dirs()]
flags += ["-lcomposition", "-llogging", "-lconst", "-lreflect_cpp"]
flags += get_rpath_flags()
return flags
def get_include_flags() -> List[str]:
return ["-I" + d for d in get_include_dirs()]
def get_compiler_flags() -> List[str]:
return get_include_flags() + get_lib_flags()
def get_compiler_flags_formatted() -> int:
flags = get_compiler_flags()
print(' '.join(flags))
return 0
def print_fourdst_version() -> int:
print("fourdst version: " + __version__)
return 0

View File

@@ -1,4 +1,4 @@
[wrap-git]
url = https://github.com/4D-STAR/libcomposition.git
revision = v2.4.3
revision = v2.4.8
depth = 1

View File

@@ -1,4 +1,4 @@
[wrap-git]
url = https://github.com/4D-STAR/libconfig.git
revision = v2.2.6
revision = v2.2.10
depth = 1

View File

@@ -1,4 +1,4 @@
[wrap-git]
url = https://github.com/4D-STAR/libconstants.git
revision = v1.1.3
revision = v1.1.7
depth = 1

View File

@@ -1,4 +1,4 @@
[wrap-git]
url = https://github.com/4D-STAR/liblogging.git
revision = v1.1.3
revision = v1.1.7
depth = 1