From fbe9fe4480a8cfdfa721720d40fbc58f1912cc59 Mon Sep 17 00:00:00 2001 From: buzhenwang Date: Mon, 26 Dec 2022 16:22:59 +0800 Subject: [PATCH] hilog rust ffi test Signed-off-by: buzhenwang --- interfaces/bundle.json | 3 ++- interfaces/rust/BUILD.gn | 48 ++++++++++++++++++++++++++++++++++++ interfaces/rust/src/lib.rs | 23 +++++++++++++++++ interfaces/rust/test/main.rs | 22 +++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 interfaces/rust/BUILD.gn create mode 100644 interfaces/rust/src/lib.rs create mode 100644 interfaces/rust/test/main.rs diff --git a/interfaces/bundle.json b/interfaces/bundle.json index f6b5cdf..915f4e5 100644 --- a/interfaces/bundle.json +++ b/interfaces/bundle.json @@ -45,7 +45,8 @@ ], "service_group": [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_base", - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog" + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//base/hiviewdfx/hilog/interfaces/rust:hello_world_rust" ] }, "inner_kits": [ diff --git a/interfaces/rust/BUILD.gn b/interfaces/rust/BUILD.gn new file mode 100644 index 0000000..47b4f6c --- /dev/null +++ b/interfaces/rust/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_rust_executable("hello_world_rust") { + sources = [ "test/main.rs" ] + + deps = [ "//base/hiviewdfx/hilog/interfaces/rust:hilog_rust" ] + subsystem_name = "hiviewdfx" + part_name = "hilog_native" +} + +ohos_rust_shared_library("hilog_rust") { + sources = [ + "src/lib.rs", + ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//build/rust:libstd.dylib.so" + ] + + crate_name = "hilog_rust" + crate_type = "dylib" + + install_images = [ system_base_dir ] + relative_install_dir = "chipset-pub-sdk" + subsystem_name = "hiviewdfx" + part_name = "hilog_native" +} + +group("rust_hilog_component") { + deps = [ + ":hilog_rust", + "//base/hiviewdfx/hilog/interfaces/rust:hello_world_rust", + ] +} diff --git a/interfaces/rust/src/lib.rs b/interfaces/rust/src/lib.rs new file mode 100644 index 0000000..78b4968 --- /dev/null +++ b/interfaces/rust/src/lib.rs @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//! dylib_crate example for Rust. +use std::ffi::{c_char}; + +#[link(name = "libhilog")] +extern "C"{ + ///test + pub fn HiLogIsLoggable(domain: u32, tag: *const c_char, level:u32) -> bool; +} \ No newline at end of file diff --git a/interfaces/rust/test/main.rs b/interfaces/rust/test/main.rs new file mode 100644 index 0000000..a833e45 --- /dev/null +++ b/interfaces/rust/test/main.rs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use crate::{hilog_rust}; + +//! Hello world example for Rust. + +fn main() { + let res = hilog_rust::HiLogIsLoggable(0xd003200, tag: *const c_char, 4); +} \ No newline at end of file -- Gitee