Skip to content

Commit 69ec814

Browse files
msluszniakclaude
andcommitted
fix: guard opencv/phonemizer code paths when features are disabled
Fixes build failures when RNE_ENABLE_OPENCV=OFF or RNE_ENABLE_PHONEMIZER=OFF: - RnExecutorchInstaller.cpp: guard CV model includes and JSI registrations with #ifdef RNE_ENABLE_OPENCV, phonemizer registration with #ifdef RNE_ENABLE_PHONEMIZER - LLM.cpp: guard VisionEncoder and MultimodalRunner (VLM support) with #ifdef RNE_ENABLE_OPENCV — text-only LLM still works without OpenCV - CMakeLists.txt: add runner/encoders/vision_encoder.cpp, runner/multimodal_prefiller.cpp and runner/multimodal_runner.cpp to OPENCV_CPP_SOURCES so they are excluded when OpenCV is disabled Verified: Android build succeeds with enableOpencv=false, enablePhonemizer=false. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0c23fd8 commit 69ec814

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

packages/react-native-executorch/android/src/main/cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ file(GLOB_RECURSE OPENCV_CPP_SOURCES CONFIGURE_DEPENDS
3030
"${COMMON_CPP_DIR}/rnexecutorch/utils/FrameProcessor.cpp"
3131
"${COMMON_CPP_DIR}/rnexecutorch/utils/FrameTransform.cpp"
3232
"${COMMON_CPP_DIR}/rnexecutorch/utils/computer_vision/*.cpp"
33+
"${COMMON_CPP_DIR}/runner/encoders/vision_encoder.cpp"
34+
"${COMMON_CPP_DIR}/runner/multimodal_prefiller.cpp"
35+
"${COMMON_CPP_DIR}/runner/multimodal_runner.cpp"
3336
)
3437

3538
# Phonemizer-dependent sources: Kokoro TTS (only user of phonemis)

packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@
22

33
#include <rnexecutorch/TokenizerModule.h>
44
#include <rnexecutorch/host_objects/JsiConversions.h>
5+
#include <rnexecutorch/models/embeddings/text/TextEmbeddings.h>
6+
#include <rnexecutorch/models/llm/LLM.h>
7+
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
8+
#include <rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h>
9+
#include <rnexecutorch/threads/GlobalThreadPool.h>
10+
#include <rnexecutorch/threads/utils/ThreadUtils.h>
11+
12+
#ifdef RNE_ENABLE_OPENCV
513
#include <rnexecutorch/models/classification/Classification.h>
614
#include <rnexecutorch/models/embeddings/image/ImageEmbeddings.h>
7-
#include <rnexecutorch/models/embeddings/text/TextEmbeddings.h>
815
#include <rnexecutorch/models/instance_segmentation/BaseInstanceSegmentation.h>
9-
#include <rnexecutorch/models/llm/LLM.h>
1016
#include <rnexecutorch/models/object_detection/ObjectDetection.h>
1117
#include <rnexecutorch/models/ocr/OCR.h>
1218
#include <rnexecutorch/models/semantic_segmentation/BaseSemanticSegmentation.h>
13-
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
1419
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
1520
#include <rnexecutorch/models/text_to_image/TextToImage.h>
16-
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
1721
#include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
18-
#include <rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h>
19-
#include <rnexecutorch/threads/GlobalThreadPool.h>
20-
#include <rnexecutorch/threads/utils/ThreadUtils.h>
22+
#endif
23+
24+
#ifdef RNE_ENABLE_PHONEMIZER
25+
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
26+
#endif
2127

2228
#if defined(__ANDROID__) && defined(__aarch64__)
2329
#include <executorch/extension/threadpool/cpuinfo_utils.h>
@@ -40,6 +46,7 @@ void RnExecutorchInstaller::injectJSIBindings(
4046
jsiRuntime->global().setProperty(*jsiRuntime, "__rne_isEmulator",
4147
jsi::Value(isEmulator));
4248

49+
#ifdef RNE_ENABLE_OPENCV
4350
jsiRuntime->global().setProperty(
4451
*jsiRuntime, "loadStyleTransfer",
4552
RnExecutorchInstaller::loadModel<models::style_transfer::StyleTransfer>(
@@ -72,6 +79,7 @@ void RnExecutorchInstaller::injectJSIBindings(
7279
RnExecutorchInstaller::loadModel<
7380
models::object_detection::ObjectDetection>(jsiRuntime, jsCallInvoker,
7481
"loadObjectDetection"));
82+
#endif // RNE_ENABLE_OPENCV
7583

7684
jsiRuntime->global().setProperty(
7785
*jsiRuntime, "loadExecutorchModule",
@@ -83,10 +91,12 @@ void RnExecutorchInstaller::injectJSIBindings(
8391
RnExecutorchInstaller::loadModel<TokenizerModule>(
8492
jsiRuntime, jsCallInvoker, "loadTokenizerModule"));
8593

94+
#ifdef RNE_ENABLE_OPENCV
8695
jsiRuntime->global().setProperty(
8796
*jsiRuntime, "loadImageEmbeddings",
8897
RnExecutorchInstaller::loadModel<models::embeddings::ImageEmbeddings>(
8998
jsiRuntime, jsCallInvoker, "loadImageEmbeddings"));
99+
#endif // RNE_ENABLE_OPENCV
90100

91101
jsiRuntime->global().setProperty(
92102
*jsiRuntime, "loadTextEmbeddings",
@@ -98,6 +108,7 @@ void RnExecutorchInstaller::injectJSIBindings(
98108
RnExecutorchInstaller::loadModel<models::llm::LLM>(
99109
jsiRuntime, jsCallInvoker, "loadLLM"));
100110

111+
#ifdef RNE_ENABLE_OPENCV
101112
jsiRuntime->global().setProperty(
102113
*jsiRuntime, "loadOCR",
103114
RnExecutorchInstaller::loadModel<models::ocr::OCR>(
@@ -107,16 +118,19 @@ void RnExecutorchInstaller::injectJSIBindings(
107118
*jsiRuntime, "loadVerticalOCR",
108119
RnExecutorchInstaller::loadModel<models::ocr::VerticalOCR>(
109120
jsiRuntime, jsCallInvoker, "loadVerticalOCR"));
121+
#endif // RNE_ENABLE_OPENCV
110122

111123
jsiRuntime->global().setProperty(
112124
*jsiRuntime, "loadSpeechToText",
113125
RnExecutorchInstaller::loadModel<models::speech_to_text::SpeechToText>(
114126
jsiRuntime, jsCallInvoker, "loadSpeechToText"));
115127

128+
#ifdef RNE_ENABLE_PHONEMIZER
116129
jsiRuntime->global().setProperty(
117130
*jsiRuntime, "loadTextToSpeechKokoro",
118131
RnExecutorchInstaller::loadModel<models::text_to_speech::kokoro::Kokoro>(
119132
jsiRuntime, jsCallInvoker, "loadTextToSpeechKokoro"));
133+
#endif // RNE_ENABLE_PHONEMIZER
120134

121135
jsiRuntime->global().setProperty(
122136
*jsiRuntime, "loadVAD",

packages/react-native-executorch/common/rnexecutorch/models/llm/LLM.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
#include <rnexecutorch/Error.h>
77
#include <rnexecutorch/Log.h>
88
#include <rnexecutorch/threads/GlobalThreadPool.h>
9+
#include <runner/text_runner.h>
10+
#ifdef RNE_ENABLE_OPENCV
911
#include <runner/encoders/vision_encoder.h>
1012
#include <runner/multimodal_runner.h>
11-
#include <runner/text_runner.h>
13+
#endif
1214

1315
namespace rnexecutorch::models::llm {
1416
namespace llm = ::executorch::extension::llm;
@@ -22,10 +24,8 @@ LLM::LLM(const std::string &modelSource, const std::string &tokenizerSource,
2224
std::shared_ptr<react::CallInvoker> callInvoker)
2325
: BaseModel(modelSource, callInvoker, Module::LoadMode::File) {
2426

25-
if (capabilities.empty()) {
26-
runner_ =
27-
std::make_unique<llm::TextRunner>(std::move(module_), tokenizerSource);
28-
} else {
27+
#ifdef RNE_ENABLE_OPENCV
28+
if (!capabilities.empty()) {
2929
std::map<llm::MultimodalType, std::unique_ptr<llm::IEncoder>> encoders;
3030
for (const auto &cap : capabilities) {
3131
if (cap == "vision") {
@@ -35,7 +35,13 @@ LLM::LLM(const std::string &modelSource, const std::string &tokenizerSource,
3535
}
3636
runner_ = std::make_unique<llm::MultimodalRunner>(
3737
std::move(module_), tokenizerSource, std::move(encoders));
38+
} else {
39+
#endif
40+
runner_ =
41+
std::make_unique<llm::TextRunner>(std::move(module_), tokenizerSource);
42+
#ifdef RNE_ENABLE_OPENCV
3843
}
44+
#endif
3945

4046
auto loadResult = runner_->load();
4147
if (loadResult != Error::Ok) {

0 commit comments

Comments
 (0)