diff --git a/Cargo.toml b/Cargo.toml index 57d708b..277f868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ ndarray = "0.15.6" numpy = "0.20" pyo3 = { version = "0.20", features = ["extension-module", "multiple-pymethods"] } pyo3-log = "0.9" -tucanos = { git = "https://github.com/tucanos/tucanos.git", rev = "f94ef7d" } +tucanos = { git = "https://github.com/tucanos/tucanos.git", rev = "ca44516" } [features] default = ["parry"] diff --git a/README.md b/README.md index bffa584..d7f3f7e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,18 @@ Python bindings to [tucanos](https://github.com/tucanos/tucanos.git) pip install git+https://github.com/tucanos/pytucanos.git ``` +To install tucanos in debug mode: + +```bash +pip install -C debug=true git+https://github.com/tucanos/pytucanos.git +``` + +To install Tucanos with [libmeshb](https://github.com/LoicMarechal/libMeshb) support: + +```bash +pip install -C meshb=true git+https://github.com/tucanos/pytucanos.git +``` + # Benchmarks ## `.meshb/.solb` I/O diff --git a/_custom_build/backend.py b/_custom_build/backend.py new file mode 100644 index 0000000..3785078 --- /dev/null +++ b/_custom_build/backend.py @@ -0,0 +1,55 @@ +# adapted from https://github.com/python-pillow/Pillow/blob/main/_custom_build/backend.py +# see also https://peps.python.org/pep-0517/#in-tree-build-backends +import sys +from setuptools.build_meta import build_wheel, build_editable + +FEATURES = ["meshb", "nlopt"] + + +def update_argv(config_settings): + if config_settings: + flags = [] + if config_settings.get("debug", "false").lower() == "true": + flags += ["--debug"] + for feature in FEATURES: + if config_settings.get(feature, "false").lower() == "true": + flags += ["--features=%s" % feature] + if flags: + sys.argv = sys.argv[:1] + ["build_rust"] + flags + sys.argv[1:] + + +backend_class = build_wheel.__self__.__class__ + + +class _CustomBuildMetaBackend(backend_class): + def run_setup(self, setup_script="setup.py"): + update_argv(self.config_settings) + return super().run_setup(setup_script) + + def build_wheel( + self, wheel_directory, config_settings=None, metadata_directory=None + ): + self.config_settings = config_settings + return super().build_wheel(wheel_directory, config_settings, metadata_directory) + + +build_wheel = _CustomBuildMetaBackend().build_wheel + +backend_class = build_editable.__self__.__class__ + + +class _CustomBuildMetaBackend(backend_class): + def run_setup(self, setup_script="setup.py"): + update_argv(self.config_settings) + return super().run_setup(setup_script) + + def build_editable( + self, wheel_directory, config_settings=None, metadata_directory=None + ): + self.config_settings = config_settings + return super().build_editable( + wheel_directory, config_settings, metadata_directory + ) + + +build_editable = _CustomBuildMetaBackend().build_editable diff --git a/pyproject.toml b/pyproject.toml index 31ffe04..8ec9169 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,4 @@ [build-system] requires = ["setuptools", "wheel", "setuptools-rust"] +build-backend = "backend" +backend-path = ["_custom_build"] \ No newline at end of file diff --git a/setup.py b/setup.py index fa07c8b..aa526c6 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,25 @@ import setuptools -from setuptools_rust import Binding, RustExtension +from setuptools_rust import Binding, RustExtension, build_rust +import sys + + +class BuildRustCommand(build_rust): + user_options = build_rust.user_options + [ + ("features=", None, "Value for cargo --features") + ] + + def initialize_options(self): + super().initialize_options() + self.features = None + + def finalize_options(self): + super().finalize_options() + ext = self.distribution.rust_extensions[0] + ext.debug = self.debug + ext.release = not self.debug + if self.features: + ext.features = self.features.split(",") -features = [] setuptools.setup( name="pytucanos", @@ -12,10 +30,9 @@ RustExtension( "pytucanos._pytucanos", binding=Binding.PyO3, - features=features, - debug=False, ) ], + cmdclass={"build_rust": BuildRustCommand}, # rust extensions are not zip safe, just like C-extensions. zip_safe=False, )