-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python package change && PyPI Support (#4)
- Loading branch information
Showing
10 changed files
with
184 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: PyPI 📦 Distribution | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- name: windows_x86_64 | ||
os: windows-latest | ||
- name: macos_x86_64 | ||
os: macos-13 | ||
- name: macos_arm64 | ||
os: macos-15 | ||
- name: manylinux2014_i686 | ||
os: ubuntu-latest | ||
target: i686 | ||
container: messense/manylinux2014-cross:i686 | ||
- name: manylinux2014_x86_64 | ||
os: ubuntu-latest | ||
target: x86_64 | ||
container: messense/manylinux2014-cross:x86_64 | ||
- name: manylinux2014_aarch64 | ||
os: ubuntu-latest | ||
target: aarch64 | ||
container: messense/manylinux2014-cross:aarch64 | ||
|
||
name: ${{ matrix.name }} | ||
runs-on: ${{ matrix.os }} | ||
container: ${{ matrix.container }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: '🦀️ Set up Rust' | ||
if: matrix.os == 'ubuntu-latest' | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
target: ${{ matrix.target }}-unknown-linux-gnu | ||
|
||
- name: '🐍 Set up Python' | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.12 | ||
|
||
- name: '🔧 Install pkg-config' | ||
if: matrix.os == 'ubuntu-latest' | ||
run: | | ||
apt update | ||
apt install -y pkg-config | ||
- name: '🛠️ Install Python build' | ||
run: | | ||
python -m pip install build | ||
- name: '🏗️ Build distribution' | ||
run: | | ||
cd bindings/python | ||
python -m build --wheel --config-setting=--build-option=--plat-name=${{ matrix.name }} | ||
- name: '📤 Upload artifact' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: python-udbserver-${{ matrix.name }} | ||
path: ${{ github.workspace }}/bindings/python/dist/* | ||
|
||
publish: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/tags') | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
pattern: python-udbserver-* | ||
merge-multiple: true | ||
path: dist | ||
|
||
- name: '🚀 Publish distribution to PyPI' | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.pypi_pass }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/target | ||
/build | ||
build | ||
dist | ||
udbserver.egg-info | ||
Cargo.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Python bindings for udbserver | ||
========================= | ||
|
||
This package provides Python bindings for udbserver, allowing you to debug your Unicorn-based projects with GDB. | ||
For more details about udbserver, please check the `project homepage <https://github.com/bet4it/udbserver>`_. | ||
|
||
Installation | ||
----------- | ||
|
||
From PyPI | ||
~~~~~~~~~ | ||
|
||
It's highly recommended to install the Python package via pip:: | ||
|
||
pip install udbserver | ||
|
||
From source | ||
~~~~~~~~~~ | ||
|
||
To build and install this package manually:: | ||
|
||
python3 -m build --wheel | ||
pip install dist/*.whl |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "setuptools-rust", "setuptools_scm[toml]"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "udbserver" | ||
dynamic = ["version"] | ||
license = { text = "MIT License" } | ||
description = "Python bindings of udbserver" | ||
readme = "README.rst" | ||
authors = [{ name = "Bet4", email = "0xbet4@gmail.com" }] | ||
urls = { homepage = "https://github.com/bet4it/udbserver" } | ||
classifiers = [ | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python :: 3", | ||
"Operating System :: POSIX", | ||
"Operating System :: MacOS :: MacOS X", | ||
"Operating System :: Microsoft :: Windows", | ||
"Topic :: Software Development :: Debuggers", | ||
] | ||
dependencies = [ | ||
"unicorn >= 2", | ||
] | ||
|
||
[tool.setuptools] | ||
zip-safe = false | ||
|
||
[tool.setuptools_scm] | ||
root = "../.." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
# encoding: utf-8 | ||
import os | ||
import sysconfig | ||
from setuptools import setup | ||
from setuptools_rust import Binding, RustExtension | ||
from setuptools.command.build_ext import build_ext | ||
from wheel.bdist_wheel import bdist_wheel | ||
|
||
from setuptools import setup, Extension | ||
class CustomBuildExt(build_ext): | ||
def get_ext_filename(self, ext_name): | ||
filename = super().get_ext_filename(ext_name) | ||
suffix = sysconfig.get_config_var('EXT_SUFFIX') | ||
ext = os.path.splitext(filename)[1] | ||
return filename.replace(suffix, '') + ext | ||
|
||
class CustomBdistWheel(bdist_wheel): | ||
def get_tag(self): | ||
_, _, plat = super().get_tag() | ||
return ('py3', 'none', plat) | ||
|
||
rust_module = Extension('udbserver', | ||
sources=['udbserver.c'], | ||
libraries=['udbserver'], | ||
) | ||
|
||
setup (name = 'udbserver', | ||
version = '0.1', | ||
author = 'Bet4', | ||
author_email = '0xbet4@gmail.com', | ||
description = 'Python bindings of udbserver', | ||
url = 'https://github.com/bet4it/udbserver', | ||
license='MIT License', | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3', | ||
'Topic :: Software Development :: Debuggers', | ||
], | ||
ext_modules = [rust_module], | ||
py_modules = [], | ||
) | ||
setup( | ||
name='udbserver', | ||
rust_extensions=[RustExtension('udbserver.libudbserver', binding=Binding.NoBinding, path='../../Cargo.toml', features=['capi'])], | ||
cmdclass={'build_ext': CustomBuildExt, 'bdist_wheel': CustomBdistWheel}, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import ctypes | ||
import sys | ||
from unicorn import Uc | ||
from ctypes import c_void_p, c_uint16, c_uint64 | ||
|
||
_current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
if sys.platform.startswith('win'): | ||
_library_file = "libudbserver.pyd" | ||
else: | ||
_library_file = "libudbserver.so" | ||
|
||
_udbserver_lib = ctypes.cdll.LoadLibrary(os.path.join(_current_dir, _library_file)) | ||
|
||
_udbserver_lib.udbserver.argtypes = [c_void_p, c_uint16, c_uint64] | ||
_udbserver_lib.udbserver.restype = None | ||
|
||
def udbserver(uc: Uc, port: int = 1234, start_addr: int = 0): | ||
"""Start udbserver. | ||
""" | ||
_udbserver_lib.udbserver(int(uc._uch.value), port, start_addr) |