Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-ios-llm-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
-scheme llm \
-sdk iphonesimulator \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro' \
-destination 'platform=iOS Simulator,name=iPhone 17 Pro' \
build \
CODE_SIGNING_ALLOWED=NO \
-jobs $(sysctl -n hw.ncpu) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void ETInstallerModule::registerNatives() {
});
}

void ETInstallerModule::injectJSIBindings() {
void ETInstallerModule::injectJSIBindings(jni::alias_ref<jstring> bundleId) {
// Grab a function for fetching images via URL from Java
auto fetchDataByUrl = [](std::string url) {
// Attaching Current Thread to JVM
Expand Down Expand Up @@ -67,9 +67,10 @@ void ETInstallerModule::injectJSIBindings() {
};

auto _isEmulator = isEmulator();
auto _bundleId = bundleId ? bundleId->toStdString() : std::string();

RnExecutorchInstaller::injectJSIBindings(jsiRuntime_, jsCallInvoker_,
fetchDataByUrl, _isEmulator);
RnExecutorchInstaller::injectJSIBindings(
jsiRuntime_, jsCallInvoker_, fetchDataByUrl, _isEmulator, _bundleId);
}
} // namespace rnexecutorch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ETInstallerModule : public jni::HybridClass<ETInstallerModule> {

static void registerNatives();

void injectJSIBindings();
void injectJSIBindings(jni::alias_ref<jstring> bundleId);

private:
friend HybridBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ETInstaller(
callInvoker: CallInvokerHolderImpl,
): HybridData

private external fun injectJSIBindings()
private external fun injectJSIBindings(bundleId: String)

init {
try {
Expand All @@ -60,7 +60,7 @@ class ETInstaller(

@ReactMethod(isBlockingSynchronousMethod = true)
override fun install(): Boolean {
injectJSIBindings()
injectJSIBindings(reactApplicationContext.packageName)
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ FetchUrlFunc_t fetchUrlFunc;

void RnExecutorchInstaller::injectJSIBindings(
jsi::Runtime *jsiRuntime, std::shared_ptr<react::CallInvoker> jsCallInvoker,
FetchUrlFunc_t fetchDataFromUrl, bool isEmulator) {
FetchUrlFunc_t fetchDataFromUrl, bool isEmulator,
const std::string &bundleId) {
fetchUrlFunc = fetchDataFromUrl;

jsiRuntime->global().setProperty(*jsiRuntime, "__rne_isEmulator",
jsi::Value(isEmulator));

jsiRuntime->global().setProperty(
*jsiRuntime, "__rne_bundleId",
jsi::String::createFromUtf8(*jsiRuntime, bundleId));

jsiRuntime->global().setProperty(
*jsiRuntime, "loadStyleTransfer",
RnExecutorchInstaller::loadModel<models::style_transfer::StyleTransfer>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class RnExecutorchInstaller {
static void
injectJSIBindings(jsi::Runtime *jsiRuntime,
std::shared_ptr<react::CallInvoker> jsCallInvoker,
FetchUrlFunc_t fetchDataFromUrl, bool isEmulator);
FetchUrlFunc_t fetchDataFromUrl, bool isEmulator,
const std::string &bundleId);

private:
template <typename ModelT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ @implementation ETInstaller
}
};
bool isEmulator = TARGET_OS_SIMULATOR;
NSString *nsBundleId = [[NSBundle mainBundle] bundleIdentifier];
std::string bundleId = nsBundleId ? nsBundleId.UTF8String : "";
rnexecutorch::RnExecutorchInstaller::injectJSIBindings(
jsiRuntime, jsCallInvoker, fetchUrl, isEmulator);
jsiRuntime, jsCallInvoker, fetchUrl, isEmulator, bundleId);

NSLog(@"Successfully installed JSI bindings for react-native-executorch!");
return @true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Pod::Spec.new do |s|
"third-party/common/phonemis/src/**/*.{cpp,hpp,h}",
]

s.resource_bundles = {
'RnExecutorchPrivacyInfo' => ['ios/PrivacyInfo.xcprivacy'],
}

s.libraries = "z"
s.ios.vendored_frameworks = "third-party/ios/ExecutorchLib.xcframework"

Expand Down
5 changes: 4 additions & 1 deletion packages/react-native-executorch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ declare global {
) => Promise<any>;
// eslint-disable-next-line camelcase
var __rne_isEmulator: boolean;
// eslint-disable-next-line camelcase
var __rne_bundleId: string;
}
// eslint-disable no-var

Expand All @@ -142,7 +144,8 @@ if (
global.loadTextToSpeechKokoro == null ||
global.loadOCR == null ||
global.loadVerticalOCR == null ||
global.__rne_isEmulator == null
global.__rne_isEmulator == null ||
global.__rne_bundleId == null
) {
if (!ETInstallerNativeModule) {
throw new Error(
Expand Down
34 changes: 18 additions & 16 deletions packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getModelNameForUrl } from '../constants/modelUrls';
import {
DOWNLOAD_EVENT_ENDPOINT,
LIB_VERSION,
} from '../constants/resourceFetcher';
import { DOWNLOAD_EVENT_ENDPOINT } from '../constants/resourceFetcher';
import { Platform } from 'react-native';
/**
* Http status codes
* @category Types
Expand Down Expand Up @@ -174,6 +172,10 @@ export namespace ResourceFetcherUtils {
return global.__rne_isEmulator;
}

export function getBundleId(): string {
return global.__rne_bundleId;
}

function getModelNameFromUri(uri: string): string {
const knownName = getModelNameForUrl(uri);
if (knownName) {
Expand All @@ -189,18 +191,18 @@ export namespace ResourceFetcherUtils {
* @param uri - The URI of the downloaded resource.
*/
export function triggerDownloadEvent(uri: string) {
try {
fetch(DOWNLOAD_EVENT_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
modelName: getModelNameFromUri(uri),
countryCode: getCountryCode(),
isEmulator: isEmulator(),
libVersion: LIB_VERSION,
}),
});
} catch (e) {}
fetch(DOWNLOAD_EVENT_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
bundleId: getBundleId(),
countryCode: getCountryCode(),
isEmulator: isEmulator(),
libVersion: require('../../package.json').version,
modelName: getModelNameFromUri(uri),
system: Platform.OS,
}),
}).catch((_) => {});
}

/**
Expand Down
Loading