[ios] Enable --use_extensions with custom built iOS pod (#16711)

- Fix link errors by including the needed onnxruntime-extensions libraries in the static framework.
- Add Objective-C API to register custom ops from embedded onnxruntime-extensions.

Caveat: Not all onnxruntime-extensions build options are working yet. E.g., building with the onnxruntime-extensions OpenCV dependency does not work.
This commit is contained in:
Edward Chen 2023-07-14 15:37:16 -07:00 committed by GitHub
parent 4faee2e44c
commit f236768d5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View file

@ -228,6 +228,13 @@ if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS)
)
endif()
if (onnxruntime_USE_EXTENSIONS)
list(APPEND onnxruntime_INTERNAL_LIBRARIES
onnxruntime_extensions
ocos_operators
)
endif()
# If you are linking a new library, please add it to the list onnxruntime_INTERNAL_LIBRARIES or onnxruntime_EXTERNAL_LIBRARIES,
# Please do not add a library directly to the target_link_libraries command
target_link_libraries(onnxruntime PRIVATE

View file

@ -243,6 +243,20 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)registerCustomOpsUsingFunctionPointer:(ORTCAPIRegisterCustomOpsFnPtr)registerCustomOpsFn
error:(NSError**)error;
/**
* Registers ONNX Runtime Extensions custom ops that have been built in to ONNX Runtime.
*
* Available since 1.16.
*
* @note ONNX Runtime must have been built with the `--use_extensions` flag for the ONNX Runtime Extensions custom ops
* to be able to be registered with this method. When using a separate ONNX Runtime Extensions library, use
* `registerCustomOpsUsingFunctionPointer:error:` instead.
*
* @param error Optional error information set if an error occurs.
* @return Whether the ONNX Runtime Extensions custom ops were successfully registered.
*/
- (BOOL)enableOrtExtensionsCustomOpsWithError:(NSError**)error;
@end
/**

View file

@ -322,6 +322,14 @@ NS_ASSUME_NONNULL_BEGIN
ORT_OBJC_API_IMPL_CATCH_RETURNING_BOOL(error)
}
- (BOOL)enableOrtExtensionsCustomOpsWithError:(NSError**)error {
try {
_sessionOptions->EnableOrtCustomOps();
return YES;
}
ORT_OBJC_API_IMPL_CATCH_RETURNING_BOOL(error)
}
#pragma mark - Internal
- (Ort::SessionOptions&)CXXAPIOrtSessionOptions {