From 78cb423cfea545a8e4ee52c6934d3f3799a1b486 Mon Sep 17 00:00:00 2001 From: liangshenglin1 Date: Sun, 26 Sep 2021 09:24:38 +0000 Subject: [PATCH] adapt rpc to ark Signed-off-by: liangshenglin --- interfaces/kits/js/napi/BUILD.gn | 35 +++++++++++++++++++ .../src/napi/src/napi_rpc_native_module.cpp | 13 +++++++ 2 files changed, 48 insertions(+) diff --git a/interfaces/kits/js/napi/BUILD.gn b/interfaces/kits/js/napi/BUILD.gn index fbca183..b60a3c7 100644 --- a/interfaces/kits/js/napi/BUILD.gn +++ b/interfaces/kits/js/napi/BUILD.gn @@ -11,10 +11,36 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") +import("//foundation/ace/ace_engine/ace_config.gni") SUBSYSTEM_DIR = "//foundation/communication/ipc" +# compile .js to .abc. +action("gen_rpc_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path( + "//foundation/communication/ipc/interfaces/kits/js/napi/rpc.js"), + "--dst-file", + rebase_path(target_out_dir + "/rpc.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + + inputs = [ "//foundation/communication/ipc/interfaces/kits/js/napi/rpc.js" ] + outputs = [ target_out_dir + "/rpc.abc" ] +} + base_output_path = get_label_info(":rpc_js", "target_out_dir") ipc_js_obj_path = base_output_path + "/rpc.o" @@ -23,6 +49,14 @@ gen_js_obj("rpc_js") { output = ipc_js_obj_path } +abc_output_path = get_label_info(":rpc_abc", "target_out_dir") +rpc_abc_obj_path = abc_output_path + "/rpc_abc.o" +gen_js_obj("rpc_abc") { + input = "$target_out_dir/rpc.abc" + output = rpc_abc_obj_path + dep = ":gen_rpc_abc" +} + config("rpc_public_config") { visibility = [ ":*" ] include_dirs = [ "$SUBSYSTEM_DIR/ipc/native/src/napi/include" ] @@ -44,6 +78,7 @@ ohos_shared_library("rpc") { ] deps = [ + ":rpc_abc", ":rpc_js", "//foundation/ace/napi:ace_napi", "//third_party/libuv:uv_static", diff --git a/ipc/native/src/napi/src/napi_rpc_native_module.cpp b/ipc/native/src/napi/src/napi_rpc_native_module.cpp index 1d55d80..1cbed70 100644 --- a/ipc/native/src/napi/src/napi_rpc_native_module.cpp +++ b/ipc/native/src/napi/src/napi_rpc_native_module.cpp @@ -23,6 +23,8 @@ extern const char _binary_rpc_js_start[]; extern const char _binary_rpc_js_end[]; +extern const char _binary_rpc_abc_start[]; +extern const char _binary_rpc_abc_end[]; namespace OHOS { EXTERN_C_START @@ -48,6 +50,17 @@ extern "C" __attribute__((visibility("default"))) void NAPI_rpc_GetJSCode(const } } +// rpc JS register +extern "C" __attribute__((visibility("default"))) void NAPI_rpc_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_rpc_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_rpc_abc_end - _binary_rpc_abc_start; + } +} + static napi_module RPCModule_ = { .nm_version = 1, .nm_flags = 0, -- GitLab