diff --git a/README.md b/README.md index a9e9906..7969e17 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ For usage information, see [the documentation](doc/README.md). ## Building python plugin Requirements: - rizin > 0.4.1 (needs commit [59b38e6](https://github.com/rizinorg/rizin/commit/59b38e6efaf00b9b9869e0ec5baba4f1b9605f37)) -- meson >= 0.62.2 +- meson >= 1.1.0 - ninja -- python >= 3.7 +- python >= 3.10 - libclang - SWIG diff --git a/meson.build b/meson.build index 2d4e869..3d6214c 100644 --- a/meson.build +++ b/meson.build @@ -117,7 +117,7 @@ if target_swig '-python', '-c++', '-outdir', '@OUTDIR@', '@INPUT@' ], - install: true, + install: host_machine.system() == 'windows', install_dir: [py.get_install_dir(), false] ) swig_py = swig_output[0] @@ -127,15 +127,18 @@ if target_swig rz_core = dependency('rz_core') endif - py.extension_module( + ext_mod = py.extension_module( '_rizin', swig_wrap, dependencies: [ py.dependency(), rz_core, ], - install: true, + install: host_machine.system() == 'windows', ) + if host_machine.system() != 'windows' + meson.add_install_script('py_install.py', swig_py.full_path(), ext_mod.full_path()) + endif endif if target_sphinx @@ -155,4 +158,3 @@ endif if get_option('plugin').enabled() subdir('plugin') endif - diff --git a/py_install.py b/py_install.py new file mode 100755 index 0000000..e4e0b98 --- /dev/null +++ b/py_install.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import os +import shutil +import sys +import sysconfig + +def install_files(scheme): + for file in sys.argv[1:]: + if file.endswith(".py"): + dest_type = 'purelib' + elif file.endswith(".so"): + dest_type = 'platlib' + install_dir = sysconfig.get_path(dest_type, scheme) + shutil.copy(file, install_dir) + print(f"Installing {os.path.basename(file)} to {install_dir}") + +try: + install_files(sysconfig.get_default_scheme()) +except PermissionError: + print("Installing to user site-packages since normal site-packages is not writeable") + install_files(f"{os.name}_user")