Skip to content

Add splitclasses option for C++ output (one header per class) - #244

Open
Kimeeek42 wants to merge 1 commit into
Autodesk:developfrom
Kimeeek42:feat/uck/splitCppOutput
Open

Kimeeek42 wants to merge 1 commit into
Autodesk:developfrom
Kimeeek42:feat/uck/splitCppOutput

Conversation

@Kimeeek42

Copy link
Copy Markdown

Closes #243

What

Adds an optional boolean attribute splitclasses (default false) to
<implementation language="Cpp"> and <binding language="CppDynamic">.
Without it the generated output is unchanged.

Output with splitclasses="true"

Cpp implementation:

  • <base>_interface_<class>.hpp per class
  • <base>_interfaces_fwd.hpp (forward declarations)
  • <base>_interfaces.hpp as an umbrella header

CppDynamic binding:

  • <base>_dynamic_<class>.hpp per class
  • _fwd, _wrapper and _table headers and the <base>_dynamic.hpp umbrella
  • one <base>_dynamic.cpp with the method bodies (it must be compiled and
    linked). The function table is private to CWrapper.
  • no .h header and no example application

Class names fwd, wrapper and table are rejected by the CppDynamic
binding in split mode because they would clash with the helper headers.

Why

For large components a single IDL edit regenerates multi-megabyte files and
forces every translation unit that includes them to rebuild. In our component
(about 450 classes) a simple method change (editing one method description)
took about 23 minutes to rebuild. When the files are synced by content,
unchanged class headers keep their timestamps and only their includers
rebuild. The same edit now takes about 1:20.

Implementation notes

  • Reuses the existing generators. buildbindingccpp.go gets a style parameter
    (header-only or split) instead of a copy of the code. The split-specific
    code is in buildbindingccppsplit.go and buildimplementationcppsplit.go.
  • Documented in Documentation/IDL.md and Source/ACT.xsd.
  • build.sh and build.bat include the new source files.

Testing

Before rebasing onto the current develop:

  • Without the attribute, the output is byte-identical to develop (compared
    on a ~450-class component, an RTTI example, and the thread safety and
    injection examples).
  • With the attribute, the generated code compiles with MSVC on the same
    components.
  • Doxygen output is equal for old and new, apart from four private
    CWrapper::*WrapperTable helpers.

After the rebase:

  • The generated C++ files in split mode are identical to those from the
    pre-rebase build on the ~450-class component.
  • libPrimes (which has a journal method) generates with splitclasses on
    both the binding and the implementation. MSVC compiles the generated
    wrapper, journal and exception sources without errors.

Not tested: macOS and Linux compilers, running a split build at runtime
(including the journal output), and the byte-identity comparison against
develop after the rebase.

Changing one method of the API description makes everything that includes the
monolithic generated C++ headers rebuild.

splitclasses="true" on <implementation language="Cpp">:
- writes <basename>_interface_<class>.hpp for every class, <basename>_interfaces.hpp
  stays as an umbrella header
- new stubs include only the header of their own class

splitclasses="true" on <binding language="CppDynamic">:
- writes one header per class with the declarations only, and the method bodies,
  function table and polymorphic factory in a single source file, so the binding
  is no longer header-only: the source file has to be compiled and linked
- no example is generated for this variant

Without the attribute the generated output is unchanged. The attribute is
documented in IDL.md and ACT.xsd. Build/build.sh and build.bat list the new
source files.
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