From dacf269e6e13ce5c1a5bb55721ae5e453efe64e8 Mon Sep 17 00:00:00 2001 From: Yotam Nachum Date: Fri, 21 Oct 2022 19:53:37 +0300 Subject: [PATCH] ci: Build binary wheels in CI --- .github/workflows/package.yml | 117 ++++++++++++++++++++++++++++++++++ frida_tools/repl.py | 3 +- setup.cfg | 2 + 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/package.yml create mode 100644 setup.cfg diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml new file mode 100644 index 00000000..15b6165a --- /dev/null +++ b/.github/workflows/package.yml @@ -0,0 +1,117 @@ +name: package +on: [push, pull_request] + +jobs: + windows-wheels: + strategy: + matrix: + arch: [x86, x64] + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + architecture: ${{ matrix.arch }} + - run: make + - run: python3 -m pip install wheel + - run: python3 -m pip install tree_sitter + - run: python3 setup.py bdist_wheel + - uses: actions/upload-artifact@v3 + with: + name: frida-tools-windows + path: dist/frida_tools-*.whl + - name: Publish package + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + + macos-wheels: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - run: make + - run: python3 -m pip install wheel + - run: python3 -m pip install tree_sitter + - run: python3 setup.py bdist_wheel + - uses: actions/upload-artifact@v3 + with: + name: frida-tools-macos + path: dist/frida_tools-*.whl + - name: Publish package + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + + linux-wheels: + strategy: + matrix: + arch: [x86, x86_64, armhf, arm64, mips] + runs-on: ubuntu-latest + container: ghcr.io/frida/x-tools-linux-${{ matrix.arch }}:latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - run: make + - run: | + case ${{ matrix.arch }} in + x86) + py_arch=i686 + ;; + armhf) + py_arch=armv7l + ;; + arm64) + py_arch=aarch64 + ;; + *) + py_arch=${{ matrix.arch }} + ;; + esac + export _PYTHON_HOST_PLATFORM=linux-$py_arch + export LIBDIR="/opt/x-tools/$XTOOLS_HOST/$XTOOLS_HOST/sysroot/usr/lib" + # export LDFLAGS="-L/opt/x-tools/$XTOOLS_HOST/$XTOOLS_HOST/sysroot/usr/lib" + export CPPFLAGS="-I/opt/x-tools/$XTOOLS_HOST/$XTOOLS_HOST/sysroot/usr/include/python3.10" + python3 -m pip install --verbose tree_sitter + case ${{ matrix.arch }} in + x86*) + py_platform=manylinux_2_5_${py_arch}.manylinux1_${py_arch} + ;; + arm*|ppc*|s390x) + py_platform=manylinux_2_17_${py_arch}.manylinux2014_${py_arch} + ;; + *) + py_platform=manylinux_2_5_${py_arch} + ;; + esac + bdist_wheel_py=/usr/lib/python3/dist-packages/wheel/bdist_wheel.py + sed "s/plat_name = plat_name\\.lower()\\.replace('-', '_')\\.replace('.', '_')/plat_name = plat_name.lower().replace('-', '_')/" \ + $bdist_wheel_py > $bdist_wheel_py.patched + if cmp -s $bdist_wheel_py $bdist_wheel_py.patched; then + rm -f $bdist_wheel_py.patched + echo 'Unable to patch bdist_wheel.py' > /dev/stderr + exit 1 + else + mv $bdist_wheel_py.patched $bdist_wheel_py + fi + echo "plat_name = $py_platform" >> setup.cfg + pip wheel --verbose -w ./dist --no-deps . + - uses: actions/upload-artifact@v3 + with: + name: frida-tools-linux-${{ matrix.arch }} + path: dist/frida_tools-*.whl + - name: Publish package + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/frida_tools/repl.py b/frida_tools/repl.py index 7e7003c2..d8140801 100644 --- a/frida_tools/repl.py +++ b/frida_tools/repl.py @@ -3,6 +3,7 @@ import hashlib import json import os +import pathlib import platform import re import shlex @@ -37,7 +38,7 @@ T = TypeVar("T") try: - JS_LANGUAGE = Language(os.path.join(os.path.dirname(__file__), "treesitter.so"), "javascript") + JS_LANGUAGE = Language(str(pathlib.Path(__file__).parent / "treesitter.so"), "javascript") ERROR_QUERY = JS_LANGUAGE.query("(_ (ERROR) @error)") except Exception: JS_LANGUAGE = None diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..08a438ab --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +py_limited_api = cp37