Add cc_binary target for C Libraries

PiperOrigin-RevId: 568902427
This commit is contained in:
Sebastian Schmidt 2023-09-27 11:02:35 -07:00 committed by Copybara-Service
parent b01ad84c6f
commit 61ce228576
11 changed files with 70 additions and 24 deletions

View File

@ -15,9 +15,13 @@ limitations under the License.
#include "mediapipe/tasks/c/components/containers/category_converter.h"
#include "mediapipe/tasks/c/components/containers/category.h"
#include "mediapipe/tasks/cc/components/containers/category.h"
namespace mediapipe::tasks::c::components::containers {
void CppConvertToCategory(mediapipe::tasks::components::containers::Category in,
void CppConvertToCategory(
const mediapipe::tasks::components::containers::Category& in,
Category* out) {
out->index = in.index;
out->score = in.score;

View File

@ -21,7 +21,8 @@ limitations under the License.
namespace mediapipe::tasks::c::components::containers {
void CppConvertToCategory(mediapipe::tasks::components::containers::Category in,
void CppConvertToCategory(
const mediapipe::tasks::components::containers::Category& in,
Category* out);
} // namespace mediapipe::tasks::c::components::containers

View File

@ -17,11 +17,12 @@ limitations under the License.
#include "mediapipe/tasks/c/components/containers/category.h"
#include "mediapipe/tasks/c/components/containers/category_converter.h"
#include "mediapipe/tasks/cc/components/containers/classification_result.h"
namespace mediapipe::tasks::c::components::containers {
void CppConvertToClassificationResult(
mediapipe::tasks::components::containers::ClassificationResult in,
const mediapipe::tasks::components::containers::ClassificationResult& in,
ClassificationResult* out) {
out->has_timestamp_ms = in.timestamp_ms.has_value();
if (out->has_timestamp_ms) {

View File

@ -22,7 +22,7 @@ limitations under the License.
namespace mediapipe::tasks::c::components::containers {
void CppConvertToClassificationResult(
mediapipe::tasks::components::containers::ClassificationResult in,
const mediapipe::tasks::components::containers::ClassificationResult& in,
ClassificationResult* out);
} // namespace mediapipe::tasks::c::components::containers

View File

@ -19,10 +19,10 @@ limitations under the License.
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/cc/components/processors/classifier_options.h"
namespace mediapipe::c::components::processors {
namespace mediapipe::tasks::c::components::processors {
void CppConvertToClassifierOptions(
ClassifierOptions in,
const ClassifierOptions& in,
mediapipe::tasks::components::processors::ClassifierOptions* out) {
out->display_names_locale = in.display_names_locale;
out->max_results = in.max_results;
@ -38,4 +38,4 @@ void CppConvertToClassifierOptions(
}
}
} // namespace mediapipe::c::components::processors
} // namespace mediapipe::tasks::c::components::processors

View File

@ -22,7 +22,7 @@ limitations under the License.
namespace mediapipe::tasks::c::components::processors {
void CppConvertToClassifierOptions(
ClassifierOptions in,
const ClassifierOptions& in,
mediapipe::tasks::components::processors::ClassifierOptions* out);
} // namespace mediapipe::tasks::c::components::processors

View File

@ -15,11 +15,12 @@ limitations under the License.
#include "mediapipe/tasks/c/core/base_options_converter.h"
#include "mediapipe/tasks/c/core/base_options.h"
#include "mediapipe/tasks/cc/core/base_options.h"
namespace mediapipe::tasks::c::components::containers {
void CppConvertToBaseOptions(BaseOptions in,
void CppConvertToBaseOptions(const BaseOptions& in,
mediapipe::tasks::core::BaseOptions* out) {
out->model_asset_buffer =
std::make_unique<std::string>(in.model_asset_buffer);

View File

@ -21,7 +21,7 @@ limitations under the License.
namespace mediapipe::tasks::c::components::containers {
void CppConvertToBaseOptions(BaseOptions in,
void CppConvertToBaseOptions(const BaseOptions& in,
mediapipe::tasks::core::BaseOptions* out);
} // namespace mediapipe::tasks::c::components::containers

View File

@ -17,7 +17,7 @@ package(default_visibility = ["//mediapipe/tasks:internal"])
licenses(["notice"])
cc_library(
name = "text_classifier",
name = "text_classifier_lib",
srcs = ["text_classifier.cc"],
hdrs = ["text_classifier.h"],
visibility = ["//visibility:public"],
@ -31,4 +31,39 @@ cc_library(
"//mediapipe/tasks/cc/text/text_classifier",
"@com_google_absl//absl/log:absl_log",
],
alwayslink = 1,
)
# bazel build -c opt --linkopt -s --strip always --define MEDIAPIPE_DISABLE_GPU=1 \
# //mediapipe/tasks/c/text/text_classifier:libtext_classifier.so
cc_binary(
name = "libtext_classifier.so",
linkopts = [
"-Wl,-soname=libtext_classifier.so",
"-fvisibility=hidden",
],
linkshared = True,
tags = [
"manual",
"nobuilder",
"notap",
],
deps = [":text_classifier_lib"],
)
# bazel build --config darwin_arm64 -c opt --strip always --define MEDIAPIPE_DISABLE_GPU=1 \
# //mediapipe/tasks/c/text/text_classifier:libtext_classifier.dylib
cc_binary(
name = "libtext_classifier.dylib",
linkopts = [
"-Wl,-install_name,libtext_classifier.dylib",
"-fvisibility=hidden",
],
linkshared = True,
tags = [
"manual",
"nobuilder",
"notap",
],
deps = [":text_classifier_lib"],
)

View File

@ -16,9 +16,9 @@ limitations under the License.
#include "mediapipe/tasks/c/text/text_classifier/text_classifier.h"
#include <memory>
#include <utility>
#include "absl/log/absl_log.h"
#include "mediapipe/tasks/c/components/containers/classification_result.h"
#include "mediapipe/tasks/c/components/containers/classification_result_converter.h"
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/c/components/processors/classifier_options_converter.h"
@ -38,7 +38,7 @@ using ::mediapipe::tasks::c::components::processors::
using ::mediapipe::tasks::text::text_classifier::TextClassifier;
} // namespace
TextClassifier* CppTextClassifierCreate(TextClassifierOptions options) {
TextClassifier* CppTextClassifierCreate(const TextClassifierOptions& options) {
auto cpp_options = std::make_unique<
::mediapipe::tasks::text::text_classifier::TextClassifierOptions>();
@ -80,12 +80,12 @@ void CppTextClassifierClose(void* classifier) {
extern "C" {
void* text_classifier_create(struct TextClassifierOptions options) {
void* text_classifier_create(struct TextClassifierOptions* options) {
return mediapipe::tasks::c::text::text_classifier::CppTextClassifierCreate(
options);
*options);
}
bool text_classifier_classify(void* classifier, char* utf8_str,
int text_classifier_classify(void* classifier, char* utf8_str,
TextClassifierResult* result) {
return mediapipe::tasks::c::text::text_classifier::CppTextClassifierClassify(
classifier, utf8_str, result);

View File

@ -20,11 +20,15 @@ limitations under the License.
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/c/core/base_options.h"
#ifndef MP_EXPORT
#define MP_EXPORT __attribute__((visibility("default")))
#endif // MP_EXPORT
#ifdef __cplusplus
extern "C" {
#endif
typedef ClassificationResult TextClassifierResult;
typedef struct ClassificationResult TextClassifierResult;
// The options for configuring a MediaPipe text classifier task.
struct TextClassifierOptions {
@ -38,14 +42,14 @@ struct TextClassifierOptions {
};
// Creates a TextClassifier from the provided `options`.
void* text_classifier_create(struct TextClassifierOptions options);
MP_EXPORT void* text_classifier_create(struct TextClassifierOptions* options);
// Performs classification on the input `text`.
bool text_classifier_classify(void* classifier, char* utf8_str,
MP_EXPORT int text_classifier_classify(void* classifier, char* utf8_str,
TextClassifierResult* result);
// Shuts down the TextClassifier when all the work is done. Frees all memory.
void text_classifier_close(void* classifier);
MP_EXPORT void text_classifier_close(void* classifier);
#ifdef __cplusplus
} // extern C