Skip to content

fix(build): compile C++ libraries carried in a STruC++ upload - #177

Open
MatthewReed303 wants to merge 1 commit into
Autonomy-Logic:developmentfrom
MatthewReed303:fix/strucpp-resource-library-includes
Open

fix(build): compile C++ libraries carried in a STruC++ upload#177
MatthewReed303 wants to merge 1 commit into
Autonomy-Logic:developmentfrom
MatthewReed303:fix/strucpp-resource-library-includes

Conversation

@MatthewReed303

Copy link
Copy Markdown

Summary

An upload can carry ordinary C++ library folders under
core/generated/libraries/<name>/, but Makefile.strucpp could not build them:

  • GEN_CPP := $(wildcard $(GENERATED_DIR)/*.cpp) globbed the top level only, so a
    library's sources were never compiled and the link failed on its symbols.
  • Nothing put those libraries' headers on the include path, so a block's
    #include <Foo.h> did not resolve.
  • The %.o pattern rule assumed a flat object tree, so a nested source had
    nowhere to build to.

Three changes:

  • RESOURCE_LIB_INC derives an include root per library folder — its src/ when
    it has one, the folder itself otherwise — and adds them with addprefix -I.
  • Sources are discovered with find, so any depth is covered. Wrapped in sort
    for a reproducible order across filesystems.
  • The pattern rule gained mkdir -p $(@D), since
    libraries/foo/src/transport/bar.cpp now builds to
    $(BUILD_DIR)/libraries/foo/src/transport/bar.o.

An upload with no libraries/ directory compiles exactly as before — find
returns the same set the old wildcard did, and RESOURCE_LIB_INC is empty.

This is the runtime half of an editor change that lets a .stlib ship the C/C++
sources its blocks compile against; the Arduino half needs nothing from here.

Ticket

How it was tested

Built openplc-runtime in Docker from this branch, uploaded a program using a
library that ships its protocol sources as resources, and confirmed the runtime
compiled and loaded it:

-I core/generated/libraries/SensorKit/src -I core/generated/libraries/SensorNet/src
Compiling core/generated/libraries/SensorNet/src/transport/HostUdpTransport.cpp...
  -o build/libraries/SensorNet/src/transport/HostUdpTransport.o
Build complete: build/new_libplc.so
PLC started.

Every part of the change is exercised: the per-library include roots, recursive
discovery, and mkdir -p $(@D) for the nested objects. The loaded libplc_*.so
carries the library's symbols as real objects in the link.

Also confirmed an upload carrying no libraries/ directory builds unchanged.

Checklist

  • bash scripts/run-pytest.sh passes
  • pre-commit run clean
  • Docs updated if behavior changed (README, CLAUDE.md, docs/)
  • Follows docs/pr-reviews/PR_REVIEW_CHECKLIST.md

GEN_CPP globbed the top level only, so a library under
core/generated/libraries/<name>/ was never compiled and its headers were
off the include path. Discover sources recursively, add each library's
src/ as an include root, and mkdir the object directory for nested sources.
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