Skip to content

Commit

Permalink
refactor: Adapt pytox to the new tox_system stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Sep 11, 2023
1 parent 1c574ed commit 5c341fc
Show file tree
Hide file tree
Showing 26 changed files with 546 additions and 125 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
pkg-config
python3-dev
python3-setuptools
- run: git clone --depth=1 https://github.com/TokTok/c-toxcore
- run: git clone --recursive --depth=1 https://github.com/TokTok/c-toxcore
- run: cd c-toxcore;
. .github/scripts/flags-gcc.sh;
add_flag -fsanitize=address;
Expand All @@ -44,10 +44,10 @@ jobs:
-DTRACE=ON
-DMUST_BUILD_TOXAV=ON
- run: cd c-toxcore/_build && ninja install -j$(nproc)
# - run:
# export CFLAGS="-I$PWD/c-toxcore/_install/include -fsanitize=address";
# export LDFLAGS="-L$PWD/c-toxcore/_install/lib -Wl,-rpath,$PWD/c-toxcore/_install/lib";
# python3 setup.py build_ext --inplace
- run:
export CFLAGS="-I$PWD/c-toxcore/_install/include -fsanitize=address";
export LDFLAGS="-L$PWD/c-toxcore/_install/lib -Wl,-rpath,$PWD/c-toxcore/_install/lib";
python3 setup.py build_ext --inplace
# - run: ASAN_OPTIONS=detect_leaks=0
# LD_PRELOAD=libasan.so.5
# PYTHONPATH=.
Expand Down
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.mypy_cache
42 changes: 39 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,59 @@ package(features = ["layering_check"])

project()

SUBSYSTEMS = [
"log",
"memory",
"network",
"options",
"random",
"system",
"time",
]

[genrule(
name = "pytox/" + sys,
srcs = [
"pytox/src/%s.pxd" % sys,
"pytox/src/%s.pyx" % sys,
"//c-toxcore:public",
],
outs = [
"pytox/%s.pxd" % sys,
"pytox/%s.pyx" % sys,
],
cmd = " ".join([
"$(location //py_toxcore_c/tools:gen_api)",
"$(location pytox/src/%s.pyx)" % sys,
"$(GENDIR)/c-toxcore",
"> $(location pytox/%s.pyx);" % sys,
"$(location //py_toxcore_c/tools:gen_api)",
"$(location pytox/src/%s.pxd)" % sys,
"$(GENDIR)/c-toxcore",
"> $(location pytox/%s.pxd)" % sys,
]),
tools = ["//py_toxcore_c/tools:gen_api"],
) for sys in SUBSYSTEMS]

genrule(
name = "pytox/core",
srcs = [
"pytox/src/core.pyx",
"//c-toxcore:tox/tox.h",
"//c-toxcore:tox/toxcore/tox.h",
],
outs = ["pytox/core.pyx"],
cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(location //c-toxcore:tox/tox.h) > $@",
cmd = "$(location //py_toxcore_c/tools:gen_api) $(location pytox/src/core.pyx) $(GENDIR)/c-toxcore > $@",
tools = ["//py_toxcore_c/tools:gen_api"],
)

pyx_library(
name = "pytox",
srcs = [
"pytox.pxd",
"pytox/av.pyx",
"pytox/core.pyx",
],
"pytox/error.pyx",
] + ["pytox/%s.pxd" % sys for sys in SUBSYSTEMS] + ["pytox/%s.pyx" % sys for sys in SUBSYSTEMS],
cdeps = ["//c-toxcore"],
cython_directives = {"language_level": "3"},
visibility = ["//visibility:public"],
Expand Down
39 changes: 31 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM ubuntu:20.04
FROM ubuntu:22.04
LABEL maintainer="iphydf@gmail.com"

RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
ca-certificates \
cmake \
cython \
gcc \
g++ \
git \
Expand All @@ -19,23 +18,47 @@ RUN apt-get update \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install mypy
&& pip3 install cython mypy

WORKDIR /build
RUN git clone --depth=1 https://github.com/TokTok/c-toxcore /build/c-toxcore \
RUN git clone --recursive --depth=1 --branch=system https://github.com/iphydf/c-toxcore /build/c-toxcore \
&& cmake -GNinja -B/build/c-toxcore/_build -H/build/c-toxcore \
-DBOOTSTRAP_DAEMON=OFF \
-DENABLE_STATIC=OFF \
-DMUST_BUILD_TOXAV=ON \
&& cmake --build /build/c-toxcore/_build --target install --parallel "$(nproc)" \
&& ldconfig
&& ldconfig && echo 2

COPY pytox /build/pytox
# Tools first, they change less.
COPY tools /build/tools
COPY pytox.pxd /build/
COPY pytox /build/pytox

RUN mypy --strict tools/gen_api.py \
&& tools/gen_api.py pytox/src/core.pyx /usr/local/include/tox/tox.h > pytox/core.pyx \
&& cython pytox/av.pyx pytox/core.pyx
&& tools/gen_api.py pytox/src/core.pyx /usr/local/include > pytox/core.pyx \
&& tools/gen_api.py pytox/src/log.pxd /usr/local/include > pytox/log.pxd \
&& tools/gen_api.py pytox/src/log.pyx /usr/local/include > pytox/log.pyx \
&& tools/gen_api.py pytox/src/memory.pxd /usr/local/include > pytox/memory.pxd \
&& tools/gen_api.py pytox/src/memory.pyx /usr/local/include > pytox/memory.pyx \
&& tools/gen_api.py pytox/src/network.pxd /usr/local/include > pytox/network.pxd \
&& tools/gen_api.py pytox/src/network.pyx /usr/local/include > pytox/network.pyx \
&& tools/gen_api.py pytox/src/options.pxd /usr/local/include > pytox/options.pxd \
&& tools/gen_api.py pytox/src/options.pyx /usr/local/include > pytox/options.pyx \
&& tools/gen_api.py pytox/src/random.pxd /usr/local/include > pytox/random.pxd \
&& tools/gen_api.py pytox/src/random.pyx /usr/local/include > pytox/random.pyx \
&& tools/gen_api.py pytox/src/system.pxd /usr/local/include > pytox/system.pxd \
&& tools/gen_api.py pytox/src/system.pyx /usr/local/include > pytox/system.pyx \
&& tools/gen_api.py pytox/src/time.pxd /usr/local/include > pytox/time.pxd \
&& tools/gen_api.py pytox/src/time.pyx /usr/local/include > pytox/time.pyx \
&& cython -I $PWD -X "language_level=3" --line-directives pytox/av.pyx pytox/core.pyx \
pytox/error.pyx \
pytox/log.pyx \
pytox/memory.pyx \
pytox/network.pyx \
pytox/options.pyx \
pytox/random.pyx \
pytox/system.pyx \
pytox/time.pyx

COPY setup.py /build/
RUN python3 setup.py install \
Expand Down
1 change: 1 addition & 0 deletions pytox.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 14 additions & 0 deletions pytox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/core.pxd
/core.pyx
/log.pxd
/log.pyx
/memory.pxd
/memory.pyx
/network.pxd
/network.pyx
/random.pxd
/random.pyx
/system.pxd
/system.pyx
/time.pxd
/time.pyx
15 changes: 15 additions & 0 deletions pytox/error.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class UseAfterFreeException(Exception):
def __init__(self):
super().__init__(
"object used after it was killed/freed (or it was never initialised)")

class ToxException(Exception):
pass

class ApiException(ToxException):
def __init__(self, err):
super().__init__(err)
self.error = err

class LengthException(ToxException):
pass
Loading

0 comments on commit 5c341fc

Please sign in to comment.