From b5976923a405889284a8cd94d66d06ec8f23c24c Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Wed, 19 Apr 2023 14:19:45 +0800 Subject: [PATCH] rust test Signed-off-by: huaqingsimeng --- tools/backup_tool/BUILD.gn | 3 ++- tools/backup_tool/src/tools_op_backup.cpp | 2 ++ utils/rust/BUILD.gn | 22 ++++++++++++++++++++++ utils/rust/simple_printer.h | 21 +++++++++++++++++++++ utils/rust/simple_printer.rs | 22 ++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 utils/rust/BUILD.gn create mode 100644 utils/rust/simple_printer.h create mode 100644 utils/rust/simple_printer.rs diff --git a/tools/backup_tool/BUILD.gn b/tools/backup_tool/BUILD.gn index 691437a6d..6f2c56181 100644 --- a/tools/backup_tool/BUILD.gn +++ b/tools/backup_tool/BUILD.gn @@ -36,7 +36,8 @@ ohos_executable("backup_tool") { "hitrace_native:hitrace_meter", ] - deps = [ "${path_backup}/utils/:backup_utils" ] + deps = [ "${path_backup}/utils/:backup_utils", + "${path_backup}/utils/rust:backup_simple_printer_cdylib" ] use_exceptions = true install_enable = true diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index 50462562f..e2efc3dcb 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -41,6 +41,7 @@ #include "base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter/hitrace_meter.h" #include "service_proxy.h" #include "tools_op.h" +#include "foundation/filemanagement/app_file_service/utils/rust/simple_printer.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -214,6 +215,7 @@ static void BackupToolDirSoftlinkToBackupDir() static int32_t InitPathCapFile(vector bundleNames) { + print_hello_world(); StartTrace(HITRACE_TAG_FILEMANAGEMENT, "InitPathCapFile"); // SELinux backup_tool工具/data/文件夹下创建文件夹 SA服务因root用户的自定义标签无写入权限 此处调整为软链接形式 BackupToolDirSoftlinkToBackupDir(); diff --git a/utils/rust/BUILD.gn b/utils/rust/BUILD.gn new file mode 100644 index 000000000..20a2cded8 --- /dev/null +++ b/utils/rust/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2022-2023 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") +import("//foundation/filemanagement/app_file_service/backup.gni") + +ohos_rust_static_ffi("backup_simple_printer_cdylib") { + sources = [ "simple_printer.rs" ] + crate_name = "backup_simple_printer_cdylib" + part_name = "app_file_service" + subsystem_name = "filemanagement" +} \ No newline at end of file diff --git a/utils/rust/simple_printer.h b/utils/rust/simple_printer.h new file mode 100644 index 000000000..64290b84f --- /dev/null +++ b/utils/rust/simple_printer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SIMPLE_PRINTER_H +#define OHOS_FILEMGMT_BACKUP_SIMPLE_PRINTER_H + +void print_hello_world(void); + +#endif diff --git a/utils/rust/simple_printer.rs b/utils/rust/simple_printer.rs new file mode 100644 index 000000000..f5b34f04f --- /dev/null +++ b/utils/rust/simple_printer.rs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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. + */ + +//! cdylib_crate example for rust + +/// function print_hello_world +#[no_mangle] +pub extern "C" fn print_hello_world() { + println!("hello world by cdylib"); +} -- Gitee