From 0f98569d00ba933b8be1d00b4c87d42257fbe88d Mon Sep 17 00:00:00 2001 From: contra Date: Fri, 6 Mar 2026 17:24:05 -0800 Subject: [PATCH] fix: React Native 0.83+ CRTP codegen compatibility React Native 0.83 switched TurboModule codegen from virtual inheritance to CRTP (Curiously Recurring Template Pattern). This changes the base class from `NativePolygenCxxSpecJSI` to `NativePolygenCxxSpec` and removes `override` keywords from method declarations, since CRTP uses static dispatch rather than virtual dispatch. Also adds the required `page_size` argument (65536) to `wasm_rt_allocate_memory` for wabt 1.0.39 compatibility. --- .../ReactNativePolygen/ReactNativePolygen.cpp | 2 +- .../ReactNativePolygen/ReactNativePolygen.h | 36 +++++++++---------- .../ReactNativePolygen/WebAssembly/Memory.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.cpp b/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.cpp index 81363d7..0710227 100644 --- a/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.cpp +++ b/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.cpp @@ -15,7 +15,7 @@ using namespace callstack::polygen; namespace facebook::react { ReactNativePolygen::ReactNativePolygen(std::shared_ptr jsInvoker) - : NativePolygenCxxSpecJSI(std::move(jsInvoker)) + : NativePolygenCxxSpec(std::move(jsInvoker)) , moduleRegistry_(generated::getModuleBag()) , moduleLoader_(moduleRegistry_) { wasm_rt_init(); diff --git a/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.h b/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.h index a309a94..950ff87 100644 --- a/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.h +++ b/packages/polygen/cpp/ReactNativePolygen/ReactNativePolygen.h @@ -48,39 +48,39 @@ struct Bridging : public NativePolygenModuleExportDescri template <> struct Bridging : public NativePolygenInternalModuleMetadataBridging {}; -class ReactNativePolygen : public NativePolygenCxxSpecJSI { +class ReactNativePolygen : public NativePolygenCxxSpec { public: constexpr static auto kModuleName = "Polygen"; explicit ReactNativePolygen(std::shared_ptr jsInvoker); virtual ~ReactNativePolygen(); - bool copyNativeHandle(jsi::Runtime &rt, jsi::Object holder, jsi::Object source) override; + bool copyNativeHandle(jsi::Runtime &rt, jsi::Object holder, jsi::Object source); // Modules - jsi::Object loadModule(jsi::Runtime &rt, jsi::Object holder, jsi::Object moduleData) override; - void unloadModule(jsi::Runtime &rt, jsi::Object moduleHolder) override; - jsi::Object getModuleMetadata(jsi::Runtime &rt, jsi::Object moduleHolder) override; + jsi::Object loadModule(jsi::Runtime &rt, jsi::Object holder, jsi::Object moduleData); + void unloadModule(jsi::Runtime &rt, jsi::Object moduleHolder); + jsi::Object getModuleMetadata(jsi::Runtime &rt, jsi::Object moduleHolder); - void createModuleInstance(jsi::Runtime &rt, jsi::Object instanceHolder, jsi::Object moduleHolder, jsi::Object importObject) override; - void destroyModuleInstance(jsi::Runtime &rt, jsi::Object instance) override; + void createModuleInstance(jsi::Runtime &rt, jsi::Object instanceHolder, jsi::Object moduleHolder, jsi::Object importObject); + void destroyModuleInstance(jsi::Runtime &rt, jsi::Object instance); // Memories - void createMemory(jsi::Runtime &rt, jsi::Object holder, double initial, std::optional maximum) override; - jsi::Object getMemoryBuffer(jsi::Runtime &rt, jsi::Object instance) override; - void growMemory(jsi::Runtime &rt, jsi::Object instance, double delta) override; + void createMemory(jsi::Runtime &rt, jsi::Object holder, double initial, std::optional maximum); + jsi::Object getMemoryBuffer(jsi::Runtime &rt, jsi::Object instance); + void growMemory(jsi::Runtime &rt, jsi::Object instance, double delta); // Globals - void createGlobal(jsi::Runtime &rt, jsi::Object holder, jsi::Object globalDescriptor, double initialValue) override; - double getGlobalValue(jsi::Runtime &rt, jsi::Object instance) override; - void setGlobalValue(jsi::Runtime &rt, jsi::Object instance, double newValue) override; + void createGlobal(jsi::Runtime &rt, jsi::Object holder, jsi::Object globalDescriptor, double initialValue); + double getGlobalValue(jsi::Runtime &rt, jsi::Object instance); + void setGlobalValue(jsi::Runtime &rt, jsi::Object instance, double newValue); // Tables - void createTable(jsi::Runtime &rt, jsi::Object holder, jsi::Object tableDescriptor, std::optional initial) override; - void growTable(jsi::Runtime &rt, jsi::Object instance, double delta) override; - jsi::Object getTableElement(jsi::Runtime &rt, jsi::Object instance, double index) override; - void setTableElement(jsi::Runtime &rt, jsi::Object instance, double index, jsi::Object value) override; - double getTableSize(jsi::Runtime &rt, jsi::Object instance) override; + void createTable(jsi::Runtime &rt, jsi::Object holder, jsi::Object tableDescriptor, std::optional initial); + void growTable(jsi::Runtime &rt, jsi::Object instance, double delta); + jsi::Object getTableElement(jsi::Runtime &rt, jsi::Object instance, double index); + void setTableElement(jsi::Runtime &rt, jsi::Object instance, double index, jsi::Object value); + double getTableSize(jsi::Runtime &rt, jsi::Object instance); private: // Utility diff --git a/packages/polygen/cpp/ReactNativePolygen/WebAssembly/Memory.h b/packages/polygen/cpp/ReactNativePolygen/WebAssembly/Memory.h index 328c175..89852ff 100644 --- a/packages/polygen/cpp/ReactNativePolygen/WebAssembly/Memory.h +++ b/packages/polygen/cpp/ReactNativePolygen/WebAssembly/Memory.h @@ -17,7 +17,7 @@ class Memory: public facebook::jsi::NativeState, public facebook::jsi::MutableBu Memory(uint64_t initial, uint64_t maximum, bool is64 = false) { this->memory_ = &this->ownedMemory_; - wasm_rt_allocate_memory(this->memory_, initial, maximum, is64); + wasm_rt_allocate_memory(this->memory_, initial, maximum, is64, 65536); } virtual ~Memory() {