linuxCppStubContent function

String linuxCppStubContent({
  1. required String lib,
  2. required String className,
})

Returns the content of a linux/src/Hybrid${className}.cpp stub.

Linux uses __attribute__((constructor)) (GCC/Clang extension) to auto-register the implementation when the shared library is loaded. This is identical to the shared src/HybridXxx.cpp pattern but lives in the platform-specific linux/src/ directory so that the desktop CMake target can link it directly.

Implementation

String linuxCppStubContent({
  required String lib,
  required String className,
}) =>
    '// Hybrid$className — LinuxNativeImpl.cpp implementation.\n'
    '// Generated by nitrogen init. Fill in the method bodies.\n'
    '#include "../../lib/src/generated/cpp/$lib.native.g.h"\n'
    '\n'
    '#include <string>\n'
    '\n'
    'class Hybrid${className}Impl final : public Hybrid$className {\n'
    'public:\n'
    '    // TODO: implement all pure-virtual methods declared in Hybrid$className\n'
    '};\n'
    '\n'
    '// GCC/Clang auto-registration via constructor attribute.\n'
    '__attribute__((constructor))\n'
    'static void nitro_auto_register() {\n'
    '    ${lib}_register_impl(new Hybrid${className}Impl());\n'
    '}\n';