gplan.so: build from source using Raspbian Stretch Docker
Use balenalib/raspberry-pi-debian:stretch with legacy.raspbian.org repos. Exact match: GCC 6.3, Python 3.5, GLIBC 2.24 — identical to the Pi. First build ~25min (QEMU), subsequent builds ~1sec (cached image). Replaces the broken Bullseye approach that had GLIBC/GLIBCXX mismatches.
This commit is contained in:
@@ -1,58 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Build gplan.so for the Onefinity Pi (armv7l, Python 3.5)
|
||||
# Build gplan.so for the Onefinity Pi (armv7l, Python 3.5, GCC 6.3)
|
||||
#
|
||||
# First run: ~30min (builds the Docker image with pre-compiled cbang/camotics)
|
||||
# After that: ~2sec (just relinks against Python 3.5m)
|
||||
# Uses a Raspbian Stretch Docker image that exactly matches the Pi's
|
||||
# toolchain. No cross-compile, no relink hacks, no GLIBC mismatches.
|
||||
#
|
||||
# Prerequisites:
|
||||
# - Docker with QEMU binfmt support (default on Docker Desktop)
|
||||
# - Python 3.5 headers from the Pi in .pi/pi-python35.tar.gz
|
||||
# Grab once: ssh bbmc@10.1.10.55 'tar czf - /usr/include/python3.5m \
|
||||
# /usr/lib/arm-linux-gnueabihf/libpython3.5m.so*' > .pi/pi-python35.tar.gz
|
||||
# First run: ~30min (builds Docker image with cbang + camotics)
|
||||
# After that: ~1sec (copies pre-built gplan.so from image)
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
IMAGE="onefin-gplan"
|
||||
HEADERS="$SCRIPT_DIR/pi-python35.tar.gz"
|
||||
OUTPUT="$PROJECT_DIR/src/py/camotics/gplan.so"
|
||||
|
||||
# Check for Python 3.5 headers
|
||||
if [[ ! -f "$HEADERS" ]]; then
|
||||
echo "Python 3.5 headers not found at $HEADERS"
|
||||
echo "Fetching from Pi..."
|
||||
ssh bbmc@10.1.10.55 'tar czf - /usr/include/python3.5m \
|
||||
/usr/lib/arm-linux-gnueabihf/libpython3.5m.so*' > "$HEADERS"
|
||||
fi
|
||||
|
||||
# Build image if needed (one-time, ~30min)
|
||||
# Build image if needed (one-time)
|
||||
if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then
|
||||
echo "Building $IMAGE Docker image (one-time, ~30min under QEMU)..."
|
||||
docker build --platform linux/arm/v7 -t "$IMAGE" -f "$SCRIPT_DIR/Dockerfile.gplan" "$SCRIPT_DIR"
|
||||
docker build -t "$IMAGE" -f "$SCRIPT_DIR/Dockerfile.gplan" "$SCRIPT_DIR"
|
||||
fi
|
||||
|
||||
# Relink gplan.so against Python 3.5m (~2sec)
|
||||
echo "Linking gplan.so against Python 3.5m..."
|
||||
docker run --rm --platform linux/arm/v7 \
|
||||
-v "$HEADERS:/tmp/pi-python35.tar.gz:ro" \
|
||||
-v "$PROJECT_DIR:/workspace" \
|
||||
"$IMAGE" bash -c '
|
||||
tar xzf /tmp/pi-python35.tar.gz -C /
|
||||
ln -sf /usr/lib/arm-linux-gnueabihf/libpython3.5m.so.1.0 \
|
||||
/usr/lib/arm-linux-gnueabihf/libpython3.5m.so
|
||||
|
||||
g++ -o /workspace/src/py/camotics/gplan.so \
|
||||
-Wl,--as-needed -Wl,-s -Wl,-x -Wl,--gc-sections -pthread -shared \
|
||||
build/gplan.os -L/opt/cbang/lib \
|
||||
build/libCAMoticsPy.a build/libCAMotics.a build/libDXF.a \
|
||||
build/libSTL.a build/libGCode.a \
|
||||
-lstdc++ -lutil -lm -ldl -lz -lcbang -lcbang-boost \
|
||||
-lssl -lcrypto -llz4 -lexpat -lbz2 -lcrypt -lpthread \
|
||||
-lpython3.5m build/dxflib/libdxflib.a
|
||||
|
||||
file /workspace/src/py/camotics/gplan.so
|
||||
readelf -d /workspace/src/py/camotics/gplan.so | grep python
|
||||
'
|
||||
# Copy gplan.so out of the image
|
||||
echo "Extracting gplan.so..."
|
||||
docker run --rm -v "$PROJECT_DIR:/workspace" "$IMAGE" \
|
||||
bash -c 'cp /opt/camotics/gplan.so /workspace/src/py/camotics/gplan.so && \
|
||||
file /workspace/src/py/camotics/gplan.so && \
|
||||
readelf -d /workspace/src/py/camotics/gplan.so | grep -E "NEEDED|python"'
|
||||
|
||||
echo "✓ Built: $OUTPUT"
|
||||
|
||||
Reference in New Issue
Block a user