Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: a switch to enable/disable ten_runtime depends on ten_rust #242

Merged
merged 3 commits into from
Nov 7, 2024
Merged
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
7 changes: 7 additions & 0 deletions build/ten_runtime/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ declare_args() {
# The go lint only depends on GO SDK which is platform independent, so only
# one CI node is enough to run the lint.
ten_enable_go_lint = ten_enable_go_binding && is_linux && is_clang && is_debug

# Whether to call apis in the ten_rust library from ten_runtime.
ten_enable_ten_rust_apis = true
}

declare_args() {
Expand All @@ -66,6 +69,10 @@ if (ten_enable_memory_check) {
ten_runtime_common_defines += [ "TEN_ENABLE_MEMORY_CHECK" ]
}

if (ten_enable_ten_rust && ten_enable_ten_rust_apis) {
ten_runtime_common_defines += [ "TEN_ENABLE_TEN_RUST_APIS" ]
}

common_deps = []
common_public_deps = []

Expand Down
5 changes: 4 additions & 1 deletion core/src/ten_runtime/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/glob.gni")
import("//build/ten_runtime/options.gni")

glob("app") {
file_list = all_native_files
Expand All @@ -13,5 +14,7 @@ glob("app") {
"ten_env",
]

public_deps = [ "//core/src/ten_rust:ten_rust_binding" ]
if (ten_enable_ten_rust && ten_enable_ten_rust_apis) {
public_deps = [ "//core/src/ten_rust:ten_rust_binding" ]
}
}
12 changes: 10 additions & 2 deletions core/src/ten_runtime/app/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@

#include "include_internal/ten_runtime/app/app.h"
#include "include_internal/ten_runtime/app/base_dir.h"
#include "ten_runtime/app/app.h"
#include "ten_utils/macro/mark.h"

#if defined(TEN_ENABLE_TEN_RUST_APIS)
#include "include_internal/ten_runtime/common/constant_str.h"
#include "include_internal/ten_rust/ten_rust.h"
#include "ten_runtime/app/app.h"
#include "ten_utils/macro/memory.h"
#endif

bool ten_app_check_start_graph_cmd_json(ten_app_t *self,
ten_json_t *start_graph_cmd_json,
ten_error_t *err) {
TEN_UNUSED ten_error_t *err) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");
TEN_ASSERT(start_graph_cmd_json, "Invalid argument.");

#if defined(TEN_ENABLE_TEN_RUST_APIS)
const char *base_dir = ten_app_get_base_dir(self);

// The pkg_info of extensions in the graph is read from the ten_packages
Expand Down Expand Up @@ -49,4 +54,7 @@ bool ten_app_check_start_graph_cmd_json(ten_app_t *self,
}

return rc;
#else
return true;
#endif
}
6 changes: 5 additions & 1 deletion core/src/ten_runtime/metadata/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/glob.gni")
import("//build/ten_runtime/options.gni")

glob("metadata") {
file_list = all_native_files
deps = [ "default" ]
public_deps = [ "//core/src/ten_rust:ten_rust_binding" ]

if (ten_enable_ten_rust && ten_enable_ten_rust_apis) {
public_deps = [ "//core/src/ten_rust:ten_rust_binding" ]
}
}
13 changes: 12 additions & 1 deletion core/src/ten_runtime/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include_internal/ten_runtime/common/constant_str.h"
#include "include_internal/ten_runtime/metadata/metadata_info.h"
#include "include_internal/ten_runtime/schema_store/store.h"
#include "include_internal/ten_rust/ten_rust.h"
#include "ten_runtime/ten_env/ten_env.h"
#include "ten_utils/lib/alloc.h"
#include "ten_utils/lib/error.h"
Expand All @@ -19,6 +18,10 @@
#include "ten_utils/value/value_is.h"
#include "ten_utils/value/value_object.h"

#if defined(TEN_ENABLE_TEN_RUST_APIS)
#include "include_internal/ten_rust/ten_rust.h"
#endif

static bool ten_metadata_load_from_json_string(ten_value_t *metadata,
const char *json_str,
ten_error_t *err) {
Expand Down Expand Up @@ -150,6 +153,7 @@ bool ten_manifest_json_string_is_valid(const char *json_string,
TEN_ASSERT(json_string, "Invalid argument.");
TEN_ASSERT(err && ten_error_check_integrity(err), "Invalid argument.");

#if defined(TEN_ENABLE_TEN_RUST_APIS)
const char *err_msg = NULL;
bool rc = ten_validate_manifest_json_string(json_string, &err_msg);

Expand All @@ -158,6 +162,7 @@ bool ten_manifest_json_string_is_valid(const char *json_string,
ten_rust_free_cstring(err_msg);
return false;
}
#endif

return true;
}
Expand All @@ -166,6 +171,7 @@ bool ten_manifest_json_file_is_valid(const char *json_file, ten_error_t *err) {
TEN_ASSERT(json_file, "Invalid argument.");
TEN_ASSERT(err && ten_error_check_integrity(err), "Invalid argument.");

#if defined(TEN_ENABLE_TEN_RUST_APIS)
const char *err_msg = NULL;
bool rc = ten_validate_manifest_json_file(json_file, &err_msg);

Expand All @@ -174,6 +180,7 @@ bool ten_manifest_json_file_is_valid(const char *json_file, ten_error_t *err) {
ten_rust_free_cstring(err_msg);
return false;
}
#endif

return true;
}
Expand All @@ -183,6 +190,7 @@ bool ten_property_json_string_is_valid(const char *json_string,
TEN_ASSERT(json_string, "Invalid argument.");
TEN_ASSERT(err && ten_error_check_integrity(err), "Invalid argument.");

#if defined(TEN_ENABLE_TEN_RUST_APIS)
const char *err_msg = NULL;
bool rc = ten_validate_property_json_string(json_string, &err_msg);

Expand All @@ -191,6 +199,7 @@ bool ten_property_json_string_is_valid(const char *json_string,
ten_rust_free_cstring(err_msg);
return false;
}
#endif

return true;
}
Expand All @@ -199,6 +208,7 @@ bool ten_property_json_file_is_valid(const char *json_file, ten_error_t *err) {
TEN_ASSERT(json_file, "Invalid argument.");
TEN_ASSERT(err && ten_error_check_integrity(err), "Invalid argument.");

#if defined(TEN_ENABLE_TEN_RUST_APIS)
const char *err_msg = NULL;
bool rc = ten_validate_property_json_file(json_file, &err_msg);

Expand All @@ -207,6 +217,7 @@ bool ten_property_json_file_is_valid(const char *json_file, ten_error_t *err) {
ten_rust_free_cstring(err_msg);
return false;
}
#endif

return true;
}
6 changes: 5 additions & 1 deletion core/src/ten_runtime/schema_store/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/glob.gni")
import("//build/ten_runtime/options.gni")

glob("schema_store") {
file_list = all_native_files
deps = [ "//core/src/ten_rust:ten_rust_binding" ]

if (ten_enable_ten_rust && ten_enable_ten_rust_apis) {
deps = [ "//core/src/ten_rust:ten_rust_binding" ]
}
}
18 changes: 13 additions & 5 deletions core/src/ten_runtime/schema_store/interface_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
// Refer to the "LICENSE" file in the root directory for more information.
//
#include "include_internal/ten_runtime/schema_store/interface.h"
#include "include_internal/ten_rust/ten_rust.h"
#include "ten_runtime/common/errno.h"
#include "ten_utils/lib/error.h"
#include "ten_utils/lib/json.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/memory.h"
#include "ten_utils/macro/mark.h"
#include "ten_utils/value/value.h"
#include "ten_utils/value/value_is.h"
#include "ten_utils/value/value_json.h"

#if defined(TEN_ENABLE_TEN_RUST_APIS)
#include "include_internal/ten_rust/ten_rust.h"
#include "ten_utils/lib/json.h"
#include "ten_utils/macro/memory.h"
#endif

ten_value_t *ten_interface_schema_info_resolve(
ten_value_t *unresolved_interface_schema_def, const char *base_dir,
ten_error_t *err) {
ten_value_t *unresolved_interface_schema_def,
TEN_UNUSED const char *base_dir, ten_error_t *err) {
TEN_ASSERT(unresolved_interface_schema_def &&
ten_value_check_integrity(unresolved_interface_schema_def),
"Invalid argument.");
Expand All @@ -29,6 +33,7 @@ ten_value_t *ten_interface_schema_info_resolve(
return NULL;
}

#if defined(TEN_ENABLE_TEN_RUST_APIS)
ten_json_t *unresolved_interface_schema_json =
ten_value_to_json(unresolved_interface_schema_def);

Expand Down Expand Up @@ -76,4 +81,7 @@ ten_value_t *ten_interface_schema_info_resolve(
}

return resolved_interface_schema_def;
#else
return NULL;
#endif
}
12 changes: 8 additions & 4 deletions core/src/ten_runtime/schema_store/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ten_utils/lib/string.h"
#include "ten_utils/macro/check.h"
#include "ten_utils/macro/field.h"
#include "ten_utils/macro/mark.h"
#include "ten_utils/value/value.h"
#include "ten_utils/value/value_is.h"
#include "ten_utils/value/value_kv.h"
Expand Down Expand Up @@ -234,6 +235,7 @@ bool ten_schema_store_set_schema_definition(ten_schema_store_t *self,
return true;
}

#if defined(TEN_ENABLE_TEN_RUST_APIS)
static void ten_schemas_parse_interface_part(
ten_hashtable_t *interface_schema_map, ten_value_t *interface_schema_value,
const char *base_dir) {
Expand Down Expand Up @@ -329,22 +331,23 @@ static bool ten_schema_store_merge_interface_schemas_into_msg_schemas(

return true;
}
#endif

/**
* @param base_dir The base directory of the addon. If the interface definition
* is a file reference, it is used to resolve the file reference based on the
* base_dir.
*/
bool ten_schema_store_set_interface_schema_definition(ten_schema_store_t *self,
ten_value_t *schema_def,
const char *base_dir,
ten_error_t *err) {
bool ten_schema_store_set_interface_schema_definition(
ten_schema_store_t *self, ten_value_t *schema_def,
TEN_UNUSED const char *base_dir, ten_error_t *err) {
TEN_ASSERT(self && ten_schema_store_check_integrity(self),
"Invalid argument.");
TEN_ASSERT(schema_def && ten_value_check_integrity(schema_def),
"Invalid argument.");
TEN_ASSERT(err && ten_error_check_integrity(err), "Invalid argument.");

#if defined(TEN_ENABLE_TEN_RUST_APIS)
if (!ten_value_is_object(schema_def)) {
ten_error_set(err, TEN_ERRNO_GENERIC,
"The interface schema should be an object.");
Expand Down Expand Up @@ -374,6 +377,7 @@ bool ten_schema_store_set_interface_schema_definition(ten_schema_store_t *self,
return false;
}
}
#endif

return true;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/ten_runtime/integration/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ group("cpp") {
"hello_world",
"http_basic",
"large_result",
"multi_apps",
"standalone_test_cpp",
]

Expand All @@ -24,4 +23,10 @@ group("cpp") {
"ffmpeg_bypass",
]
}

if (ten_enable_ten_rust && ten_enable_ten_rust_apis) {
# This case will start an invalid graph, and it will be failed without
# graph checking.
deps += [ "multi_apps" ]
}
}
9 changes: 7 additions & 2 deletions tests/ten_runtime/smoke/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ ten_executable("ten_runtime_smoke_test") {
"data_test",
"extension_test",
"graph_test",
"interface_test",
"msg_test",
"notify_test",
"result_conversion",
"schema_test",
"standalone_test",
"video_frame_test",
]

if (ten_enable_ten_rust && ten_enable_ten_rust_apis) {
deps += [
"interface_test",
"schema_test",
]
}

if (ten_enable_curl) {
deps += [ "//third_party/curl" ]
}
Expand Down
Loading