Skip to content

P0c: permissive libraries as cvcpkg packages (Qhull, Clipper2, CDT, Shewchuk's predicates), smoke tests, CGAL A/B rows - #1112

Merged
transfix merged 15 commits into
masterfrom
tfx/p0c-permissive-libs-f5c610
Nov 10, 2026
Merged

transfix merged 15 commits into
masterfrom
tfx/p0c-permissive-libs-f5c610

Conversation

@transfix

@transfix transfix commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Phase P0c of docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md ("Permissive libraries"). This PR brings in the permissive libraries that replace CGAL's GPL packages (§1.2), with no mutable process-wide state (§1.3) and with wasm-mt builds (§1.8). It adds each library's smoke test, natively and under node, and the first cgal_ab_test rows (T16). It is non-breaking.

No vendoring (Joe, 2026-11-09: "dont vendor third party libraries in the libcvc repo!! make cvcpkg packages for them"). All four libraries are cvcpkg packages, and §1.2 and §9 item 1 of the roadmap now say so:

What lands

  • Four optional dependencies, each ON by default and OFF when its package is missing (find_package(... CONFIG), as with Jolt):
    • CVC_WITH_QHULL: reentrant libqhull_r, shared (or libqhullstatic_r for a static or wasm cvc);
    • CVC_WITH_CLIPPER2;
    • CVC_WITH_CDT: CDT::CDT, #include <CDT/CDT.h>;
    • CVC_WITH_SHEWCHUK: Shewchuk::predicates, #include <shewchuk/predicates.hpp>.
  • How cvc links them: Qhull and Clipper2 PRIVATE (a static cvc lists them in CVC_PRIVATE_LINK_PACKAGES, which cvcConfig.cmake uses to find them). The header-only two link $<BUILD_INTERFACE:...>, as PEGTL does, so nothing reaches cvc's exports. cvc_permissive_geometry is a build-tree-only interface target carrying all four.
  • libcvc's recipe lists qhull on the native platforms where it is published. The other packages join once published, because install-deps is all-or-nothing.
  • permissive_libs_test: a plain main(), run by ctest natively and, with -DCVC_BUILD_PERMISSIVE_SMOKE=ON, as wasm-mt under node in the new permissive-wasm job. Each section runs when its package is present and prints SKIP otherwise.
    • Qhull d Qbb Qt Qz gives the cube-and-centre's 12 tetrahedra, none flat, and two triangulations on two threads equal the sequential ones tetrahedron for tetrahedron (13,040 and 19,597).
    • Clipper2's Booleans, offsets and Minkowski sum give the expected areas.
    • CDT's constrained square gives 4 triangles.
    • The predicates are exact on grids spaced 2^-53 and on degenerate integer points, also on two threads.
    • The predicates check Qhull's and CDT's empty circumspheres.
  • tools/cgal_ab, the T16 rows (cgal_ab_permissive.cpp; Qhull alone in cgal_ab_qhull.cpp). Results are compared exactly where the sides must agree and by tolerance where they differ by design, and both sides are timed. Details are in tools/cgal_ab/README.md.
    • Shewchuk against CGAL's exact predicates: all 1.2M signs agree.
    • Qhull against Delaunay_triangulation_3, and CDT against Constrained_Delaunay_triangulation_2: identical in general position.
    • Clipper2 against Polygon_set_2, straight-skeleton offsets and minkowski_sum_2: equal areas, exactly on the grid and within rounding otherwise.

Packages

All four are published (Joe's "Yes, merge + publish"; cy-pca/cvcpkg#597 merged as 830c55ed; populate-server runs 42754861238, 42759427894 and 42759468516). They cover wasm, wasm-mt, linux, freebsd, netbsd, openbsd and windows; qhull was already published natively.

  • cgal-ab and permissive-wasm install them from the catalog.
  • libcvc's recipe lists qhull (runtime) and clipper2, cdt and shewchuk-predicates (build-only) on those platforms.
  • macOS has no bundles yet, so there the three options turn OFF and the test skips their sections.

Left for a follow-up:

  • qhull's wasm-mt row in the recipe, when libcvc's wasm publish builds with it (P1);
  • swapping the vendored nanoflann for the nanoflann package, once it has a macOS bundle.

Verified locally (Windows 11, MSVC 19.44, CGAL 6.0.1; emsdk 5.0.7, node 22)

All against locally installed packages built by #597's recipe scripts:

  • native: permissive_libs_test all checks, also under ctest; cgal_ab_test ok: 0 failure(s);
  • wasm-mt: permissive_libs_test under node.

On MSVC objects (llvm-nm on COFF):

  • the predicates header and the patched CDT leave nothing writable but compiler RTTI;
  • the packaged Qhull and Clipper2 keep a few never-written tables MSVC places in .data (Qhull's mergetypes; Clipper2's const sentinels and error-message pointers), candidates for P0a's allowlist.

The P1 spike: Qhull by incremental insertion

qhull_incremental (in cgal_ab_qhull.cpp) works like this:

  1. It seeds a hull with 32 points, d Qbb Qz, led by the point farthest from the origin, because Qz's point at infinity sits at 1.1x the seed's highest lifted point.
  2. It adds the rest in Morton order with qh_setdelaunay and qh_addpoint.
  3. It finishes with qh_triangulate, as Qt does.

"Warm start" locates each point with qh_findbest from the newest facet instead of qh_findbestfacet's walk from the head of the facet list. The results are printed as SPIKE lines (local Windows numbers).

Cloud Matches batch? Warm start / batch Cold, Morton / batch Cold, input order / batch
uniform 2k identical, and identical to CGAL 1.12x 1.24x 1.16x
uniform 20k identical, and identical to CGAL 1.10x 2.44x 2.34x
uniform 100k identical, and identical to CGAL 2.5-3.0x 32x 4.6x
Gaussian clump 20k identical, and identical to CGAL 1.13x 1.18x 4.40x
sphere 2k (nearly cospherical) different valid tiling (3,990 vs 3,992) 1.0-1.2x
10^3 lattice (cospherical) different valid tiling (6,546 vs 5,423 tetrahedra, more flat ones) 1.07x

So incremental insertion reproduces the batch triangulation exactly in general position, at about the batch cost up to 20k points with the warm start. The documented qh_findbestfacet walk is not usable at scale.

Findings for P1 and P3a

  • Qhull is not exact on degenerate input:
    • Qt leaves flat tetrahedra on exactly cospherical sets: 1,049 of 5,423 on a 10^3 lattice.
    • On points rounded onto a sphere it merges everything into one facet and fans it. That's a valid tiling, but not Delaunay by exact predicates.
    • No option tried fixes both: Q0 Qt Qz handles the lattice but fails on the sphere; QJ Qz handles the sphere but leaves flats on the lattice.
    • Qhull's batch build is 3-4x slower than CGAL's.
    • So P1 drops flat tetrahedra and accepts approximate Delaunay on nearly cospherical samples, or uses its own incremental Delaunay on Shewchuk's predicates, which would be exact and a stepper by construction.
  • Clipper2's mitred offsets differ from straight-skeleton offsets past an edge event (7-11% in area on two deep inward star offsets, reported as INFO). They agree before the first event and on convex polygons.
  • Clipper2's symmetric difference returns pieces that touch at points as separate polygons, where CGAL keeps one polygon with holes. The areas agree exactly.

The VolumeRover ports replace CGAL's GPL packages with permissive libraries
(docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md 1.2). The two header-only ones are
vendored here, beside nanoflann, with no mutable process-wide state (1.3):

- CDT 2.0.1 (MPL-2.0; its predicates BSD-3, its nth_element Apache-2.0 WITH
  LLVM-exception), from the tag's tarball. Two files changed: the never-written
  `static double log2_constant` is const, and Lenthe's predicates.h initialises its
  error bounds from constant expressions (same values), so no object file carries
  writable copies or guard variables for them.
- Shewchuk's predicates (public domain), generated into shewchuk/predicates.hpp by
  shewchuk/gen_predicates.py: exactinit()'s globals become constexpr constants (no
  init call, nothing mutable), only the four adaptive predicates are kept, FP
  contraction is off around them, and insphereexact's ~200 KB of arrays move to the
  heap (a wasm thread's stack is 64 KB by default).

Each has its notice in THIRD_PARTY_NOTICES.md, which also gains Qhull and Clipper2.
… T16 rows (P0c)

- CVC_WITH_QHULL / CVC_WITH_CLIPPER2 (ON, OFF when the package is missing): cvc
  links reentrant Qhull (shared libqhull_r, or libqhullstatic_r for a static or wasm
  cvc) and Clipper2 PRIVATE; a static cvc lists both in CVC_PRIVATE_LINK_PACKAGES, so
  cvcConfig.cmake finds them. cvc_permissive_geometry (build tree only) adds
  third_party/ (CDT, Shewchuk) to the include path.
- tests/permissive_libs_test.cpp, a plain main() under ctest and, with
  CVC_BUILD_PERMISSIVE_SMOKE, as wasm-mt under node: Qhull `d Qbb Qt Qz` gives the
  cube-and-centre's 12 tetrahedra and two triangulations on two threads equal the
  sequential ones; Clipper2's union, intersection, difference, offsets and Minkowski
  sum give the expected areas; CDT's constrained square gives 4 triangles; the
  predicates are exact on near-degenerate grids and degenerate integer points; and
  the predicates check Qhull's and CDT's empty circumspheres.
- tools/cgal_ab: the first T16 rows (cgal_ab_permissive.cpp, Qhull alone in
  cgal_ab_qhull.cpp): Shewchuk vs CGAL's exact predicates, Qhull vs
  Delaunay_triangulation_3, CDT vs Constrained_Delaunay_triangulation_2, Clipper2 vs
  Polygon_set_2 Booleans, straight-skeleton offsets and minkowski_sum_2, exact where
  they must agree and by tolerance where they differ by design, both sides timed;
  plus the P1 spike, Qhull by incremental insertion (SPIKE lines).
…libcvc recipe needs qhull (P0c)

- permissive-wasm, "permissive geometry (wasm-mt, node)": builds libcvc for wasm-mt
  with Qhull's static library and Clipper2 from the catalog, then runs
  permissive_libs_test under node.
- cgal-ab installs qhull and clipper2 beside CGAL for the new rows.
- The libcvc recipe gains qhull as a runtime dependency on the native platforms it
  is published for, so the native lanes run permissive_libs_test's Qhull checks.
  Clipper2 and qhull's wasm-mt build join once they are published to cvcpkg.org.
…hey are published

cgal-ab and permissive-wasm stopped at "no bundles found in catalog": qhull's wasm-mt
row and the clipper2 recipe (cy-pca/cvcpkg#578, squash 15d72750) are merged but not
yet published to cvcpkg.org. Both jobs now fetch that commit's recipes (sparse, pinned)
and let cvcpkg build those two from them when the catalog has no bundle
(--fallback-to-source; nothing is published). Once the bundles are on the catalog they
install prebuilt and the fallback never runs.
Joe, 2026-11-09: "dont vendor third party libraries in the libcvc repo!! make cvcpkg
packages for them". The vendored src/cvc/third_party/CDT and shewchuk/ are gone; both are
now cvcpkg packages (cy-pca/cvcpkg#597, open), as Qhull and Clipper2 already were
(cy-pca/cvcpkg#578):

- cdt 2.0.1 (CDT::CDT, #include <CDT/CDT.h>), with the same no-mutable-statics changes as
  a recipe patch;
- shewchuk-predicates (Shewchuk::predicates, #include <shewchuk/predicates.hpp>), the same
  generated header, its generator in cvcpkg's third-party/shewchuk-predicates.

CVC_WITH_CDT and CVC_WITH_SHEWCHUK find them like Qhull and Clipper2 (OFF when missing).
cvc links the two header-only ones $<BUILD_INTERFACE:...>, as it links PEGTL, so they never
reach its exports. permissive_libs_test runs each section whose package is present and
prints SKIP otherwise. cgal_ab_test needs all four.

CI: cgal-ab and permissive-wasm fetch #597's head (which includes #578) and let cvcpkg build
whatever the catalog lacks from those recipes (--fallback-to-source), until the packages
are published. libcvc's recipe gains them once published (install-deps is all-or-nothing).

The roadmap's rule (1.2), 1.8, the P0c row and 9 item 1 now say: cvcpkg packages, never
vendored. #597 also adds nanoflann 2.0.1, so the vendored nanoflann (#1080) can go once
it is published; THIRD_PARTY_NOTICES and the third_party README say so.

Checked locally against the packages as #597's scripts install them (Windows, MSVC 19.44):
all four found, permissive_libs_test 19/19, cgal_ab_test ok, 0 failures.
@transfix transfix changed the title P0c: permissive libraries (Qhull, Clipper2, CDT, Shewchuk's predicates), smoke tests, CGAL A/B rows P0c: permissive libraries as cvcpkg packages (Qhull, Clipper2, CDT, Shewchuk's predicates), smoke tests, CGAL A/B rows Nov 10, 2026
…, not install's fallback

permissive-wasm failed at 02770c2: `cvcpkg install qhull --platform wasm-mt
--fallback-to-source` looks for qhull's build tools (cmake) for wasm-mt and finds none. The
job now installs each geometry package from the catalog and, when there is no bundle, runs
`cvcpkg build --platform wasm-mt --host-platform linux` on the pinned recipe, which takes
the build tools for the host. clipper2's wasm-mt bundle is already published (populate-server
run 42739931761); qhull's wasm rows failed packing there, fixed in cy-pca/cvcpkg#597
(7fe32a12), which both jobs now pin. cgal-ab's native fallback (clipper2 built from source)
passed at 02770c2 and is unchanged.
Joe approved publishing them, and cy-pca/cvcpkg#597 is merged (830c55ed). populate-server
runs 42759427894, 42759468516 and 42754861238 put qhull (wasm-mt), clipper2, cdt,
shewchuk-predicates and nanoflann on cvcpkg.org: wasm, wasm-mt, linux, freebsd, netbsd,
openbsd and windows.

- cgal-ab and permissive-wasm install all four geometry packages from the catalog
  (--no-fallback-to-source), with no recipe fetch and no source build.
- libcvc's recipe gains clipper2, cdt and shewchuk-predicates as build deps on the platforms
  they are published for. The header-only two are BUILD_INTERFACE links, and clipper2 is
  absorbed by a shared cvc, so none is baked into required_deps. The native lanes now run
  every section of permissive_libs_test, except on macOS, which has no bundles yet, so
  there those options turn OFF.
- Not yet: qhull's wasm-mt row in the recipe (libcvc's wasm publish doesn't build with it),
  and nanoflann in place of the vendored copy (it needs a macOS bundle first).
…p0c-permissive-libs-f5c610

# Conflicts:
#	.github/workflows/ci.yml
#	src/cvc/CMakeLists.txt
The writable-data scan failed on package-linux / libcvc-release-grpc for
the merge with master: commits that landed after the scan (#1107) added
objects it did not list. None come from P0c. The new list is the one the
scan itself emitted for that build.

- algo/distance_transform.cpp edt_scratch()::s (tls + guard): the
  per-thread EDT scratch moved here from nav/grid_nav.cpp, so its two
  grid_nav lines go.
- nav/grid_nav.cpp sdf_scratch()::s (tls + guard): a per-thread scratch
  buffer, the same pattern as astar_impl's S already listed.
- ariadne/script_engine.cpp SlicedCall::SlicedCall()::body and
  locked_call()::body (bss + guard): each is a parsed constant AST built
  once and only read afterwards.
…ctory

package-linux / libcvc-release failed on
WasmEngineTest.KeyPointerAndSignalHooksGetTheirEvents: its load read an
empty guest.wat ("expected at least one module field"), at a different
line on each retry. ctest runs every case as its own process, several at
once, and all of them used /tmp/ariadne_wasm_test, where each SetUp
truncates and rewrites guest.wat. One case could load the file just
after another truncated it. #1129's new hook tests made the overlap
likelier.

The directory now carries the process id, the same way
ariadne_media_test and the hdf5 tests already name theirs.
package-macos / libcvc-debug failed ScriptEngineTest.AKeyHookTakesEveryKeyInOrder
(finished 4, not 3) and AFailedEventLetsTheNextOneGo (3 outcomes, not 2),
the same on every retry. ScriptLane::take_queue moved on_done out of its
copy of the hook's options into the QueueDelivery, then passed the options
on to start(). libc++ moves a std::function whose callable sits in its
small buffer by copying it, so the moved-from on_done still held the
test's lambda. The activation then called it once more when its process
ended, on top of the one call per event. libstdc++ and MSVC leave a
moved-from std::function empty, so Linux and Windows passed.

std::exchange leaves the options without it on every standard library.
…p0c-permissive-libs-f5c610

# Conflicts:
#	src/cvc/ariadne/script_engine.cpp
#	tools/singleton_scan/allowlist.txt
@transfix
transfix enabled auto-merge (squash) November 10, 2026 20:09
@transfix
transfix merged commit d30f7bd into master Nov 10, 2026
10 of 33 checks passed
@transfix
transfix deleted the tfx/p0c-permissive-libs-f5c610 branch November 10, 2026 20:22
transfix added a commit that referenced this pull request Nov 10, 2026
)

One conflict, in src/cvc/tests/CMakeLists.txt, where both sides added a
test after physics_replay_test: master's permissive_libs_test and this
branch's threaded runs of the two Ariadne suites. Both are kept; ctest
registers permissive_libs_test, ariadne_runtime_test_threads_auto and
ariadne_host_test_threads_auto.

Neither PR adds a static or thread_local to a scanned target's sources, so
the writable-data allowlist is unchanged. Rebuilt cvc; ocean_shore_test 15
passes, permissive_libs_test runs (its libraries are absent from this
build, so it skips), and ariadne_runtime_test (291) and ariadne_host_test
(48) pass with CVC_EXEC_THREADS=auto.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant