Skip to content

Ap203min modern - #488

Open
ramcdona wants to merge 12 commits into
stepcode:developfrom
ramcdona:ap203min-modern
Open

ramcdona wants to merge 12 commits into
stepcode:developfrom
ramcdona:ap203min-modern

Conversation

@ramcdona

Copy link
Copy Markdown

This version resolves the issues that OpenVSP has had with STEPCode. We were far out of date, so mostly this is fast-forwarding to the latest release with a few other small things (mostly picked up from other in-progress work).

This builds with CMake 4. While STEPCode's internal tools still use dynamic libraries, this builds the libraries so OpenVSP can link statically against them.

The ap203_min project is a MWE of how OpenVSP integrates and uses STEPCode, so I got this working and then applied the same approach to update OpenVSP. This request includes a CI test of ap203_min that tests generation of a minimal file and also checks that the resulting executable is only statically linked.

cshorler and others added 12 commits October 2, 2022 20:54
"cmake: declare target link interfaces explicitly" (0b950dd) made SC_ADDLIB
publish its LINK_LIBRARIES as PUBLIC. That is the right change, but it is not
compatible with the way src/cldai/CMakeLists.txt names its static dependency:

    SC_ADDLIB(stepdai-static STATIC SOURCES ${DAI_SRCS}
              LINK_LIBRARIES $<JOIN:${_libdeps},-static >-static)

_libdeps holds one entry, steputils, so the generator expression is an elaborate
way of writing steputils-static. While the dependency was linked privately it
expanded once, on the link line of stepdai-static, and was correct. Published as
PUBLIC it lands in INTERFACE_LINK_LIBRARIES and is evaluated again in every
consumer, where it comes back out mangled and reaches the linker verbatim:

    LINK : fatal error LNK1104: cannot open file $<JOIN:steputils,-static.obj

p21read_sdai_<schema> is the first consumer to hit it, so with BUILD_STATIC_LIBS=ON
no schema executable links. Reproduced on develop tip - nothing after 0b950dd
touches either file, so the static build is broken there too.

Building the list with a foreach costs nothing, reads the same, and keeps working
if _libdeps ever grows. The shared branch is untouched; this is inside
if(BUILD_STATIC_LIBS).
Update the ExternalProjectBuild example (the MWE for how OpenVSP consumes
STEPCode) for the current CMake system:

- Install to <build>/sc-install via CMAKE_INSTALL_PREFIX; SC_INSTALL_PREFIX
  is no longer honored, so the install step tried to write to /usr/local.
- Build static libraries only (BUILD_SHARED_LIBS=OFF, BUILD_STATIC_LIBS=ON)
  and link the <lib>-static archives in dependency order.
- Define SC_STATIC for the consumer so Windows headers do not dllimport.
- Declare BUILD_BYPRODUCTS so the Ninja generator works.
- Pass through CMAKE_BUILD_TYPE (default Release), PIC, and macOS
  architecture/deployment target; disable Python generator and tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Add CTest tests to the ExternalProject example: run AP203Minimum, and
inspect it with otool -L (macOS), ldd (Linux) or dumpbin /dependents
(Windows).  The tool output is printed as a diagnostic; the test fails
if any dependency is outside the system library locations, cannot be
resolved, or looks like a STEPCode library.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Existing CI never exercises a static-only build, which is how OpenVSP
consumes STEPCode.  Build example/ap203min/ExternalProjectBuild on Linux
(GCC, Clang), macOS, and Windows (MSVC with Ninja, and the default
Visual Studio generator), check no shared libraries were produced, then
run its tests: run AP203Minimum and check it has no non-system dynamic
dependencies.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
TYPEselect_print() stores a tag in the type's clientData to mark it as
being processed, then freed the tag on return while leaving clientData
pointing at it.  Later visits to the same type test clientData and read
the freed tag, a heap-use-after-free reported by AddressSanitizer while
generating ap203 and most other schemas.

Keep the tag: it is the "processed" marker the recursion relies on, one
small struct per SELECT type in a short-lived program.

With AddressSanitizer, exp2cxx now runs cleanly over all 18 schemas in
data/, and the generated code is otherwise unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

3 participants