Skip to content

Commit

Permalink
libopcut musl libc allocation bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
bozokopic committed Jun 6, 2024
1 parent 8f74b41 commit be04093
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 48 deletions.
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
FROM python:3.10-slim-bookworm as opcut-base
WORKDIR /opcut
RUN apt update -y && \
apt install -y pkg-config gcc libcairo2-dev
apt install -y pkg-config gcc libcairo2-dev && \
python3 -m venv /opt/opcut

FROM opcut-base as opcut-build
WORKDIR /opcut
RUN apt install -y nodejs yarnpkg git && \
ln -sT /usr/bin/yarnpkg /usr/bin/yarn
RUN apt install -y nodejs npm git
COPY . .
RUN pip install -r requirements.pip.txt && \
doit clean_all && \
doit
RUN /opt/opcut/bin/pip install -r requirements.pip.txt && \
/opt/opcut/bin/doit clean_all && \
/opt/opcut/bin/doit

FROM opcut-base as opcut-run
WORKDIR /opcut
COPY --from=opcut-build /opcut/build/py/*.whl .
RUN pip install *.whl && \
rm *.whl
RUN /opt/opcut/bin/pip install *.whl && \
rm -r /opcut
EXPOSE 8080
CMD ["/usr/local/bin/opcut", "server"]
CMD ["/opt/opcut/bin/opcut", "server"]
22 changes: 22 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.12-alpine3.20 as opcut-base
WORKDIR /opcut
RUN apk update && \
apk add cairo && \
python3 -m venv /opt/opcut

FROM opcut-base as opcut-build
WORKDIR /opcut
RUN apk add build-base pkgconf cargo cairo-dev nodejs npm
COPY . .
RUN /opt/opcut/bin/pip install -r requirements.pip.txt && \
/opt/opcut/bin/doit clean_all && \
/opt/opcut/bin/doit

FROM opcut-base as opcut-run
WORKDIR /opcut
COPY --from=opcut-build /root/.cache/pip /root/.cache/pip
COPY --from=opcut-build /opcut/build/py/*.whl .
RUN /opt/opcut/bin/pip install *.whl && \
rm -r /opcut
EXPOSE 8080
CMD ["/opt/opcut/bin/opcut", "server"]
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Development requirements

* C99 compiler (gcc, clang, ...)
* nodejs >=7
* npm


Build
Expand Down
2 changes: 1 addition & 1 deletion playground/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/result.json
/output.pdf
/output.svg
/build
/dist
27 changes: 0 additions & 27 deletions playground/build.sh

This file was deleted.

10 changes: 10 additions & 0 deletions playground/check-glibc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

PLAYGROUND_PATH=$(dirname "$(realpath "$0")")
. $PLAYGROUND_PATH/env.sh

for i in $(find $ROOT_PATH/src_py -name '*.so'); do
objdump -T $i | grep GLIBC
done
61 changes: 61 additions & 0 deletions playground/dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

set -e

PLAYGROUND_PATH=$(dirname "$(realpath "$0")")
. $PLAYGROUND_PATH/env.sh

cd $ROOT_PATH
rm -rf $DIST_PATH
mkdir -p $DIST_PATH


if command -v x86_64-w64-mingw32-gcc >/dev/null; then
export TARGET_PLATFORM=windows_amd64

$PYTHON -m doit clean_all
$PYTHON -m doit dist

cp $ROOT_PATH/build/py/*.whl $DIST_PATH
cp $ROOT_PATH/build/dist/*.zip $DIST_PATH
fi


PLATFORMS="linux/amd64
linux/arm/v7
linux/arm64/v8"

for PLATFORM in $PLATFORMS; do
for DOCKERFILE in $PLAYGROUND_PATH/dockerfiles/*; do
IMAGE=$PLATFORM/$(basename $DOCKERFILE)
IMAGE_ID=$(podman images -q $IMAGE)

$PYTHON -m doit clean_all

podman build --platform $PLATFORM \
-f $DOCKERFILE \
-t $IMAGE \
.
if [ -n "$IMAGE_ID" -a "$IMAGE_ID" != "$(podman images -q $IMAGE)" ]; then
podman rmi $IMAGE_ID
fi
podman run --rm \
--platform $PLATFORM \
-v $DIST_PATH:/opcut/dist \
-v ~/.cache/pip:/root/.cache/pip \
-i $IMAGE /bin/sh - << EOF
set -e
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip hat-json
./playground/requirements.sh > requirements.pip.txt
pip install --upgrade -r requirements.pip.txt
doit clean_all
doit
cp build/py/*.whl dist
EOF

done
done

$PYTHON -m doit clean_all
9 changes: 9 additions & 0 deletions playground/dockerfiles/build-opcut:alpine3.20-cpy3.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-alpine3.20 as base
RUN apk update && \
apk add build-base pkgconf cargo cairo-dev nodejs npm git jq

FROM base
WORKDIR /opcut
VOLUME /opcut/dist
VOLUME /root/.cache/pip
COPY . .
9 changes: 9 additions & 0 deletions playground/dockerfiles/build-opcut:debian11-cpy3.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-bullseye as base
RUN apt update -qy && \
apt install -qy pkg-config gcc libcairo2-dev nodejs npm git jq

FROM base
WORKDIR /opcut
VOLUME /opcut/dist
VOLUME /root/.cache/pip
COPY . .
2 changes: 2 additions & 0 deletions playground/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

PYTHON=${PYTHON:-python3}
ROOT_PATH=$PLAYGROUND_PATH/..
DIST_PATH=$PLAYGROUND_PATH/dist

VERSION=$($PYTHON -m hat.json.convert $ROOT_PATH/pyproject.toml | \
jq -r .project.version)

Expand Down
13 changes: 12 additions & 1 deletion playground/podman-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ PLAYGROUND_PATH=$(dirname "$(realpath "$0")")
. $PLAYGROUND_PATH/env.sh

cd $ROOT_PATH
exec podman build -t bozokopic/opcut:$VERSION .

PLATFORM=linux/amd64

podman build --platform $PLATFORM \
-f Dockerfile \
-t bozokopic/opcut:$VERSION \
.

podman build --platform $PLATFORM \
-f Dockerfile.alpine \
-t bozokopic/opcut:alpine-$VERSION \
.
9 changes: 9 additions & 0 deletions playground/requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

PLAYGROUND_PATH=$(dirname "$(realpath "$0")")
. $PLAYGROUND_PATH/env.sh

hat-json-convert $ROOT_PATH/pyproject.toml | \
jq -r '.project | .dependencies[], .["optional-dependencies"][][]'
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[project]
name = "opcut"
version = "0.4.14"
version = "0.4.15"
description = "Cutting stock problem optimizer"
readme = "README.rst"
requires-python = ">=3.10"
license = {text = "GPLv3"}
dependencies = [
"aiohttp ~=3.9.3",
"hat-aio ~=0.7.9",
"aiohttp ~=3.9.5",
"hat-aio ~=0.7.10",
"hat-json ~=0.5.27",
"pycairo ~=1.26.0",
]
Expand All @@ -20,10 +20,10 @@ Homepage = "https://opcut.kopic.xyz"
Repository = "https://github.com/bozokopic/opcut.git"

[project.optional-dependencies]
dev = ["hat-doit ~=0.15.13"]
dev = ["hat-doit ~=0.15.15"]

[build-system]
requires = ["hat-doit ~=0.15.13"]
requires = ["hat-doit ~=0.15.15"]
build-backend = "hat.doit.pep517"

[tool.hat-doit]
Expand Down
6 changes: 3 additions & 3 deletions requirements.pip.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp ~=3.9.3
hat-aio ~=0.7.9
hat-doit ~=0.15.13
aiohttp ~=3.9.5
hat-aio ~=0.7.10
hat-doit ~=0.15.15
hat-json ~=0.5.27
pycairo ~=1.26.0
4 changes: 2 additions & 2 deletions src_py/opcut/libopcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def calculate(method: common.Method,

native_method = _encode_method(method)

a = _lib.opcut_allocator_create(ctypes.pythonapi.PyMem_Malloc,
ctypes.pythonapi.PyMem_Free)
a = _lib.opcut_allocator_create(ctypes.pythonapi.PyMem_RawMalloc,
ctypes.pythonapi.PyMem_RawFree)
if a is None:
raise Exception("allocation error")

Expand Down

0 comments on commit be04093

Please sign in to comment.