Files
ocp/occt/Dockerfile
stroblme 6139852768 Phase 10A/10B Inc 0: build system, handle model, first module surface
Builds n3xd-ocp end to end and publishes 7.9.3.1.dev1 to the Gitea registry,
where it installs anonymously and passes its suite.

- occt/Dockerfile: OCCT 7.9.3 compiled once into a manylinux_2_28 builder
  image (base digest + tarball sha256 pinned), Draw/VTK/Tk/Xlib/OpenGL off,
  FreeType on, -O2 without fast-math or march=native. A final layer asserts
  TKService/TKV3d exist with no libGL/libX11 DT_NEEDED, which is what lets the
  app image drop libgl1/libx11-6. Mounted into, never built FROM.
- scikit-build-core + nanobind STABLE_ABI -> one cp312-abi3 extension that
  registers every OCP.* submodule via PyImport_AddModule, so `import
  OCP.TopoDS` needs no shim and cls.__module__ is right. Version <occt>.N is
  asserted against the OCCT found, keeping occt_version() truthful.
- occt_handle.h: type caster for opencascade::handle<T> over OCCT's intrusive
  refcount. Wrappers are non-owning instances holding exactly one handle in
  their keep-alive list, reusing an existing wrapper so identity survives a
  round trip. Transient constructors go through ocp_new (never nb::init<>,
  which would let OCCT delete nanobind's storage); the caster refuses a
  refcount-0 object rather than corrupt the heap. Verified under ASAN with no
  memory-safety errors, plus an RSS bound over 50k create/destroy cycles.
- Sub-shapes are returned by value everywhere, making the TShape lifetime class
  that segfaulted a process-global face memo unrepresentable.
- Standard_Failure derives RuntimeError, with ~20 concrete types dispatched on
  the dynamic OCCT type (cad_pool marshals failures home by type name).
- Inc 0 surface: gp subset, TopAbs, TopoDS (+ downcasts), TopExp, TopLoc,
  TopTools, BRep, BinTools, Poly, Standard. 34 of the app's 139 symbols.
- n3xd_ocp: additive APIs kept out of the OCP namespace so parity testing stays
  meaningful. bintools (shape <-> bytes, GIL-free, byte-identical) and _debug.

Two findings worth the record, both verified against the stock wheel rather
than assumed: upstream binds __hash__ but leaves __eq__ at identity, which is
exactly what geom_memo.py's hash-bucket + IsSame scan is built around, so we
match it instead of "fixing" it; and BinTools can release the GIL after all, by
slurping the file-like object instead of bridging a streambuf that would call
back into Python.

Gate: BREP round-trips are byte-identical to cadquery-ocp-novtk across six
fixtures (the generator asserts stock idempotency first). That matters beyond
IPC — derive.py content-addresses BREP payloads by sha256 and stores the ref.
2026-08-10 16:10:28 +02:00

80 lines
3.7 KiB
Docker

# OCCT builder image — a compiler appliance, not a base for the wheel.
#
# Wheel builds `docker run` this with the repo mounted (see ../Makefile); they
# never `FROM` it, so iterating on the binding never re-layers the kernel.
# Rebuild only when this file changes, and bump the image tag's -N when you do.
#
# The production host (4 cores) can never compile OCCT, which is the whole
# reason this exists: the kernel is compiled once here and shipped inside the
# wheel by `auditwheel repair`.
FROM quay.io/pypa/manylinux_2_28_x86_64@sha256:f854c50adf7b7a325bc4794316f3758d387a41d61f9e2ebca0f26c7dc8f761d4
# FreeType + fontconfig are the only optional OCCT dependencies we keep — the
# text-emboss feature builds glyph outlines through Font_BRepFont (TKService).
# ccache/ninja serve the wheel build that runs in this image later.
RUN dnf install -y freetype-devel fontconfig-devel ninja-build ccache valgrind \
&& dnf clean all
ARG OCCT_TAG=V7_9_3
ARG OCCT_SHA256=5ecf094ec6b12d5413dfb851d8c3590c354058aee556e32e408bdfbf8c357d57
RUN curl -fsSL -o /tmp/occt.tar.gz \
"https://github.com/Open-Cascade-SAS/OCCT/archive/refs/tags/${OCCT_TAG}.tar.gz" \
&& echo "${OCCT_SHA256} /tmp/occt.tar.gz" | sha256sum -c - \
&& mkdir -p /src \
&& tar -xzf /tmp/occt.tar.gz -C /src --strip-components=1 \
&& rm /tmp/occt.tar.gz
# Conservative FP flags are deliberate: OCCT's version is a determinism input
# for assay's committed goldens, so a different optimizer could shift last-ulp
# results against the upstream wheel we are proving parity with. -O2 (not the
# Release default -O3), no -ffast-math, no -march=native.
RUN cmake -G Ninja -S /src -B /build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG" \
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG" \
-DBUILD_LIBRARY_TYPE=Shared \
-DINSTALL_DIR=/opt/occt \
-DBUILD_MODULE_FoundationClasses=ON \
-DBUILD_MODULE_ModelingData=ON \
-DBUILD_MODULE_ModelingAlgorithms=ON \
-DBUILD_MODULE_Visualization=ON \
-DBUILD_MODULE_DataExchange=ON \
-DBUILD_MODULE_ApplicationFramework=ON \
-DBUILD_MODULE_Draw=OFF \
-DBUILD_MODULE_DETools=OFF \
-DUSE_FREETYPE=ON \
-DUSE_VTK=OFF -DUSE_TK=OFF -DUSE_TCL=OFF \
-DUSE_XLIB=OFF -DUSE_OPENGL=OFF -DUSE_GLES2=OFF \
-DUSE_TBB=OFF -DUSE_RAPIDJSON=OFF -DUSE_DRACO=OFF \
-DUSE_FREEIMAGE=OFF -DUSE_FFMPEG=OFF -DUSE_OPENVR=OFF \
&& ninja -C /build -j"$(nproc)" \
&& ninja -C /build install \
&& find /opt/occt/lib -name '*.so*' -type f -exec strip --strip-debug {} + \
&& rm -rf /build /src
# Assert the headless build actually produced what the app needs. Text emboss
# imports OCP.StdPrs.StdPrs_BRepFont, which is a deprecated typedef of
# Font_BRepFont living in TKService/TKV3d — those toolkits must exist even with
# OpenGL and Xlib off, and must not have picked up a libGL/libX11 DT_NEEDED
# (dropping those two runtime packages from the app image is a phase goal).
RUN test -f /opt/occt/lib/libTKService.so \
&& test -f /opt/occt/lib/libTKV3d.so \
&& test -f /opt/occt/lib/libTKDESTEP.so \
&& ! ldd /opt/occt/lib/libTKService.so | grep -qE 'libGL\.|libX11\.' \
&& ! ldd /opt/occt/lib/libTKV3d.so | grep -qE 'libGL\.|libX11\.' \
&& ldd /opt/occt/lib/libTKService.so | grep -q libfreetype
ENV OCCT_ROOT=/opt/occt \
CMAKE_PREFIX_PATH=/opt/occt \
LD_LIBRARY_PATH=/opt/occt/lib \
PATH=/opt/python/cp312-cp312/bin:$PATH
WORKDIR /io
# Sanitizer runtime for `make test-asan`, the handle-model memory-safety check.
# Deliberately the last layer: adding it never invalidates the kernel build
# above, so the ~40 minute compile is not repeated for a test dependency.
RUN dnf install -y gcc-toolset-14-libasan-devel && dnf clean all