Skip to content

Commit

Permalink
fix cython
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jun 10, 2024
1 parent b5f727e commit 60ada09
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bindings/python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TESTS = test_basic.py test_detail.py test_arm.py test_aarch64.py test_m68k.py te
TESTS += test_ppc.py test_sparc.py test_systemz.py test_x86.py test_xcore.py test_tms320c64x.py
TESTS += test_m680x.py test_skipdata.py test_mos65xx.py test_bpf.py test_riscv.py
TESTS += test_evm.py test_tricore.py test_wasm.py test_sh.py test_hppa.py
TESTS += test_lite.py test_iter.py test_customized_mnem.py test_alpha.py
TESTS += test_lite.py test_iter.py test_customized_mnem.py test_alpha.py test_xtensa.py

check:
@for t in $(TESTS); do \
Expand Down
91 changes: 69 additions & 22 deletions bindings/python/setup_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# adapted from commit e504b81 of Nguyen Tan Cong
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
IS_64BITS = sys.maxsize > 2**32
IS_64BITS = sys.maxsize > 2 ** 32

# are we building from the repository or from a source distribution?
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -69,7 +69,50 @@
compile_args = ['-O3', '-fomit-frame-pointer', '-I' + HEADERS_DIR]
link_args = ['-L' + LIBS_DIR]

ext_module_names = ['arm', 'arm_const', 'aarch64', 'aarch64_const', 'm68k', 'm68k_const', 'm680x', 'm680x_const', 'mips', 'mips_const', 'ppc', 'ppc_const', 'x86', 'x86_const', 'sparc', 'sparc_const', 'systemz', 'sysz_const', 'xcore', 'xcore_const', 'tms320c64x', 'tms320c64x_const', 'evm', 'evm_const', 'mos65xx', 'mos65xx_const', 'wasm', 'wasm_const', 'bpf', 'bpf_const', 'riscv', 'riscv_const', 'sh', 'sh_const', 'tricore', 'tricore_const', 'alpha', 'alpha_const', 'hppa', 'hppa_const' ]
ext_module_names = [
"arm",
"arm_const",
"aarch64",
"aarch64_const",
"m68k",
"m68k_const",
"m680x",
"m680x_const",
"mips",
"mips_const",
"ppc",
"ppc_const",
"x86",
"x86_const",
"sparc",
"sparc_const",
"systemz",
"sysz_const",
"xcore",
"xcore_const",
"tms320c64x",
"tms320c64x_const",
"evm",
"evm_const",
"mos65xx",
"mos65xx_const",
"wasm",
"wasm_const",
"bpf",
"bpf_const",
"riscv",
"riscv_const",
"sh",
"sh_const",
"tricore",
"tricore_const",
"alpha",
"alpha_const",
"hppa",
"hppa_const",
"xtensa",
"xtensa_const",
]

ext_modules = [Extension("capstone.ccapstone",
["pyx/ccapstone.pyx"],
Expand All @@ -90,6 +133,7 @@ def clean_bins():
shutil.rmtree(LIBS_DIR, ignore_errors=True)
shutil.rmtree(HEADERS_DIR, ignore_errors=True)


def copy_pysources():
for fname in os.listdir(PYPACKAGE_DIR):
if not fname.endswith('.py'):
Expand All @@ -100,6 +144,7 @@ def copy_pysources():
else:
shutil.copy(os.path.join(PYPACKAGE_DIR, fname), os.path.join(CYPACKAGE_DIR, fname + 'x'))


def build_libraries():
"""
Prepare the capstone directory for a binary distribution or installation.
Expand Down Expand Up @@ -134,7 +179,8 @@ def build_libraries():
if not os.path.exists("build"): os.mkdir("build")
os.chdir("build")
# Only build capstone.dll
os.system('cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_SHARED=ON -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "NMake Makefiles" ..')
os.system(
'cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_SHARED=ON -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "NMake Makefiles" ..')
os.system("cmake --build .")
else: # Unix incl. cygwin
os.system("CAPSTONE_BUILD_CORE_ONLY=yes bash ./make.sh")
Expand All @@ -152,9 +198,10 @@ def run(self):
build_libraries()
return build.run(self)


# clean package directory first
#import os.path, shutil, sys
#for f in sys.path:
# import os.path, shutil, sys
# for f in sys.path:
# if f.endswith('packages'):
# pkgdir = os.path.join(f, 'capstone')
# #print(pkgdir)
Expand All @@ -164,23 +211,23 @@ def run(self):
# pass

setup(
provides = ['capstone'],
package_dir = {'capstone' : 'pyx'},
packages = ['capstone'],
name = 'capstone',
version = VERSION,
cmdclass = {'build_ext': build_ext, 'build': custom_build},
ext_modules = ext_modules,
author = 'Nguyen Anh Quynh',
author_email = '[email protected]',
description = 'Capstone disassembly engine',
url = 'https://www.capstone-engine.org',
classifiers = [
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
provides=['capstone'],
package_dir={'capstone': 'pyx'},
packages=['capstone'],
name='capstone',
version=VERSION,
cmdclass={'build_ext': build_ext, 'build': custom_build},
ext_modules=ext_modules,
author='Nguyen Anh Quynh',
author_email='[email protected]',
description='Capstone disassembly engine',
url='https://www.capstone-engine.org',
classifiers=[
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
include_package_data=True,
package_data={
"capstone": ["lib/*", "include/capstone/*"],
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/test_xtensa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import print_function
from capstone import *
from capstone.tricore import *
from capstone.xtensa import *
from xprint import to_hex, to_x

all_tests = (
Expand Down

0 comments on commit 60ada09

Please sign in to comment.