Skip to content

Commit

Permalink
Build binary wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamN committed Oct 21, 2022
1 parent 70bafe3 commit e20e896
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 14 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: package
on: [push, pull_request]
jobs:
linux_wheels:
strategy:
matrix:
arch: [x86, x86_64, armhf, arm64, mips, mipsel, mips64, mips64el]
runs-on: ubuntu-latest
container: ghcr.io/frida/x-tools-linux-${{ matrix.arch }}:latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- run: cd agents/tracer && npm install && npm run build
- run: pip install tree_sitter
- run: |
case ${{ matrix.arch }} in
x86)
py_arch=i686
;;
armhf)
py_arch=armv7l
;;
arm64)
py_arch=aarch64
;;
*)
py_arch=${{ matrix.arch }}
;;
esac
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
export _PYTHON_HOST_PLATFORM=linux-$py_arch
echo "plat_name = $py_platform" >> setup.cfg
pip wheel -w ./dist --no-deps .
- uses: actions/upload-artifact@v3
with:
name: frida_tools_linux
path: dist

macos_wheels:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- run: cd agents/tracer && npm install && npm run build
- run: python3 -m pip install wheel
- run: python3 -m pip install tree_sitter
- run: python3 setup.py bdist_wheel --plat-name=macosx_10_9_x86_64
- run: python3 setup.py bdist_wheel --plat-name=macosx_11_0_x86_64
- uses: actions/upload-artifact@v3
with:
name: frida_tools_macos
path: dist

windows_wheels:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- run: cd agents/tracer && npm install && npm run build
- run: python3 -m pip install wheel
- run: python3 -m pip install tree_sitter
- run: python3 setup.py bdist_wheel --plat-name=win_amd64
- run: python3 setup.py bdist_wheel --plat-name=win32
- uses: actions/upload-artifact@v3
with:
name: frida_tools_windows
path: dist
10 changes: 0 additions & 10 deletions build-aux/build-treesitter.py

This file was deleted.

18 changes: 18 additions & 0 deletions build_aux/build_treesitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

import os

from tree_sitter import Language


def build() -> None:
Language.build_library(
os.path.join("frida_tools", "treesitter.so"),
[
os.path.join("vendor", "tree-sitter-javascript"),
],
)


if __name__ == "__main__":
build()
2 changes: 1 addition & 1 deletion build-aux/meson.build → build_aux/meson.build
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python = find_program('python3', 'python')
run_command(python, 'build-treesitter.py')
run_command(python, 'build_treesitter.py')
4 changes: 2 additions & 2 deletions frida_tools/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
T = TypeVar("T")

try:
JS_LANGUAGE = Language(os.path.join(os.path.dirname(__file__), "treesitter.so"), "javascript")
treesitter_lib_name = "treesitter.lib" if os.name == "nt" else "treesitter.so"
JS_LANGUAGE = Language(os.path.join(os.path.dirname(__file__), treesitter_lib_name), "javascript")
ERROR_QUERY = JS_LANGUAGE.query("(_ (ERROR) @error)")
except Exception:
JS_LANGUAGE = None
Expand Down Expand Up @@ -364,7 +365,6 @@ def _input_complete(self) -> Filter:
def inner() -> bool:
assert self._cli is not None
if self._parser is None or ERROR_QUERY is None:
print("None", file=sys.stderr)
return False

tree = self._parser.parse(self._cli.default_buffer.document.text.encode())
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ subdir('agents')
subdir('frida_tools')
subdir('scripts')
subdir('completions')
subdir('build-aux')
subdir('build_aux')
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
py_limited_api = cp37
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

from setuptools import setup

from build_aux import build_treesitter

pkg_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "frida_tools"))

agents = glob.glob(os.path.join(pkg_dir, "*_agent.*"))
assert len(agents) > 0, "Agents not compiled; run “npm install && npm run build” in agents/*/"
build_treesitter.build()
package_data = agents + ["treesitter.so"]

setup(
Expand All @@ -25,6 +28,7 @@
"frida >= 16.0.0, < 17.0.0",
"prompt-toolkit >= 2.0.0, < 4.0.0",
"pygments >= 2.0.2, < 3.0.0",
"tree_sitter==0.20.1",
],
license="wxWindows Library Licence, Version 3.1",
zip_safe=True,
Expand Down

0 comments on commit e20e896

Please sign in to comment.