Skip to content

Commit

Permalink
✨ initial Chimera support (and upgrade to Hyperscan v5.4.0)
Browse files Browse the repository at this point in the history
Closes #32
  • Loading branch information
darvid committed Apr 11, 2022
1 parent 1d95aea commit 0527aac
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 336 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.github
.pytest_cache
.venv
.vscode
build
dist
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PCRE_PATH=../hyperscan/pcre-8.44/.libs
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- cp37-cp37m
- cp38-cp38
- cp39-cp39
- cp310-cp310
env:
PYTHON_VERSION: ${{ matrix.python-version }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
setup.py
.pytest_cache/
.vscode/
*.whl
examples/hsbench-samples

.vscode/
poetry.lock
setup.py

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
21 changes: 0 additions & 21 deletions .semaphore/build_wheels.sh

This file was deleted.

29 changes: 0 additions & 29 deletions .semaphore/ghr-deploy.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .semaphore/pypi-deploy.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .semaphore/run_tests.sh

This file was deleted.

53 changes: 0 additions & 53 deletions .semaphore/semaphore.yml

This file was deleted.

7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM darvid/manylinux-hyperscan:5.4.0
ENV PCRE_PATH=/opt/pcre/.libs
RUN python3.9 -m pip install poetry
RUN mkdir /src
WORKDIR /src
COPY . .
RUN python3.9 -m poetry install -vvv
54 changes: 33 additions & 21 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
import glob
import os
import subprocess
import sys
from distutils.command.build_ext import build_ext
from distutils.core import Extension
from distutils.errors import (
CCompilerError,
DistutilsExecError,
DistutilsPlatformError,
)

pcre_path = os.getenv("PCRE_PATH", "/opt/pcre")


# http://code.activestate.com/recipes/502261-python-distutils-pkg-config/
def pkgconfig(libs, optional=''):
def pkgconfig(libs, optional=""):
flag_map = {
'include_dirs': (['--cflags-only-I'], 2),
'library_dirs': (['--libs-only-L'], 2),
'libraries': (['--libs-only-l'], 2),
'extra_compile_args': (['--cflags-only-other'], 0),
'extra_link_args': (['--libs-only-other'], 0),
"include_dirs": (["--cflags-only-I"], 2, []),
"library_dirs": (["--libs-only-L"], 2, []),
"libraries": (["--libs-only-l"], 2, []),
"extra_compile_args": (["--cflags-only-other"], 0, ["-O0"]),
"extra_link_args": (
["--libs-only-other"],
0,
[
# f"-Wl,-rpath={pcre_path}",
# "-l:libpcre.so",
],
),
}
ext_kwargs = {'extra_compile_args': ['-std=c99']}
ext_kwargs = {"extra_compile_args": ["-fPIC"]}
for lib in libs:
for distutils_kwarg, (pkg_options, trim_offset) in flag_map.items():
for distutils_kwarg, (
pkg_options,
trim_offset,
default_value,
) in flag_map.items():
try:
options = (
subprocess.check_output(
['pkg-config', optional, *pkg_options, lib]
["pkg-config", optional, *pkg_options, lib]
)
.decode()
.split()
)
except subprocess.CalledProcessError:
continue
ext_kwargs.setdefault(distutils_kwarg, []).extend(
ext_kwargs.setdefault(distutils_kwarg, default_value).extend(
[opt[trim_offset:] for opt in options]
)
return ext_kwargs
Expand All @@ -41,13 +49,17 @@ def pkgconfig(libs, optional=''):
def build(setup_kwargs):
setup_kwargs.update(
{
'ext_modules': [
"ext_modules": [
Extension(
'hyperscan._hyperscan',
['src/hyperscan/hyperscanmodule.c'],
**pkgconfig(['libhs']),
"hyperscan._hyperscan",
["src/hyperscan/hyperscanmodule.c"],
extra_objects=[
os.path.join(pcre_path, "libpcre.a"),
*glob.glob(os.path.join(pcre_path, '*.o')),
],
**pkgconfig(["libhs", "libch"]),
)
],
'cmdclass': {'build_ext': build_ext},
"cmdclass": {"build_ext": build_ext},
}
)
25 changes: 23 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0527aac

Please sign in to comment.